Creating k8s clusters locally for dev setup using kind
Overview:
Kubernetes is an open-source container orchestration system for automating software deployment, scaling, and management. Originally designed by Google, the project is now maintained by the Cloud Native Computing Foundation. The name Kubernetes originates from Greek, meaning helmsman or pilot.
Options:
kubernetes can be setup in multiple ways. It all depends on for which purpose you are creating it. Are you creating it for Dev setup or production setup?
Following are some of the options that we have for setting up k8s.
Dev
- minikube
- k3d
- kind
- k3s
- microk8s
Production
- kubeadm
- kubespray
- kops
etc etc…
In this setup we are going to use kind(kubernetes in docker) to setup kubernetes cluster.
Pre-requisites:
- docker
if you dont have docker installed follow the instructions specificed here.
Installing Kind:
I am using Ubuntu machine. Below mentioned instructions works for other operating systems as well.
Linux OS:
curl -Lo ./kind https://kind.sigs.k8s.io/dl/v0.17.0/kind-linux-amd64
chmod +x ./kind
sudo mv ./kind /usr/local/bin/kind
MacOS:
# for Intel Macs
[ $(uname -m) = x86_64 ]&& curl -Lo ./kind https://kind.sigs.k8s.io/dl/v0.17.0/kind-darwin-amd64
# for M1 / ARM Macs
[ $(uname -m) = arm64 ] && curl -Lo ./kind https://kind.sigs.k8s.io/dl/v0.17.0/kind-darwin-arm64
chmod +x ./kind
mv ./kind /some-dir-in-your-PATH/kind
Windows:
curl.exe -Lo kind-windows-amd64.exe https://kind.sigs.k8s.io/dl/v0.17.0/kind-windows-amd64
Move-Item .\kind-windows-amd64.exe c:\some-dir-in-your-PATH\kind.exe
Note:
In all the above instructions we are installing specific version i.e v0.17.0. If you want to install other versions refer here.
You can verify whether kind is installed or not by executing either of the below mentioned commands.
kind version
kind --help
Installing k8s clusters using kind
Execute the below mentioned command to create k8s cluster named “cluster1”.
kind create cluster --name cluster1
Note: name attribute in the above command refers to k8s cluster name. you can replace the value as per your needs.
execute the below command to list the number of k8s clusters created using kind.
kind get clusters
The above command output should display the number of clusters created.
Lets try to connect to the cluster.
kubectl cluster-info --context kind-cluster1
Note: context attribute value in the above command must be in the format of kind-<clustername>(in our case kind-cluster1).
Now we have connected to “cluster1”. you can execute the traditional kubectl commands.
for ex:
kubectl get nodes
kubectl cluster-info --context kind-cluster1
Note: wait until the node gets ready before moving further.
Note: Another important thing to note is that there will be only one node(control plane) that gets created if you have followed above instructions. All the workloads will be placed on this single node which is a control plane node.
Lets try to deploy the sample pod and verify that it gets launched on this single control plane node.
kubectl run nginx --image nginx
kubectl get pods -o wide
From the above screenshot we can confirm that pod gets launched on controlplane node.
Tear down the cluster
kind delete cluster --name cluster1
Note: name attribute value in the above command refers to cluster name.
Awesome. We were able to create k8s cluster successfully. but wait we created cluster with single node right that too with a control plane node. what if I want to create cluster with multiple nodes? can we achieve it with using kind?
well the answer is yes. we can do that using Kind. Lets discuss about it in my next blog.
Feel free to provide any comments or suggestions.