How to install Minikube on Ubuntu 22.04

Minikube is a tool that makes it easy to run Kubernetes locally. Minikube runs a single-node Kubernetes cluster inside a VM on your local machine. Kubernetes quickly set up a local Kubernetes cluster on Linux, Windows, and macOS.

It is always advisable before diving into Kubernetes, you will need a minimal Kubernetes setup. Such a setup should spin up fast and integrate well with other tools.

In his tutorial, we are going to learn how to install Minikube on Ubuntu 22.04. I am going to use Docker as a containerization platform. You can either VirtualBox, Podman, KVM, etc.

Minikube is the best fit because of the following:

  • It runs on Windows, Linux, and macOS.
  • It supports the latest Kubernetes release
  • It supports multiple container runtimes i.e Containerd, KVM, Docker, Podman, etc
  • It has supports for advanced features such as Load balancing, Featuregates, and filesystems mounts.
  • It has support for Addons. Addons is a marketplace for developers to share configurations for running services on Minikube.
  • It supports CI environments

Prerequisites

To run Kubernetes effectively you need to allocate the following to Minikube on your system.

  • 2 CPUs or more
  • 2 GB of memory
  • 20 GB or more of free disk space
  • Reliable internet connections.
  • Container or virtual machine manager such as Docker, KVM, Podman, Virtual Box etc.

Related Articles

Install Minikube on Ubuntu 22.04

1. Update system repositories

The first thing we need to do is to update our system repositories in order to make them up to date. Run the following command on your terminal to update our system.

$ sudo apt update && apt upgrade -y

2. Install Docker on Ubuntu 20.04

As I said from the beginning, we are going to use Docker. Check this article on How to install Docker-CE on Ubuntu 22.04

You can install Docker using the following command on your terminal.

$ sudo apt install docker.io

You need to enable and start docker so that it will start every time you boot your system.

# Enable docker
$ sudo systemctl enable docker
# Start docker
$sudo systemctl start docker 
# Check docker status
$ sudo systemctl status docker  
# Docker Status 
● docker.service - Docker Application Container Engine
     Loaded: loaded (/lib/systemd/system/docker.service; enabled; vendor preset: enabled)
     Active: active (running) since Sun 2022-01-23 15:32:26 UTC; 5min ago
TriggeredBy: ● docker.socket
       Docs: https://docs.docker.com
   Main PID: 8858 (dockerd)
      Tasks: 10
     Memory: 41.8M
     CGroup: /system.slice/docker.service
             └─8858 /usr/bin/dockerd -H fd:// --containerd=/run/containerd/containerd.sock

Once Docker is installed, we need to add a user into our system because Docker runs in rootless mode.

Add a user to Docker with the following command.

# add user and add to docker group
$ sudo usermod -aG docker $USER && newgrp docker

When Docker installation is complete then it’s time to install Minikube.

3. Install Minikube on Ubuntu 20.04

In order to install the latest version release of Minikube, we are going to download it using the curl command.

$ curl -LO https://storage.googleapis.com/minikube/releases/latest/minikube_latest_amd64.deb
sudo dpkg -i minikube_latest_amd64.deb

4. Start Minikube

To start using Minikube we need to start it first with the following command:

$ minikube start

You will see the following output

# output
😄  minikube v1.25.2 on Ubuntu 22.04
✨  Automatically selected the docker driver. Other choices: none, ssh
👍  Starting control plane node minikube in cluster minikube
🚜  Pulling base image ...
💾  Downloading Kubernetes v1.23.3 preload ...
    > preloaded-images-k8s-v17-v1...: 505.68 MiB / 505.68 MiB  100.00% 1.20 MiB
    > gcr.io/k8s-minikube/kicbase: 379.06 MiB / 379.06 MiB  100.00% 911.18 KiB 
🔥  Creating docker container (CPUs=2, Memory=2200MB) ...
🐳  Preparing Kubernetes v1.23.3 on Docker 20.10.12 ...
    ▪ kubelet.housekeeping-interval=5m
    ▪ Generating certificates and keys ...
    ▪ Booting up control plane ...
    ▪ Configuring RBAC rules ...
