I’m sure you’ve heard the term Kubernetes by now, and maybe you’re curious how you can get started with this technology. In this guide I will demonstrate how you can run Kubernetes locally on your Linux Desktop or Linux Server using MiniKube.
This guide will walk you through how to install Kubernetes using minikube and deploy an application to the cluster. Since this is being deployed to 1 Server / PC, this is referred to as a Single Node Cluster. This type of deployment for development, testing, or learning. Please don’t use this guide for the production of Kubernetes.
Prerequisites:
Basic Linux Knowlege
Server or PC running Linux (For this guide, I am using CentOS)
Docker installed (If you are running inside a VM)
Internet Connection
Settings up the Host
First, we need to make sure we have the latest updates, run the command,
sudo yum -y update
This will take a few minutes to run.
Once that is done, we will need to add the EPEL repository to be able to pull the packages we need for the system.
sudo yum -y install epel-release
Install the following packages:
sudo yum -y install libvirt qemu-kvm virt-install virt-top libguestfs-tools
Start the libvirtd service
sudo systemctl start libvirtd
Enable the libvirtd service (this allows it to boot at startup)
sudo systemctl enable libvirtd
Check the status of the service
systemctl status libvirtd
Add your username to the libvirt group
sudo usermod -a -G libvirt $(whoami)
The next step is to edit the conf file for libvirtd
sudo vi /etc/libvirt/libvirtd.conf
Uncomment these lines, (in vi you can hit “/” and type “unix_sock_group” and it will search the file for that and take you straight to it.) If you are new to VI, hit “i” to get into insert mode, which will allow you to enter text and remove as needed. After you make your changes, hit “esc” then “:wq” to write and quit.
unix_sock_group = "libvirt"
unix_sock_rw_perms = "0770"
Before:
After:
Restart the libvirtd service and check the status
sudo systemctl restart libvirtd.service
sudo systemctl status libvirtd.service
Your host is now set up and ready to install MiniKube
Installing minikube
Download MiniKube using this command
wget https://storage.googleapis.com/minikube/releases/latest/minikube-linux-amd64
Change permissions to give it execute rights
chmod +x minikube-linux-amd64
Move the binary to /usr/local/bin
sudo mv minikube-linux-amd64 /usr/local/bin/minikube
To test to see if it’s working
minikube version
Now, we need to setup KubeCTL. This is what we will use to manage the cluster.
Pull the package down
curl -LO https://storage.googleapis.com/kubernetes-release/release/`curl -s https://storage.googleapis.com/kubernetes-release/release/stable.txt`/bin/linux/amd64/kubectl
Give kubectl execute rights
chmod +x kubectl
Move it to the usr/local/bin folder
sudo mv kubectl /usr/local/bin/
Check the install
kubectl version --client -o json
Start MiniKube
minikube start --driver=kvm2
If you are running inside a VM (docker must be installed)
minikube start --driver=docker
Your Single Node Cluster is running! To see the running pods
kubectl get pods --all-namespaces
Deploy a Hello World Application
We will deploy a sample application and test it
kubectl create deployment web --image=gcr.io/google-samples/hello-app:1.0
Expose the deployment
kubectl expose deployment web --type=NodePort --port=8080
Get the application URL
minikube service web --url
Now, CURL the URL to see the output
curl http://192.168.39.99:30326
To see the runnings pods
kubectl get pods
To see the deployment
kubectl get deployments
To delete the web deployment
kubectl delete deployment web
Congrats! You have successfully installed minikube and deployed a sample application. I hope this guide was able to get you started as this doesn’t even scratch the surface when it comes to Kubernetes. I will be posting more guides for Kubernetes in the very near future.