How to Run Kubernets Cluster locally (minikube)?
Do you know minikube? or how to run minikube? Let it be! First of all, know minikube!
What is minikube?
Minikube is in existence because it was required to run Kubernetes as a single node cluster and Minikube do it as it is designed. Minikube runs a single Go binary (named localkube), which runs all the Kubernetes components. It can run a single-node Kubernetes cluster inside a VM for trying out Kubernetes or for development purpose. Minikube uses libmachine for provisioning VMs, and kubeadm to provision a kubernetes cluster.
- Kuberenets features like DNS, Dashboards, CNI, NodePorts, ConfigMaps and Secrets etc are supported by minikube
- Minikube supports rkt container engine along with Docker containers.
- Possible to reuse the minikube’s built-in Docker daemon
- Supports persistent volumes and host folder mounting.
- Kubernetes environment configurable.
- kubectl (Read Kubernetes Installation )
- VirtualBox or KVM
- VT-x/AMD-v virtualization must be enabled in BIOS
- Internet connection on the first run
NOTE: If you use –vm-driver=none, be sure to specify a bridge network for docker. Otherwise, it might change between network restarts, causing loss of connectivity to your cluster.
Step 1: Setup KVM2 driver
Setup KVM driver to communicate with Minikube as we are going to setup Minikube inside a VM. If you are using a bare metal then you may skip this but still, I would suggest going KVM driver installation.
[[email protected] ~]# yum install libvirt-daemon-kvm qemu-kvm libvirt libvirt-python libguestfs-tools virt-install [[email protected] ~]# service libvirtd restart Redirecting to /bin/systemctl restart libvirtd.service [[email protected] ~]# usermod -a -G libvirt $(whoami) [[email protected] ~]# newgrp libvirt [[email protected] ~]# curl -Lo docker-machine-driver-kvm2 https://storage.googleapis.com/minikube/releases/latest/docker-machine-driver-kvm2 \ && chmod +x docker-machine-driver-kvm2 \ && sudo cp docker-machine-driver-kvm2 /usr/local/bin/ \ && rm docker-machine-driver-kvm2
Step2: Download Minikube
Now download the Minikube and set up this under /usr/local/bin
[[email protected] ~]# curl -Lo minikube https://storage.googleapis.com/minikube/releases/latest/minikube-linux-amd64 && chmod +x minikube && sudo mv minikube /usr/local/bin/ % Total % Received % Xferd Average Speed Time Time Time Current Dload Upload Total Spent Left Speed 100 38.5M 100 38.5M 0 0 5267k 0 0:00:07 0:00:07 --:--:-- 6460k Minikube
Step 3: Start Minkube
If you want to change the VM driver add the appropriate –vm-driver=xxx. We can start the minikube with the driver
[[email protected] ~]# minikube start --vm-driver=kvm2 Starting local Kubernetes v1.10.0 cluster... Starting VM... Downloading Minikube ISO 160.27 MB / 160.27 MB [============================================] 100.00% 0sGetting VM IP address... Moving files into cluster... Downloading kubelet v1.10.0 Downloading kubeadm v1.10.0 Finished Downloading kubelet v1.10.0 Finished Downloading kubeadm v1.10.0 Setting up certs... Connecting to cluster... Setting up kubeconfig... Starting cluster components... Kubectl is now configured to use the cluster. Loading cached images from config file.
Step 4: Setup Minikube Context
Now set the Minikube context. The context is what determines which cluster kubectl is interacting with. You can see all your available contexts in the ~/.kube/config file.
[[email protected] ~]# kubectl config use-context minikube Switched to context "minikube". [[email protected] ~]# kubectl cluster-info Kubernetes master is running at https://192.168.99.100:8443 KubeDNS is running at https://192.168.99.100:8443/api/v1/namespaces/kube-system/services/kube-dns:dns/proxy
To further debug and diagnose cluster problems, use ‘kubectl cluster-info dump‘.
With this last command, we have set up Minikube cluster on our system. And ready to use.
For this article, we will deploy a sample application and try to figure out some basic commands to know more about Kubernetes cluster.
Step 1: Create and deploy a sample app.
We are going to use a hell Minikube using echoserver image on port 8080 and expose that as node port because it’s a single node cluster.
[[email protected] ~]# kubectl run hello-minikube --image=k8s.gcr.io/echoserver:1.4 --port=8080 deployment.apps/hello-minikube created [[email protected] ~]# kubectl expose deployment hello-minikube --type=NodePort service/hello-minikube exposed
with these commands, we have created a deployment and exposed our service on port 8080.
Step 2: Get Pod Details and access Our App
Now we will check our pods status and try to access our services.
[[email protected] ~]# kubectl get pod NAME READY STATUS RESTARTS AGE hello-minikube-6c47c66d8-n2995 1/1 Running 0 12m
Now you may access your service by directly hitting curl command on your terminal like below
[[email protected] ~]# curl $(minikube service hello-minikube --url)
Or you may get the URL of your service and access it on a browser
[[email protected] ~]# minikube service hello-minikube --url http://192.168.99.100:31349
Now access http://192.168.99.100:31349 in your browser
Step 3: Clean up
Now we are doing to clean up our deployment and stop Minikube. This can be done so easily by following commands.
[[email protected] ~]# kubectl delete service hello-minikube service "hello-minikube" deleted [[email protected] ~]# kubectl delete deployment hello-minikube deployment.extensions "hello-minikube" deleted [[email protected] ~]# minikube stop Stopping local Kubernetes cluster... Machine stopped.
Well, this brings ends to our Minikube introduction and a sample application deployment. In the next article, we will get to gather with some useful command for Minikube.
Kubernetes Series Links:
Understanding Kubernetes Concepts RHEL/CentOs K8s Part-1
Understanding Kubernetes Concepts RHEL/CentOs k8s: Part-2
How to Install Kubernetes on CentOS/RHEL k8s?: Part-3
How to Install Kubernetes on CentOS/RHEL k8s?: Part-4
How To Bring Up The Kubernetes Dashboard? K8s-Part: 5
How to Run Kubernetes Cluster locally (minikube)? K8s – Part: 6
How To Handle Minikube(Cheatsheet)-3? K8s – Part: 7
How To Handle Minikube(Cheatsheet)-3? K8s – Part: 8
How To Handle Minikube(Cheatsheet)-3? K8s – Part: 9