How to Run Kubernetes using Minikube

Kubernetes is an open-source container orchestration platform that enables users to deploy and manage applications in a distributed environment and it requires at least 2 nodes for proper functioning. One behaves as a controller node and the other is a worker node. But if you want to test it, we can also install it on a single Linux server and can enjoy its functionality.

In this article, we are going to show you a step-by-step process to run Kubernetes on Minikube.

As you must be knowing Kubernetes is designed to automate the deployment, scaling, and management of containerized applications. With Kubernetes, users can quickly and easily deploy applications on a variety of platforms, including on-premise, cloud, and hybrid environments.

Minikube is an open-source tool that provides a local Kubernetes environment for development and testing. It runs a single-node Kubernetes cluster inside a virtual machine and is designed to be used for local development and testing of Kubernetes applications.

 

Run Kubernetes using Minikube

 

Minikube Requirements

 

Minikube can be installed on a Docker container, Hyper-V, KVM, Parallels, Podman, VirtualBox, or VMware Fusion/Workstation, bare-metal servers, etc., and has specific resource requirements. Below is the required list to run minikube itself:

1. CPU: 2 or more
2. Memory: 2GB of free memory
3. Disk Space: 20GB of free disk space
4. Access to the Internet connection

 

Step-by-Step Process to Run Kubernetes using Minikube

 

For this tutorial, we are using Ubuntu 20.04.2 LTS which is running Amazon web services (AWS).

ubuntu@ip-172-31-2-197:~$ cat /etc/os-release 
NAME="Ubuntu"
VERSION="20.04.2 LTS (Focal Fossa)"
ID=ubuntu
ID_LIKE=debian
PRETTY_NAME="Ubuntu 20.04.2 LTS"
VERSION_ID="20.04"
HOME_URL="https://www.ubuntu.com/"
SUPPORT_URL="https://help.ubuntu.com/"
BUG_REPORT_URL="https://bugs.launchpad.net/ubuntu/"
PRIVACY_POLICY_URL="https://www.ubuntu.com/legal/terms-and-policies/privacy-policy"
VERSION_CODENAME=focal
UBUNTU_CODENAME=focal

 

Running Kubernetes using Minikube is a combination of majorly 2 steps

:

1. To install Docker
2. To install Minikube

 

1. Steps to Install Docker on Ubuntu

 

i. First of all, our objective is to install Docker on Ubuntu so that we can run Minikube commands. For this start with updating package information on your ubuntu machine by running `sudo apt-get update`.

 

ubuntu@ip-172-31-2-197:~$ sudo apt-get update
Hit:1 http://ca-central-1.ec2.archive.ubuntu.com/ubuntu focal InRelease
Get:2 http://ca-central-1.ec2.archive.ubuntu.com/ubuntu focal-updates InRelease [114 kB]
Get:3 http://ca-central-1.ec2.archive.ubuntu.com/ubuntu focal-backports InRelease [101 kB]
Get:4 http://security.ubuntu.com/ubuntu focal-security InRelease [114 kB]
...................
..................
Output is truncated
..................
..................
Get:39 http://security.ubuntu.com/ubuntu focal-security/universe amd64 c-n-f Metadata [12.4 kB]
Get:40 http://security.ubuntu.com/ubuntu focal-security/multiverse amd64 Packages [21.9 kB]
Get:41 http://security.ubuntu.com/ubuntu focal-security/multiverse Translation-en [4948 B]
Get:42 http://security.ubuntu.com/ubuntu focal-security/multiverse amd64 c-n-f Metadata [540 B]
Fetched 20.0 MB in 3s (6536 kB/s)                          
Reading package lists... Done

 

ii. Now once you have updated the package information, it is time to set up the repository for Docker installation on Ubuntu.

You will have to run the following commands:

 

$ sudo apt-get install \
    ca-certificates \
    curl \
    gnupg \
    lsb-release

$ sudo mkdir -p /etc/apt/keyrings
$ curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /etc/apt/keyrings/docker.gpg

