In this post we will discuss minikube, and we will do some hands-on so that we can create our own Kubernetes cluster using minikube. Before going through this post, I would request you please go through the Kubernetes Series: Part 1, where we discussed some fundamentals of Kubernetes. Below is the link of Kubernetes Series: Part 1.
If you have time, go through the Kubernetes Series: Part 2 as well to understand components of Kubernetes cluster.
We know Kubernetes cluster is the group of VMs (nodes) where one VM (or multiple VM for HA) act as master node and others act as worker node (run the containers).
Minikube is such a tool through which we can create a Kubernetes cluster using only one node and this node will work as master as well as worker node. Minikube runs on Windows, macOS and Linux platform.
There are two main things which we need to install –
- kubectl – It is Kubernetes command-line tool which allows us to run command against Kubernetes cluster.
- minikube – It is the tool using which we will create the Kubernetes cluster.
Note: kubectl version should be within one minor version difference of the Kubernetes Cluster version (in this case, its minikube).
Step – 1
Run the below command to download the latest release of kubectl binary.
curl -L -O "https://dl.k8s.io/release/$(curl -L -s https://dl.k8s.io/release/stable.txt)/bin/linux/amd64/kubectl"
In the above command,
-L : If the requested page has moved to a different location, then using this -L flag will send the request to the new place where that page exists.
-O : Using -O flag will save the requested file in the current directory with the same name as the remote file.
And we can replace this portion (
curl -L -s https://dl.k8s.io/release/stable.txt) of the URL by our required version. For example if we need v1.10.0 then we can use this URL with curl command –
Step – 2
If we see the above screenshot, there is no executable permission for kubectl. So we need to add executable permission to it. For this run the below command
chmod +x kubectl
Step – 3
Now let’s install the kubectl to the
/usr/local/bin directory. For this, run the below command.
install kubectl /usr/local/bin/
Note: Here I am running the above commands from root directory. If are not running the command from root, then add sudo.
Step – 4
To verify whether kubectl installed successfully, run the below command.
kubectl version --client
If you are getting similar output as shown in the above screenshot, then congratulations! You have installed kubectl.
Here, we will install kubectl in a Linux machine. If you want to install it in other OS then please follow the below site.
Step – 1
Run the below command to download the Debian package of minikube binary.
curl -L -O https://storage.googleapis.com/minikube/releases/latest/minikube_latest_amd64.deb
Step – 2
Now let’s install the minikube. Run the below command to install it.
dpkg -i minikube_latest_amd64.deb
Note: Use sudo if you are not in the root directory.
Step – 3
To confirm minikube installed successfully, run the below command.
Step – 4
Let’s start the minikube. Before starting, we need to discuss something here.
Minikube requires driver to run. There is a list of driver available. We can use any one of them. Below is the documentation link, which you can follow for the list.
Here we will go with docker driver and for that we need to install docker.
Please install docker by running the below command. I ran the below command as root user. If are not in root user, please use sudo.
apt install docker.io
To check whether docker is installed successfully or not, run the below command.
Now if I start minikube with docker as driver from root user I get the below error.
* The "docker" driver should not be used with root privileges.
To solve that issue I will come out of root user and run the same command as “ubuntu” user. But before doing that, let’s add this “ubuntu” user in the docker group. If I don’t add this user in docker group, I will get the below permission denied error, as shown in the screenshot.
I will run the bellow commands to add my “ubuntu” user in docker group (docker group automatically created once we install docker)
sudo usermod -aG docker $USER
Now we are ready to start the minikube with docker driver. In my case I will start the minikube from “ubuntu” user which I added in docker group.
minikube start --vm-driver=docker
It will take a few minutes to get started.
Note: After running the
minikube start command, if you still get the below error, then please restart your machine. It will fix it.
Step – 5
To check the status of the minikube, run the below command.
Congratulations! You have installed minikube. And installing minikube you have created your own Kubernetes cluster.
Now we can run various Kubernetes command to check the cluster. For example if we run the below command,
kubectl get namespace
This command will give the namespaces in the Kubernetes cluster.
In this way you can run other Kubernetes commands and deploy an application in that Kubernetes cluster.
If you are interested in learning DevOps, please have a look at the below articles, which will help you greatly.
- Kubernetes Series: Part 1 – Introduction to Kubernetes | Background of Kubernetes
- Kubernetes Series: Part 2 – Components of Kubernetes cluster | Kubernetes cluster in detail
- Introduction to Ansible | High Level Understanding of Ansible
- What is “Monitoring” in DevOps? Why do we need to Monitor App/DB servers, Transactions etc.?
- What is End-to-End Monitoring of any web application and Why do we need it?
- DevOps Engineer or Software Developer Engineer which is better for you?- Let’s discuss
- Network Connectivity Troubleshooting Guide for Beginners