🔎  Verifying Kubernetes components...
    ▪ Using image gcr.io/k8s-minikube/storage-provisioner:v5
🌟  Enabled addons: storage-provisioner, default-storageclass
💡  kubectl not found. If you need it, try: 'minikube kubectl -- get pods -A'
🏄  Done! kubectl is now configured to use "minikube" cluster and "default" namespace by default

We can check minikube version with the following command:

$ minikube version
minikube version: v1.25.2
commit: 362d5fdc0a3dbee389b3d3f1034e8023e72bd3a7

5. Install Kubectl on Ubuntu 20.04

Let’s install kubectl using binary install. We are going to use the curl command.

$ curl -LO "https://dl.k8s.io/release/$(curl -L -s https://dl.k8s.io/release/stable.txt)/bin/linux/amd64/kubectl"

Download the following checksum to validate our install

$ curl -LO "https://dl.k8s.io/$(curl -L -s https://dl.k8s.io/release/stable.txt)/bin/linux/amd64/kubectl.sha256"

Then when installation is complete validate with the following command.

$ echo "$(<kubectl.sha256)  kubectl" | sha256sum --check

If valid you will get kubectl ok as the output.

Install Kubectl

$ sudo install -o root -g root -m 0755 kubectl /usr/local/bin/kubectl

If you ls you will notice that kubectl changes color meaning it’s now executable.

Check if t=Kubectl is installed properly.

$ kubectl version --short 
Flag --short has been deprecated, and will be removed in the future. The --short output will become the default.
Client Version: v1.24.1
Kustomize Version: v4.5.4
Server Version: v1.23.3

Check kubectl cluster information with the following command;

$ kubectl cluster-info

If its working correctly then we will see a URL being shown

# output
Kubernetes control plane is running at https://192.168.49.2:8443
CoreDNS is running at https://192.168.49.2:8443/api/v1/namespaces/kube-system/services/kube-dns:dns/proxy

To further debug and diagnose cluster problems, use 'kubectl cluster-info dump'.

To check configuration use kubectl config view

$ kubectl config view 

You will get a very nice json file like the one shown below.

# output
apiVersion: v1
clusters:
- cluster:
    certificate-authority: /home/nextgen/.minikube/ca.crt
    extensions:
    - extension:
        last-update: Sat, 28 May 2022 13:40:38 EAT
        provider: minikube.sigs.k8s.io
        version: v1.25.2
      name: cluster_info
    server: https://192.168.49.2:8443
  name: minikube
contexts:
- context:
    cluster: minikube
    extensions:
    - extension:
        last-update: Sat, 28 May 2022 13:40:38 EAT
        provider: minikube.sigs.k8s.io
        version: v1.25.2
      name: context_info
    namespace: default
    user: minikube
  name: minikube
current-context: minikube
kind: Config
preferences: {}
users:
- name: minikube
  user:
    client-certificate: /home/nextgen/.minikube/profiles/minikube/client.crt
    client-key: /home/nextgen/.minikube/profiles/minikube/client.key

In order to access your cluster using kubectl use the following command.

$ kubectl get po -A
NAMESPACE     NAME                               READY   STATUS    RESTARTS      AGE
kube-system   coredns-64897985d-hgvbk            1/1     Running   0             30m
kube-system   etcd-minikube                      1/1     Running   0             30m
kube-system   kube-apiserver-minikube            1/1     Running   0             30m
kube-system   kube-controller-manager-minikube   1/1     Running   0             30m
kube-system   kube-proxy-6c48r                   1/1     Running   0             30m
kube-system   kube-scheduler-minikube            1/1     Running   0             30m
kube-system   storage-provisioner                1/1     Running   1 (29m ago)   30m

6. Enable Kubernetes Dashboard

Kubernetes comes with a dashboard where you will manage your clusters. To enable the dashboard, use the following command:

$ minikube dashboard

