Setup Single Node Kubernetes Cluster With Minikube On Ubuntu
In this blog post We will learn to setup single node kubernetes cluster with minikube on ubuntu.
What Is Minikube?
Minikube is a tool which will help us to easily run kubernetes locally.
Minikube runs as a single node kubernetes cluster inside a VM on the laptop for the users who want to try kubernetes and test codes locally on the kubernetes environment.
Minikube is available for Linux , Windows and MacOS.
Features Supported By Minikube
Minikube suppports the following kubernetes features.
- Container Runtime such as containerd , Docker , CRI-O
- ConfigMaps and Secrets
Before installing minikube on the Local systems , We need to check If virtualization is supported on the local system.
As I am using Ubuntu as my local machine , I will run the below command and should verify that the response is not empty.
sudo grep -E --color 'vmx|svm' /proc/cpuinfo
To check the virtualization compatibility on MacOS , Run this command.
sysctl -a | grep -E --color 'machdep.cpu.features|VMX'
To check if the virtualization is supported on Windows , Run this command.
Before installing minikube , We need to complete the below requirements.
- kubectl should be installed – kubectl is used to manage the kubernetes cluster.
- VirtualBox should be installed.
Kubectl a command line utility , is used to manage the kubernetes cluster.
To install kubectl use the below commands.
Download the latest release,
curl -LO https://storage.googleapis.com/kubernetes-release/release/`curl -s https://storage.googleapis.com/kubernetes-release/release/stable.txt`/bin/linux/amd64/kubectl
Make the kubectl binary executable,
chmod +x ./kubectl
Move to binary into the user path (/usr/local/bin),
sudo mv ./kubectl /usr/local/bin/kubectl
To check the version of kubectl installed on the system,
kubectl version --client
Virtual box can be downloaded and installed from the official website.
Minikube can be installed using the stand-alone binary.
You can download the minikube binary from the below link,
curl -Lo minikube https://storage.googleapis.com/minikube/releases/latest/minikube-linux-amd64 && chmod +x minikube
Also Using the above command , We have set the executable permission for the minikube binary.
And then move the minikube binary to your PATH.
sudo mv minikube /usr/local/bin/minikube
Run the below command to check the version of minikube installed.
To check the lists of available minikube commands , Run,
If you check the status of minikube , It says there is no cluster running currently.
Creating Cluster Using Minikube
To launch the single node kubernetes cluster locally , Run the below command.
When you run the above command , It will launch a VM in the virtual box where the cluster will be launched and so it will take some time for the minikube to launch the cluster.
Now we have the running kubernetes cluster locally.
To check the status of the cluster , Run the following command.
To manage the objects or to control the resources of kubernetes objects such as pods . deployment , services , volumes etc , We can launch the minikube kubernetes dashboard so that we can manage everything graphically.
Execute the below command to start the minikube dashboard.
After the successfully execution of the above command , It will automatically open the minikube – kubernetes dashboard in the default browser.
and you will get the following screen.
To interact with the kubernetes cluster we will be using command line interface , kubectl.
To get the Cluster information,
To get the lists of nodes in the cluster , Run the below command,
kubectl get nodes
To list the pods running within the cluster,
kubectl get pods
To list the pods across all namespaces,
kubectl get pods --all-namespaces
Deploying Apps Into Kubernetes Cluster Using Kubectl
Lets deploy our first app on kubernetes cluster with the kubectl commands.
We will deploy the existing image named echoserver , which is a simple HTTP server.
Before deploying , Lets understand few key components of kubernetes cluster.
Deployment represents a set of multiple , identical pods without any unique identifiers.Deployment runs multiple replicas of application and automatically replaces with the failed pods.Deployments are managed by Kubernetes Deployment Controller
A Pod is the basic execution unit of a kubernetes application.It represents the processes running on the cluster.A Pod can run multiple containers.
namespaces are a way to divide cluster resources between multiple users via resource quota.
A service can be defined as a logical set of pods which provides a single IP address and DNS name by which the pods can be accessed.With the help of pod , It is very easy to manage load balancing configurations.
Let’s start the deployment.We are naming the deployment as hello-minikube.
kubectl create deployment hello-minikube --image=k8s.gcr.io/echoserver:1.10
You should get the similar response.
To list the deployments,
kubectl get deployments
The deployment will create a pod , We can check the status of the pod as shown below,
kubectl get po -o wide
The access the app which we have deployed , We need to expose it as a service using the below command.
kubectl expose deployment hello-minikube --type=NodePort --port=8080
To get the service details,
kubectl get svc
To get the url of the app which we have deployed,
minikube service hello-minikube --url
If you copy and paste the URL in the browser , You should get the below response.
Now Head over to the Kubernetes Dashboard and then click Deployments ,
Here you can find the deployments that we have made using kubectl.
Click Pods , To list the pods running in the kubernetes cluster,
Terminating Local Kubernetes Cluster
After the testing is completed , We can terminate the single node kubernetes cluster which we are running locally using minikube.
Before terminating the cluster , We need to remove the pods and services and deployments which are actively running in the cluster.
To terminate the Services , Run the below command.
kubectl delete service hello-minikube
hello-minikube – is the service name.
Using the below command , We can delete the pods
kubectl delete pods hello-minikube-64b64df8c9-7lgxg
hello-minikube-64b64df8c9-7lgxg – is the pod name
To delete the deployments,
kubectl delete deployment hello-minikube
hello-minikube – is the deployment name
After all the resources are deleted from the kubernetes cluster , We can terminate the kubernetes cluster.
This command will delete the VM created in the Virtual box and all other traces of the cluster.
Finally , Run the below command to verify the cluster status.
As you can see that we are not running any cluster locally.
We have learnt to launch a single node kubernetes cluster using minikube on Ubuntu.
Also also we know to manage the kubernetes cluster and deploy applications into kubernetes cluster using kubectl.
Hope you find it helpful.Thanks for reading.
Please do check out my other blogs.