Deploy a Multi-node Kubernetes cluster in 5 minutes
Kubernetes is the most adopted open-source platform to orchestrate containers. Here I will show you how to create a multi-node cluster in 5 minutes using kind. Here we are going to use run docker container as Kubernetes worker nodes using a tool called kind.
Kubernetes Architecture
Before we jump into cluster creation, lets get to know about Kubernetes architecture.
Every Kubernetes node will have a container runtime to run the container. For master nodes, will have an API server, controller manager, scheduler, and kubelet. For the worker node, it will have kubectl and kube-proxy.
Also Learn more about each components here.
KIND
Kind is a simple tool but has some powerful and unique features that make running local Kubernetes clusters more convenient. Kind is Kubernetes SIGs project but is quite different compared to minikube. It moves the cluster into Docker containers. When compared to spawning VM, this results in a significantly faster startup time.
Nodes can be either physical machines on data centers and virtual machines on cloud providers. Recommended VRAM requirement is 8GB.
Prerequisites
This tool requires you to possess either Docker or Podman installed.
Optional Packages
1. The Kubernetes command-line tool, kubectl installed.
2. Install jq.
Now install kind using any of the below two steps.
1.Install kind using golang
Kind publishes its Go packages that are used behind the scenes if you want to programmatically create a Kubernetes cluster. If you want to learn more, take a look at the GoDocs and see how KUDO uses kind for its integration tests.
Download latest golang packages from here.
wget https://golang.org/dl/go1.16.6.linux-amd64.tar.gz
sudo tar xzf go1.16.6.linux-amd64.tar.gz -C /usr/local/
export PATH=$PATH:/usr/local/go/bin
GO111MODULE="on" go get sigs.k8s.io/kind@v0.11.1
- After step 4, go directory gets created. Now export the PATH to
export PATH=$PATH:~/go/bin
2. Install kind using binary
The instructions we will be following will create a “kind” file in your home directory and set appropriate permissions to the file and move it to /usr/bin
location .
curl -Lo ./kind https://kind.sigs.k8s.io/dl/v0.11.0/kind-linux-amd64
chmod +x ./kind
sudo mv ./kind /usr/bin/
or/usr/local/bin/
verify the version using -> kind version
kind v0.11.0 go1.16.4 linux/amd64
Creating a single node kind-cluster:
We will first start by creating a single node cluster. To create a single master node running inside a docker container execute kind cluster create
Creates a default cluster name as kind. Use --name=<cluster-name>
to specify cluster name while creating a cluster.k config get-contexts
to list the currently active clusters.
To switch to different cluster,
k config use-context <cluster-name>
Creating a multi-node kind-cluster:
To create a multinode kind-cluster environment use the yaml file.
Use this config file while creating the cluster to create a multi-node Kubernetes cluster with 3 control planes and 3 worker nodes.
kind create cluster --config configs/control-plane-ha.yaml
Validate the cluster nodes created by executing, kubectl get nodes
Cluster Configurations:
By default, the cluster access configuration is stored in ${HOME}/.kube/config
Set the KUBECONFIG environment with export KUBECONFIG=${HOME}/.kube/config
. In terminal use kind get kubeconfig
to validate your configurations.
Changing the node image:
If you want to use the older image, you can specify it while creating the cluster
kind create cluster --image kindest/node:v1.20.7@sha256:cbeaf907fc78ac97ce7b625e4bf0de16e3ea725daf6b04f930bd14c67c671ff9
Every version of kind supports the specific list of versions of Kubernetes. you can see the list of supported versions of Kubernetes from the release page.
Also, you can pass the specific images through the config file for every node.
Dynamic Volume Provisioning:
If you want to attach persistent storage to your cluster, Kind comes with a pre-configured default Storage Class while creating the kind cluster. using kubectl get sc
cmd to see the list of available storage classes present.
WaitforFirstConsumer in volumebindingmode indicates pvc will not get bound until it gets attached to a pod.
Create a pvc.yaml file.
kubectl create -f pvc.yaml
We have created a persistent volume claim(pvc) and Now we will attach it to a busybox pod.
kubectl create -f busybox.yaml
Validate the created pv, pvc using kubectl get pv,pvc
and kubectl get pods
Now that we have created a multi-node cluster backed by pvc and mounted it on busybox.
You must expose your service in order for your user to be able to access it after it has been deployed in Kubernetes. There are three ways to access the cluster from outside: ingress, load balancer, and nodeport.
Delete cluster:
It is very simple to remove the Kind cluster.
kind delete cluster
When I want to load my local images directly into the cluster, Kind cluster comes in handy. This saves me a few extra steps of repairing a registry and pushing my image each time I want to make a change. The image is available for use in my cluster with a simple kind load docker-image app:latest
command.