Kubernetes - Setting up a local development cluster
Introduction to Kubernetes
Kubernetes has been around for a while and it’s the leading-edge platform technology today. I am sure a lot of us would have heard about it, so let’s see what exactly Kubernetes is and how is it useful for us.
Still confused?? 😕
Let’s go by the definition, Kubernetes, also known as K8s, is a popular open source platform for container orchestration — that is for managing containerised applications across multiple hosts.
To put it in simpler words, all we have to do is containerise our application and the rest of the things like deployment, availability and scaling of the application in terms of the resource requirements as per the required load is all taken care by Kubernetes.
A Kubernetes cluster consists of 2 main components:
- Control Plane Components : Master node, manages all worker nodes
- Worker Node Components : Runs containerised applications
Here’s a diagram of a Kubernetes cluster with all the components tied together. More detailed explanation of each of these components can be found here.
Now that we have a basic understanding of Kubernetes, why not let’s setup a cluster of our own, let’s begin with exploring the different tools available for setting up a local Kubernetes cluster.
Development environment setup: Time to explore different tools!
We can deploy a Kubernetes cluster on a local machine, cloud, on-premises datacentre, or a managed Kubernetes cluster on public cloud.
kind
kind is a tool that lets us run Kubernetes on local computer. It just requires Docker installed and configured. That’s it, we don’t need to install any VirtualBox or any other hosted hypervisor or worry about its installation steps.
minikube
minikube is a tool that lets us run Kubernetes locally. minikube runs a single-node Kubernetes cluster on local computer and can be run on any operating systems (Windows, Linux or MacOS). Though it is very user friendly, but it still requires VM installation (but the latest versions can be run on containers too).
kubeadm
kubeadm is a tool to create and manage Kubernetes clusters. Installation process is a bit tricky one with kubeadm but it performs the actions necessary to get a minimum viable, secure cluster up and running.
Comparing the above tools around their supported features:
Setting up local Kubernetes Cluster using Kind
Kind as the name suggests stands for “Kubernetes inside Docker”. It runs a local cluster by using Docker containers as “nodes”.
Why kind?
1. Using kind, we are already testing our workloads on containerd because while it uses docker or podman on the host, it uses CRI /containerd inside the nodes and does not use dockershim. I know this might not be an easy one to understand, but I’ll cover this in detail in another post on dockershim deprecation.
2. One feature that I personally enjoy is that there is no need to push images to any external image registry such as dockerhub, ECR, etc, we can directly build and load the image inside the kind cluster and run our service. This saves a lot of time to push and pull image from registry every time we want to try out our changes and thus helps increases productivity.
3. It allows support for multi master and multi node clusters, which also helps in testing out High Availability (HA) / Disaster Recovery (DR) scenarios.
Sounds Interesting? 😄 Why not let’s try it out by ourself.
Prerequisites:
In this blog we will mostly have commands for MacOS setup i.e., using Docker for Mac, but for other OS as well you can refer here:
· Docker
· kubectl
Time to build clusters with kind! ☁️
To create a Kubernetes cluster, just run the below command:
kind create cluster
Voila! That’s it 😲, we are done with setting up our own Kubernetes cluster. Now let’s verify if the node and pods are created successfully.
kind create cluster -- name kind-2 #To create multiple clusters
To list all the kind clusters:
kind get clusters
To interact with a specific cluster, just specify the cluster name as context accordingly:
kubectl cluster-info --context kind-kindkubectl cluster-info --context kind-kind-2
To delete the cluster, if the flag — name is not specified, kind will use the default cluster context name kind and delete that cluster:
kind delete cluster
Well, that’s it for now!
We will also create clusters with custom config i.e., multiple master or worker nodes or any required addons and deploy a sample application on our local cluster using kind but that will be covered in next post, so stay tuned!!
Feel free to drop any questions or suggestions that you have. Till then Happy Reading!! 😄 😄