$ echo \
  "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.gpg] https://download.docker.com/linux/ubuntu \
  $(lsb_release -cs) stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null

 

Here is the output from the above commands:

 

ubuntu@ip-172-31-2-197:~$ sudo apt-get install \
>     apt-transport-https \
>     ca-certificates \
>     curl \
>     gnupg \
>     lsb-release

Reading package lists... Done
Building dependency tree       
Reading state information... Done
lsb-release is already the newest version (11.1.0ubuntu2).
lsb-release set to manually installed.
ca-certificates is already the newest version (20210119~20.04.1).
ca-certificates set to manually installed.
gnupg is already the newest version (2.2.19-3ubuntu2.1).
gnupg set to manually installed.
The following additional packages will be installed:
  libcurl4
The following NEW packages will be installed:
  apt-transport-https
The following packages will be upgraded:
  curl libcurl4
2 upgraded, 1 newly installed, 0 to remove and 108 not upgraded.
Need to get 400 kB of archives.
After this operation, 162 kB of additional disk space will be used.
Do you want to continue? [Y/n] y
...............................
...............................
Unpacking apt-transport-https (2.0.6) ...
Setting up curl (7.68.0-1ubuntu2.6) ...
Processing triggers for man-db (2.9.1-1) ...
Processing triggers for libc-bin (2.31-0ubuntu9.2) ...
ubuntu@ip-172-31-2-197:~$ 
ubuntu@ip-172-31-2-197:~$ curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /usr/share/keyrings/docker-archive-keyring.gpg
ubuntu@ip-172-31-2-197:~$ 
ubuntu@ip-172-31-2-197:~$ 
ubuntu@ip-172-31-2-197:~$ echo \
>   "deb [arch=amd64 signed-by=/usr/share/keyrings/docker-archive-keyring.gpg] https://download.docker.com/linux/ubuntu \
>   $(lsb_release -cs) stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null

ubuntu@ip-172-31-2-197:~$ sudo apt-get update
Hit:1 http://ca-central-1.ec2.archive.ubuntu.com/ubuntu focal InRelease
Hit:2 http://ca-central-1.ec2.archive.ubuntu.com/ubuntu focal-updates InRelease
Hit:3 http://ca-central-1.ec2.archive.ubuntu.com/ubuntu focal-backports InRelease
Get:4 https://download.docker.com/linux/ubuntu focal InRelease [52.1 kB]   
Hit:5 http://security.ubuntu.com/ubuntu focal-security InRelease
Get:6 https://download.docker.com/linux/ubuntu focal/stable amd64 Packages [10.7 kB]
Fetched 62.9 kB in 0s (148 kB/s)
Reading package lists... Done

 

iii. Now you have to install docker. You can run the below commands to install docker on a Ubuntu machine.

 

$  sudo apt-get install docker-ce docker-ce-cli containerd.io

Here is the sample output of the above commands:

ubuntu@ip-172-31-2-197:~$  sudo apt-get install docker-ce docker-ce-cli containerd.io
Reading package lists... Done
Building dependency tree       
Reading state information... Done
The following additional packages will be installed:
  docker-ce-rootless-extras docker-scan-plugin pigz slirp4netns
Suggested packages:
  aufs-tools cgroupfs-mount | cgroup-lite
The following NEW packages will be installed:
  containerd.io docker-ce docker-ce-cli docker-ce-rootless-extras docker-scan-plugin pigz slirp4netns
0 upgraded, 7 newly installed, 0 to remove and 108 not upgraded.
Need to get 96.7 MB of archives.
After this operation, 406 MB of additional disk space will be used.
Do you want to continue? [Y/n] y
...................
...................
Created symlink /etc/systemd/system/multi-user.target.wants/docker.service → /lib/systemd/system/docker.service.
Created symlink /etc/systemd/system/sockets.target.wants/docker.socket → /lib/systemd/system/docker.socket.
Processing triggers for man-db (2.9.1-1) ...
Processing triggers for systemd (245.4-4ubuntu3.6) ...

 

