DevOpsDockerkubernetes

Install Kubernetes using Minikube on Linux, CentOS, Fedora, Red Hat

In this article we are going to learn how to setup a local Kubernetes cluster. In the market many software's like Kind, K3s, Minikube, etc. are available which will install and setup local Kubernetes cluster for us. In this article we will use Minikube due to following benefits than its competitors.

  • Provides close experience of working on production Kubernetes environment.
  • Helps in Kubernetes certification exam preparation as most of the objects and operations are supported.
  • Gives Developer an ability to test application behavior before going to the production.

Prerequisites

  • 2 CPUs or more
  • 2GB of free memory
  • 20GB of free disk space
  • Stable Internet connection
  • Container or virtual machine manager, such as: Docker, Podman, VirtualBox
  • Virtualization support must be enabled
  • A dedicated physical machine

The Minikube requires virtual machine to create a cluster. We can use any virtual machine or containerization software like Docker, Podman, Virtualbox, etc. in tandem. For this tutorial lets use Docker which will act as an virtual machine (VM) driver for Minikube to perform VM related operations.

Steps to install Docker using DNF on Fedora, CentOS, Red Hat

Adding Docker repository

We will use DNF and official Docker repository for installation purpose. Let's install DNF utility as it is not available by default.

Note - You can use any alternate utility than DNF without any change in the installation steps.

sudo dnf install dnf-plugins-core -y
sudo dnf config-manager --add-repo https://download.docker.com/linux/fedora/docker-ce.repo

Tip - Refer to the below dedicated articles on how to install Docker.

Install latest stable version of Docker

sudo dnf install docker-ce docker-ce-cli containerd.io

Verify Docker installation

Once the installation is completed, start the Docker service and verify the Docker installation by spinning a light weight image.

sudo systemctl start docker
sudo docker run hello-world

Steps to install Minikube on Fedora, CentOS, Red Hat

Download Minikube binary

Download Minikube binary from the official link as in below command.

sudo wget https://storage.googleapis.com/minikube/releases/latest/minikube-linux-amd64 -O /usr/local/bin/minikube

Example:

[[email protected] ~]$ sudo wget https://storage.googleapis.com/minikube/releases/latest/minikube-linux-amd64 -O /usr/local/bin/minikube
--2022-04-06 22:07:25--  https://storage.googleapis.com/minikube/releases/latest/minikube-linux-amd64
Resolving storage.googleapis.com (storage.googleapis.com)... 142.250.77.176, 172.217.163.208, 172.217.166.112, ...
Connecting to storage.googleapis.com (storage.googleapis.com)|142.250.77.176|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 72651748 (69M) [application/octet-stream]
Saving to: ‘/usr/local/bin/minikube’

/usr/local/bin/minikube              100%[====================================================================>]  69.29M  14.5MB/s    in 4.8s    

2022-04-06 22:07:30 (14.4 MB/s) - ‘/usr/local/bin/minikube’ saved [72651748/72651748]

Change permission of Minikube binary

To make the binary executable, change the permission of Minkube binary to 775 as in below command.

[[email protected] ~]$ sudo chmod 755 /usr/local/bin/minikube 

Setup Minikube to use Docker

Post successful execution of the above steps, execute Minikube binary for the first time to perform initial installation. Remember that Docker service must be started before executing Minikube binary so that Minikube can auto detect the Docker driver.

minikube start

Output:

😄  minikube v1.25.2 on Fedora 35
✨  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% 8.97 MiB
    > gcr.io/k8s-minikube/kicbase: 379.06 MiB / 379.06 MiB  100.00% 5.43 MiB p/
🔥  Creating docker container (CPUs=2, Memory=3800MB) ...
🐳  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

Using kubectl to interact with Minikube cluster

Minikube ships with kubectl utility and is enabled by default. The control plane cluster can be accessed by using kubetl utility as in below command

minikube kubectl get all

After executing the above command, Minikube will configure kubectl if its running for first time as in below output

    > kubectl.sha256: 64 B / 64 B [--------------------------] 100.00% ? p/s 0s
    > kubectl: 44.43 MiB / 44.43 MiB [-------------] 100.00% 15.93 MiB p/s 3.0s

Again check by executing kubectl command and you will get the result

[[email protected] ~]$ minikube kubectl get all
NAME                 TYPE        CLUSTER-IP   EXTERNAL-IP   PORT(S)   AGE
service/kubernetes   ClusterIP   10.96.0.1    <none>        443/TCP   46h

To use simple 'kubectl' command instead of 'minikube kubectl' command every time, create a symbolic link to the kubectl binary.

sudo ln -s $(which minikube) /usr/local/bin/kubectl

Verify if the minikube kubectl symbolic works by executing command as below

[[email protected] ~]$ kubectl get all
NAME                 TYPE        CLUSTER-IP   EXTERNAL-IP   PORT(S)   AGE
service/kubernetes   ClusterIP   10.96.0.1    <none>        443/TCP   46h

That's all. We are all set to use Minikube and perform operations on local Kubernetes cluster. You may get away from using sudo in commands by adding your user in the sudo users group.

Tip: If Docker and Minikube service has to be started manually on boot then always start Docker service first followed by the Minikube service before using kubectl utility.

References

https://minikube.sigs.k8s.io/docs/

https://minikube.sigs.k8s.io/docs/handbook/kubectl/

Abhijit Sandhan

Love to Automate, Blog, Travel, Hike & spread Knowledge!

Leave a Reply

Your email address will not be published.

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

Back to top button