Table of Contents
You must be asking a question "How do I setup Kubernetes Cluster?" and you may end up getting different answers from different search results and it can be overwhelming for beginners. Kubernetes is a sophisticated system, and getting it installed and managing it well isn't an easy task.
However, as the Kubernetes community has expanded and matured, more and more user-friendly tools have emerged. As of today, based on your requirements, there are a lot of options to choose from:
- If you are using physical (bare-metal) servers or virtual machines (VMs),
Kubeadmis a good fit.
- If you're running on cloud environments, kops and Kubespray can ease Kubernetes installation, as well as integration with the cloud providers.
- If you want to drop the burden of managing the Kubernetes control plane, almost all cloud providers have their Kubernetes managed services, such as Google Kubernetes Engine (GKE), Amazon Elastic Kubernetes Service (EKS), Azure Kubernetes Service (AKS), and IBM Kubernetes Service (IKS).
- If you just want a playground to study Kubernetes , Minikube and Kind can help you spin up a Kubernetes cluster in minutes.
So, as you see you have a bunch of options to choose from to deploy your first Kubernetes Cluster. In this Kubernetes Tutorial I will cover the steps to install kubernetes cluster on CentOS 8 using Minikube.
Overview on Minikube
Minikube is a tool that can be used to set up a single-node cluster, and it provides handy commands and parameters to configure the cluster. It primarily aims to provide a local testing environment. It packs a VM containing all the core components of Kubernetes that get installed onto your host machine, all at once. This allows it to support any operating system, as long as there is a virtualization tool (also known as a Hypervisor) pre-installed.
As we learned in our previous tutorial, a Kubernetes cluster consists of a controller and worker node where both node types have their own set of components. But since Minikube is a single node cluster, it will contain all the cluster components inside this single node, which would look something like following:
The minimum resource requirement for your physical host:
- 2 CPUs or more
- Minimum 2GB of free memory
- Minimum 20GB of free disk space
Additionally your host must have:
- Working internet connection
- Virtualization technology must be enabled in BIOS to support hypervisor
- Anyone of the supported hypervisor
The following are the most common Hypervisors supported by Minikube:
- VirtualBox (works for all operating systems)
- KVM (Linux-specific)
- Hyperkit (macOS-specific)
- Hyper-V (Windows-specific)
I will use my Laptop which is installed with Windows 10 and Oracle VirtualBox to setup Minikube.
Install Oracle VirtualBox
You may also choose to install different hypervisor based on your environment, we will use Oracle VirtualBox as I already use this for writing most of my tutorials.
Download VirtualBox software from their official repository. I have written another article to install Oracle Virtual Box, which is quiet straight forward on Windows. Just double click the downloaded software and follow the instructions, leave all the settings to default.
Download and install kubectl
The Kubernetes command-line tool,
kubectl, allows you to run commands against Kubernetes clusters. You can use
kubectl to deploy applications, inspect and manage cluster resources, and view logs.
- If you are using a different platform other than Windows then you can follow official guide to download the kubectl for your platform
- I have created a folder inside my C drive "
C:\Kubernetes" where I will be storing these software.
- As the time of writing this tutorial, kubectl 1.19 was the latest stable release available at this link.
- Or if you have curl installed, use this command:
curl -LO https://storage.googleapis.com/kubernetes-release/release/v1.19.0/bin/windows/amd64/kubectl.exe
- To find out the latest stable version (for example, for scripting), take a look at https://storage.googleapis.com/kubernetes-release/release/stable.txt.
- Test to ensure the version of
kubectlis the same as downloaded:
C:\Kubernetes>kubectl version --client
Output from my setup:
Download and install Minikube
- You can follow the official guide to get the latest available minikube package for your respective platform. For Windows you can download the latest available minikube from https://storage.googleapis.com/minikube/releases/latest/minikube-installer.exe
- I have downloaded minikube and placed it inside
C:\Kubernetesfolder which I created in the previous step.
- Next you can double click on the downloaded installer and just follow the on screen instructions to install the software.
- Once installed, open a command prompt and enter "
minikube version" to make sure it is working as expected.
Build and start your minikube cluster
Next we will deploy our Kubernetes Cluster for which we will execute "minikube start". This command will download the minikube ISO image and deploy a new Virtual Machine using Oracle VirtualBox which will take some time depending upon your network speed.
minikube startto start the cluster services before you can access it.
minikube has successfully deployed our single node cluster, you can verify the same on your Oracle VirtualBox where you should have a new VM in running state.
Interact with your cluster
The following commands should help establish that the Kubernetes cluster that was started by Minikube is running properly.
C:\Kubernetes>minikube status minikube type: Control Plane host: Running kubelet: Running apiserver: Running kubeconfig: Configured
Now, let's look at the version of the kubectl client and Kubernetes server:
C:\Kubernetes>kubectl version --short Client Version: v1.19.0 Server Version: v1.19.2
To check the machines comprise the cluster and get some basic information about them:
C:\Kubernetes>kubectl get node NAME STATUS ROLES AGE VERSION minikube Ready master 112m v1.19.2
Now you should have Minikube set up with a single-node Kubernetes cluster.
Now that our cluster node is UP and running, we can create our first Pod (which is basically a container), but before that verify if there is already any pod available on the minikube cluster:
C:\Kubernetes>kubectl get pods No resources found in default namespace.
Since the cluster is freshly installed, we did not had any pods. I will create a new pod "
C:\Kubernetes>kubectl create deployment hello-minikube --image=k8s.gcr.io/echoserver:1.4 pod/hello-minikube created
Now verify the available pods, currently the status shows as "
C:\Kubernetes>kubectl get pods NAME READY STATUS RESTARTS AGE hello-minikube-6ddfcc9757-gtr9s 1/1 ContainerCreating 1 19h
Wait for sometime and execute the same command, now the status of the pod shows as running:
C:\Kubernetes>kubectl get pods NAME READY STATUS RESTARTS AGE hello-minikube-6ddfcc9757-gtr9s 1/1 Running 1 3m2s
This is basically a webserver and to be able to access it we need to execute following command:
C:\Kubernetes>kubectl expose deployment hello-minikube --type=NodePort --port=8080 service/hello-minikube exposed
To get the URL of the web server
C:\Kubernetes>minikube service hello-minikube --url http://192.168.99.100:31068
Now we can use this URL to access our application
We are done with this demonstration so I will delete the deployment
C:\Kubernetes>kubectl delete deployment hello-minikube deployment.apps "hello-minikube" deleted
Now we don't have any more pods running:
C:\Kubernetes>kubectl get pods No resources found in default namespace.
Manage your cluster
To pause Kubernetes without impacting deployed applications use:
Lastly I will stop my minikube cluster which will power off the virtual machine:
C:\Kubernetes>minikube stop * Stopping node "minikube" ... * 1 nodes stopped.
To delete all the minikube clusters
minikube delete --all
Minikube is mostly used to setup (Proof-of-Concept) POC environment to learn Kubernetes Cluster. Although I would be using kubeadm to setup multi-node Kubernetes Cluster in my next article which I will use to demonstrate the entire Kubernetes Tutorial. In this article, you learned the steps to deploy a cluster using minikube on your WIndows host machine, similarly you can deploy cluster on any other host environment such as Ubuntu, CentOS etc.