Running the following command will get us the following output.

#output
🔌  Enabling dashboard ...
    ▪ Using image kubernetesui/dashboard:v2.3.1
    ▪ Using image kubernetesui/metrics-scraper:v1.0.7
🤔  Verifying dashboard health ...
🚀  Launching proxy ...
🤔  Verifying proxy health ...
🎉  Opening http://127.0.0.1:35251/api/v1/namespaces/kubernetes-dashboard/services/http:kubernetes-dashboard:/proxy/ in your default browser...

It will then open your dashboard on your default browser. You can now interact easily with your deployments.

Whenever you don’t want to start minikube dashboard on your browser, you can prefix with –url

minikube dashboard --url

7. Create a deployment and a service

A service is an abstraction that defines a logical set of Pods and a policy by which to access them. Pods are the smallest execution unit in Kubernetes. It encapsulates one or more applications. Kubernetes Pods are created and destroyed to match the desired state of your cluster. Pods are only accessible by its internal IP address within the kubernetes cluster.

Let’s make an hello-node. Follow the following steps.

Create deployment

To create a deployment we use kubectl create command

$ kubectl create deployment hello-node --image=k8s.gcr.io/echoserver:1.4

Sample output will look like this

 > kubectl.sha256: 64 B / 64 B [--------------------------] 100.00% ? p/s 0s
    > kubectl: 30.80 KiB / 44.43 MiB [>_________________________] 0.07% ? p/s     > kubectl: 46.80 KiB / 44.43 MiB [>_________________________] 0.10% ? p/s     > kubectl: 78.79 KiB / 44.43 MiB [>_________________________] 0.17% ? p/s     > kubectl: 286.79 KiB / 44.43 MiB [>_______] 0.63% 426.90 KiB p/s ETA 1m45    > kubectl: 558.79 KiB / 44.43 MiB [>_______] 1.23% 426.90 KiB p/s ETA 1m45    > kubectl: 894.79 KiB / 44.43 MiB [>_______] 1.97% 426.90 KiB p/s ETA 1m44    > kubectl: 1.61 MiB / 44.43 MiB [>_________] 3.62% 545.52 KiB p/s ETA 1m20    > kubectl: 1.61 MiB / 44.43 MiB [>_________] 3.62% 545.52 KiB p/s ETA 1m20

To view the deployments, we use kubectl get deployments

kubectl get deployments

The sample output will look like this.

NAME         READY   UP-TO-DATE   AVAILABLE   AGE
hello-node   1/1     1            1           115s

To view the pods use the kubectl get pods command.

kubectl get pods 

The sample output will look like this

NAME                          READY   STATUS    RESTARTS   AGE
hello-node-6b89d599b9-mlv7q   1/1     Running   0          5m23s

After we have created deployment we need to expose the Pod to the public internet with kubectl expose command.

kubectl expose deployment hello-node --type=LoadBalancer --port=8080

–type=LoadBalancer expose the service outside the cluster

You will get an output service/hello-node exposed.

To view the services you have created we use kubectl get services command.

kubectl get services 

This is the output you will get.

NAME         TYPE           CLUSTER-IP    EXTERNAL-IP   PORT(S)          AGE
hello-node   LoadBalancer   10.97.64.87   <pending>     8080:30179/TCP   33m
kubernetes   ClusterIP      10.96.0.1     <none>        443/TCP          133m

To stop minikube virtual machine we use minikube stop

minikube stop

To delete minikube virtual machine use minikube delete

minikube delete

To stop and delete the services we have created above we use the following command.

$ kubectl delete service hello-node
$ kubectl delete deployment hello-node

Conclusion

We have successfully installed Minikube on Ubuntu 22.04. If you face any challenges do give us a comment and we will be happy to assist.

About Kipkoech Sang

I am a technology enthusiast who loves to share gained knowledge through offering daily tips as a way of empowering others. I am fan of Linux and all other things open source.
View all posts by Kipkoech Sang →

Leave a Reply

Your email address will not be published. Required fields are marked *