Introduction

Minikube and kubectl are the essential tools for running and managing a Kubernetes cluster on your own machine. In this step-by-step guide, you’ll install Docker, kubectl and Minikube on Ubuntu 22.04 LTS, start a local cluster, and then learn the core Kubernetes objects you’ll work with every day.

Prerequisites

  1. A system running Ubuntu 22.04 LTS. This guide uses an AWS EC2 instance, but any Ubuntu machine or VM works.
  2. Basic knowledge of Kubernetes and common Linux commands.
  3. At least 2 CPU cores, 2GB of RAM and 20GB of free storage.

Step 1: Install Docker

Minikube needs a container runtime or virtualization driver to run a single-node cluster, and Docker is the most popular choice. Update your package list and install Docker:

sudo apt update -y
sudo apt install -y docker.io
Installing Docker on Ubuntu 22.04

Step 2: Install kubectl

kubectl is the command-line tool for managing Kubernetes clusters. Install the prerequisites, then download and install the latest stable kubectl:

sudo apt install -y curl wget apt-transport-https
curl -LO "https://dl.k8s.io/release/$(curl -L -s https://dl.k8s.io/release/stable.txt)/bin/linux/amd64/kubectl"
sudo install -o root -g root -m 0755 kubectl /usr/local/bin/kubectl

Verify the installation:

kubectl version --client
Checking the kubectl version on Ubuntu

Step 3: Install Minikube

Download the Minikube binary and install it:

curl -LO https://storage.googleapis.com/minikube/releases/latest/minikube-linux-amd64
sudo install minikube-linux-amd64 /usr/local/bin/minikube

Add your user to the docker group so Minikube can use Docker without root:

sudo usermod -aG docker $USER && newgrp docker

Step 4: Start Minikube

Start your cluster with the Docker driver:

minikube start --driver=docker
Starting Minikube with the Docker driver

This guide runs Minikube directly on Docker. If you’d rather use a virtualization tool such as KVM or VirtualBox, install it and pass the matching driver, for example minikube start --driver=kvm2. See the full list of supported Minikube drivers.

Step 5: Interact with Your Cluster

With Minikube running, try these commands to explore your cluster:

minikube status
kubectl get nodes
kubectl get ns
kubectl get pods -A
Running kubectl commands against Minikube

Step 6: Stop and Delete Minikube

When you’re finished, stop the cluster, or delete it completely:

minikube stop
minikube delete

Using Rocky Linux instead? See our guide to installing Minikube and kubectl on Rocky Linux 9.

Conclusion

You’ve installed Minikube and kubectl on Ubuntu 22.04 LTS and started a local Kubernetes cluster. You can now develop and test containerized applications right on your machine. Check the official documentation for updates and advanced configuration options.

Understanding Kubernetes Objects

In Kubernetes, objects are the building blocks for orchestrating containerized applications. Each one plays a distinct role in managing your applications and infrastructure. Here are the most important ones:

  1. Pod:

    • Explanation: A pod is the smallest deployable unit in Kubernetes, representing a single instance of a running process. It encapsulates one or more containers and shared storage, along with configuration settings.
    • Sample Syntax:

      apiVersion: v1
      kind: Pod
      metadata:
      name: my-pod
      spec:
      containers:
      - name: my-container
      image: nginx:latest

  2. Service:

    • Explanation: Services enable network communication within and outside the cluster. They abstract the underlying pod instances, providing a consistent way to access applications, load balance traffic, and ensure high availability.
    • Sample Syntax:

      apiVersion: v1
      kind: Service
      metadata:
      name: my-service
      spec:
      selector:
      app: my-app
      ports:
      - protocol: TCP
      port: 80
      targetPort: 8080

  3. ConfigMap:

    • Explanation: ConfigMaps allow you to decouple configuration data from application code. They store key-value pairs, environment variables, and configuration files, making it easier to manage configurations across different environments.
    • Sample Syntax:

      apiVersion: v1
      kind: ConfigMap
      metadata:
      name: my-config
      data:
      app.config: |
      key1: value1
      key2: value2

  4. Deployment:

    • Explanation: Deployments define the desired state for your application, ensuring it runs as expected. They handle scaling, rolling updates, and self-healing by managing replica sets of pods.
    • Sample Syntax:

      apiVersion: apps/v1
      kind: Deployment
      metadata:
      name: my-app-deployment
      spec:
      replicas: 3
      selector:
      matchLabels:
      app: my-app
      template:
      metadata:
      labels:
      app: my-app
      spec:
      containers:
      - name: my-app-container
      image: my-app-image:latest

  5. Namespace:

    • Explanation: Namespaces provide a logical separation of resources within a cluster. They help organize and isolate applications, preventing naming conflicts and allowing multiple teams to work independently.
    • Sample Syntax:

      apiVersion: v1
      kind: Namespace
      metadata:
      name: my-namespace

  6. Secret:

    • Explanation: Secrets secure sensitive information such as passwords, API tokens, and certificates. They are base64-encoded and can be mounted as volumes or used as environment variables in pods.
    • Sample Syntax:

      apiVersion: v1
      kind: Secret
      metadata:
      name: my-secret
      type: Opaque
      data:
      username: dXNlcm5hbWU= # base64-encoded "username"
      password: cGFzc3dvcmQ= # base64-encoded "password"

  7. Role-Based Access Control (RBAC):

    • Explanation: RBAC allows you to define fine-grained access control policies for users and services within your cluster. It ensures that only authorized entities can perform specific actions on resources.

    • Sample Syntax (Role):

      apiVersion: rbac.authorization.k8s.io/v1
      kind: Role
      metadata:
      name: my-role
      rules:
      - apiGroups: [""]
      resources: ["pods"]
      verbs: ["get", "list", "watch"]

    • Sample Syntax (RoleBinding):

      apiVersion: rbac.authorization.k8s.io/v1
      kind: RoleBinding
      metadata:
      name: my-role-binding
      subjects:
      - kind: User
      name: alice
      apiGroup: rbac.authorization.k8s.io
      roleRef:
      kind: Role
      name: my-role
      apiGroup: rbac.authorization.k8s.io

These Kubernetes objects are fundamental to orchestrating containerized applications, ensuring efficient management, security, and scalability within your clusters. For quick reference, also check our kubectl cheat sheet.

Filed under:

3 responses to “Minikube and Kubectl Installation on Ubuntu (22.04 LTS) and Kubernetes Objects Explained”

  1. […] Minikube and kubectl easy installation on Ubuntu and Kubernetes Object […]

  2. […] Using Ubuntu instead? Follow our guide to installing Minikube and kubectl on Ubuntu. […]

Leave a Reply

About the Author

Amin Nadaf is an HPC and Linux specialist and Red Hat Certified Engineer (RHCE) with 15 years of hands-on experience, from server hardware to production HPC clusters, cloud and DevOps.

More about Amin →

Get new tutorials by email

Kubernetes, DevOps and cloud guides, straight to your inbox. No spam.