iv. Now once docker is installed just confirm by running `sudo docker version`

ubuntu@ip-172-31-2-197:~$ sudo docker version
Client: Docker Engine - Community
 Version:           20.10.8
 API version:       1.41
 Go version:        go1.16.6
 Git commit:        3967b7d
 Built:             Fri Jul 30 19:54:27 2021
 OS/Arch:           linux/amd64
 Context:           default
 Experimental:      true

Server: Docker Engine - Community
 Engine:
  Version:          20.10.8
  API version:      1.41 (minimum version 1.12)
  Go version:       go1.16.6
  Git commit:       75249d8
  Built:            Fri Jul 30 19:52:33 2021
  OS/Arch:          linux/amd64
  Experimental:     false
 containerd:
  Version:          1.4.9
  GitCommit:        e25210fe30a0a703442421b0f60afac609f950a3
 runc:
  Version:          1.0.1
  GitCommit:        v1.0.1-0-g4144b63
 docker-init:
  Version:          0.19.0
  GitCommit:        de40ad0

You can also try to run a container by running `sudo docker run –rm ubuntu bash`

 

ubuntu@ip-172-31-2-197:~$ sudo docker run --rm ubuntu bash
Unable to find image 'ubuntu:latest' locally
latest: Pulling from library/ubuntu
35807b77a593: Pull complete 
Digest: sha256:9d6a8699fb5c9c39cf08a0871bd6219f0400981c570894cd8cbea30d3424a31f
Status: Downloaded newer image for ubuntu:latest
ubuntu@ip-172-31-2-197:~$ sudo docker image ls
REPOSITORY   TAG       IMAGE ID       CREATED       SIZE
ubuntu       latest    fb52e22af1b0   2 weeks ago   72.8MB

ubuntu@ip-172-31-2-197:~$ 
ubuntu@ip-172-31-2-197:~$ 
ubuntu@ip-172-31-2-197:~$ sudo docker run hello-world
Unable to find image 'hello-world:latest' locally
latest: Pulling from library/hello-world
b8dfde127a29: Pull complete 
Digest: sha256:7d91b69e04a9029b99f3585aaaccae2baa80bcf318f4a5d2165a9898cd2dc0a1
Status: Downloaded newer image for hello-world:latest

 

Now, your docker is installed. It’s time to install Minikube on Ubuntu [20.04.2 LTS (Focal Fossa)] machine.

 

2. Steps to Install MiniKube on Ubuntu

 

i. To install the latest minikube release, run the below command:

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

 

This should look something like below:

 

ubuntu@ip-172-31-2-197:~$ # INSTALL MINIKUBE
ubuntu@ip-172-31-2-197:~$ curl -LO https://storage.googleapis.com/minikube/releases/latest/minikube-linux-amd64
inikube-linux-amd64 /usr/local/bin/minikube  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100 65.2M  100 65.2M    0     0  90.8M      0 --:--:-- --:--:-- --:--:-- 90.8M
ubuntu@ip-172-31-2-197:~$ sudo install minikube-linux-amd64 /usr/local/bin/minikube

ii. If everything is fine, then the command `minikube start` should work without any issue and you can start interacting with your Kubernetes cluster using the command `minikube kubectl — get po -A` or if you already have “kubectl” installed, just run `kubectl — get po -A`.

 

If you are facing any issues, please refer to the below troubleshooting guide.

 

Troubleshooting minikube Start

 

Sometimes it might happen that you will see an error while running the “minikube start” command. So in this troubleshooting guide, we help you to resolve those errors.

 

Error 1: Unable to pick a default driver

Solution: Use –driver=docker while running minikube command.

minikube start --driver=docker

 

Error 2: ❌ Exiting due to DRV_AS_ROOT: The “docker” driver should not be used with root privileges.

Solution: Don’t run minikube command “minikube start –driver=docker” with sudo option.

 

Error 3: Exiting due to PROVIDER_DOCKER_NEWGRP

Solution: Run “sudo usermod -aG docker $USER && newgrp docker” and then minikube start command

sudo usermod -aG docker $USER && newgrp docker
minikube start --driver=docker

 

Error 4: Docker is not default driver.

Solution: Run the below command to make docker default driver:

minikube config set driver docker
minikube delete

Output of the above command

ubuntu@ip-172-31-2-197:~$ minikube config set driver docker
❗  These changes will take effect upon a minikube delete and then a minikube start

ubuntu@ip-172-31-2-197:~$ minikube delete
🔥  Deleting "minikube" in docker ...
🔥  Deleting container "minikube" ...
🔥  Removing /home/ubuntu/.minikube/machines/minikube ...
💀  Removed all traces of the "minikube" cluster.

 

Once everything is set up correctly, you will be able to run `minikube start` command without any issues.

 

ubuntu@ip-172-31-2-197:~$ minikube start
😄  minikube v1.23.0 on Ubuntu 20.04 (xen/amd64)
✨  Using the docker driver based on user configuration
👍  Starting control plane node minikube in cluster minikube
🚜  Pulling base image ...
🔥  Creating docker container (CPUs=2, Memory=2200MB) ...
🐳  Preparing Kubernetes v1.22.1 on Docker 20.10.8 ...
    ▪ 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: default-storageclass, storage-provisioner
💡  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
ubuntu@ip-172-31-2-197:~$ 

 

If you already have kubectl installed, you can now use it to access your Kubernetes cluster.

# kubectl get po -A

If not, minikube can download the appropriate version of kubectl, just use double-dashes in the command line like below:

ubuntu@ip-172-31-2-197:~$ minikube kubectl -- get po -A
    > kubectl.sha256: 64 B / 64 B [--------------------------] 100.00% ? p/s 0s
    > kubectl: 44.73 MiB / 44.73 MiB [-----------] 100.00% 234.47 MiB p/s 400ms
NAMESPACE     NAME                               READY   STATUS    RESTARTS      AGE
kube-system   coredns-78fcd69978-dxqwp           1/1     Running   0             96s
kube-system   etcd-minikube                      1/1     Running   0             102s
kube-system   kube-apiserver-minikube            1/1     Running   0             102s
kube-system   kube-controller-manager-minikube   1/1     Running   0             102s
kube-system   kube-proxy-6knsk                   1/1     Running   0             96s
kube-system   kube-scheduler-minikube            1/1     Running   0             102s
kube-system   storage-provisioner                1/1     Running   1 (65s ago)   107s
ubuntu@ip-172-31-2-197:~$ 

 

Verifying Kubernete Working on Minikube

 

Once everything is done, you can verify that Kubernetes is working as expected by running kubectl command to get the node with IP or any other command.

ubuntu@ip-172-31-2-197:~$ kubectl get no -o wide
NAME       STATUS   ROLES                  AGE     VERSION   INTERNAL-IP    EXTERNAL-IP   OS-IMAGE             KERNEL-VERSION   CONTAINER-RUNTIME
minikube   Ready    control-plane,master   8m32s   v1.22.1   192.168.49.2           Ubuntu 20.04.2 LTS   5.4.0-1045-aws   docker://20.10.8
ubuntu@ip-172-31-2-197:~$ 

ubuntu@ip-172-31-2-197:~$ kubectl run busybox --image=busybox --restart=Never --rm -it -- /bin/sh -c "echo hello"
hello
pod "busybox" deleted
ubuntu@ip-172-31-2-197:~$ 

 

Resources for reference:

# Install Docker on Ubuntu: https://docs.docker.com/engine/install/ubuntu/
# Install Minikube: https://minikube.sigs.k8s.io/docs/start/

 

Using Minikube is a great way to get started with Kubernetes. To run Kubernetes using Minikube, you just need to install the Minikube software and start a cluster.

Once your cluster is running, you can easily deploy your applications and manage them with Kubernetes. Minikube makes it easy to start and manage Kubernetes clusters, allowing you to quickly get up and running with the power of Kubernetes.

Buy me a coffeeBuy me a coffee

Add Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.