Install a kubernetes cluster ( using kind) in your laptop/anywhere in just 2 minutes

Before we start, let me introduce to kind which is the tool I will be using here to bring up a kube cluster, so whats kind?:

From : https://github.com/kubernetes-sigs/kind/

kind is a tool for running local Kubernetes clusters using Docker container "nodes".
kind was primarily designed for testing Kubernetes itself, but may be used for local development or CI.

If you have go (1.11+) and docker installed GO111MODULE="on" go get sigs.k8s.io/kind@v0.8.0 && kind create cluster is all you need!

We can use it to create multi-node or multi-control-plane Kubernetes clusters, however, in this article I will bring up a single node cluster which may be the test bed for quickly test or learn something. Yes, multi-node cluster has its own advantages, so I will write next post about the same.[Please see the reference section for multi-node cluster deployment]

Why I blogged about kind today is mainly because of the new kind release happened today ( v0.8.0) which include one of the fixes which I have been waiting for long time ie Clusters that continue working when you reboot your host / docker :

https://github.com/kubernetes-sigs/kind/releases/tag/v0.8.0


KIND v0.8.0 is here with:
- Clusters that continue working when you reboot your host / docker :tada:
- Experimental podman support
- Improved networking (It's always been DNS! & a fix for the pesky iptables :arrow_right: nftables)
- Enhanced errors :pray:

Without much delay lets bring up a kubernetes cluster with version 1.18.x using kind:

$curl -Lo kind https://github.com/kubernetes-sigs/kind/releases/latest/download/kind-Linux-amd64 % Total % Received % Xferd Average Speed Time Time Time Current Dload Upload Total Spent Left Speed 100 147 100 147 0 0 26 0 0:00:05 0:00:05 –:–:– 34 100 629 100 629 0 0 103 0 0:00:06 0:00:06 –:–:– 103 100 9896k 100 9896k 0 0 58671 0 0:02:52 0:02:52 –:–:– 42278

$chmod +x kind

$sudo mv kind /usr/local/bin/

$kind create cluster –image=docker.io/kindest/node:1.18.0 Creating cluster “kind” … ✓ Ensuring node image (kindest/node:v1.18.2) ? ✓ Preparing nodes ? ✓ Writing configuration ? ✓ Starting control-plane ?️ ✓ Installing CNI ? ✓ Installing StorageClass ? Set kubectl context to “kind-kind” You can now use your cluster with:

kubectl cluster-info –context kind-kind

Have a nice day! ?

Above bootstrapped a Kubernetes cluster using a pre-built node image (https://kind.sigs.k8s.io/docs/design/node-image) – you can find it on docker hub kindest/node. If you desire to build the node image yourself, it’s possible too, refer kind documentation for the same. To specify another image to bring up your cluster, you can use the --image flag with the create cluster command.

By default, the cluster will be given the name kind. Use the –name flag to assign the cluster a different context name.

Just to go some more in details about the kind options and how to use it, let’s see below examples which can be used in kind created cluster:

$sudo /usr/local/bin/kind export kubeconfig Set kubectl context to “kind-kind”

$kubectl config use-context kind-kind Switched to context “kind-kind”.

$sudo kubectl get nodes NAME STATUS ROLES AGE VERSION kind-control-plane Ready master 15m v1.18.2 $sudo kubectl get pods –all-namespaces NAMESPACE NAME READY STATUS RESTARTS AGE kube-system coredns-66bff467f8-c92t6 1/1 Running 0 18m kube-system coredns-66bff467f8-kg7zl 1/1 Running 0 18m kube-system etcd-kind-control-plane 1/1 Running 0 18m kube-system kindnet-zz6dt 1/1 Running 0 18m kube-system kube-apiserver-kind-control-plane 1/1 Running 0 18m kube-system kube-controller-manager-kind-control-plane 1/1 Running 0 18m kube-system kube-proxy-sjbcw 1/1 Running 0 18m kube-system kube-scheduler-kind-control-plane 1/1 Running 0 18m local-path-storage local-path-provisioner-bd4bb6b75-n28xd 1/1 Running 0 18m

$ sudo docker exec kind-control-plane crictl images

IMAGE TAG IMAGE ID SIZE docker.io/kindest/kindnetd 0.5.4 2186a1a396deb 113MB docker.io/rancher/local-path-provisioner v0.0.12 db10073a6f829 42MB k8s.gcr.io/coredns 1.6.7 67da37a9a360e 43.9MB k8s.gcr.io/debian-base v2.0.0 9bd6154724425 53.9MB k8s.gcr.io/etcd 3.4.3-0 303ce5db0e90d 290MB k8s.gcr.io/kube-apiserver v1.18.2 7df05884b1e25 147MB k8s.gcr.io/kube-controller-manager v1.18.2 31fd71c85722f 133MB k8s.gcr.io/kube-proxy v1.18.2 312d3d1cb6c72 133MB k8s.gcr.io/kube-scheduler v1.18.2 121edc8356c58 113MB k8s.gcr.io/pause 3.2 80d28bedfe5de 686kB

If you want to get details about your kind cluster:

$ sudo kind help kind creates and manages local Kubernetes clusters using Docker container ‘nodes’

Usage: kind [command]

Available Commands: build Build one of [node-image] completion Output shell completion code for the specified shell (bash, zsh or fish) create Creates one of [cluster] delete Deletes one of [cluster] export Exports one of [kubeconfig, logs] get Gets one of [clusters, nodes, kubeconfig] help Help about any command load Loads images into nodes version Prints the kind CLI version

Flags: -h, –help help for kind –loglevel string DEPRECATED: see -v instead -q, –quiet silence all stderr output -v, –verbosity int32 info log verbosity

Use “kind [command] –help” for more information about a command.

$ sudo /usr/local/bin/kind get nodes kind-control-plane

$ sudo /usr/local/bin/kind get kubeconfig apiVersion: v1 clusters: – cluster: certificate-authority-data: ……… server: https://127.0.0.1:38831 name: kind-kind contexts: – context: cluster: kind-kind user: kind-kind name: kind-kind current-context: kind-kind kind: Config preferences: {} users: – name: kind-kind user: client-certificate-data: …………………. client-key-data: …………. $

$ sudo /usr/local/bin/kind load docker-image alpine Image: “alpine” with ID “sha256:f70734b6a266dcb5f44c383274821207885b549b75c8e119404917a61335981a” not yet present on node “kind-control-plane”, loading…

$ sudo docker exec kind-control-plane crictl images IMAGE TAG IMAGE ID SIZE docker.io/kindest/kindnetd 0.5.4 2186a1a396deb 113MB docker.io/library/alpine latest f70734b6a266d 5.88MB docker.io/rancher/local-path-provisioner v0.0.12 db10073a6f829 42MB k8s.gcr.io/coredns 1.6.7 67da37a9a360e 43.9MB k8s.gcr.io/debian-base v2.0.0 9bd6154724425 53.9MB k8s.gcr.io/etcd 3.4.3-0 303ce5db0e90d 290MB k8s.gcr.io/kube-apiserver v1.18.2 7df05884b1e25 147MB k8s.gcr.io/kube-controller-manager v1.18.2 31fd71c85722f 133MB k8s.gcr.io/kube-proxy v1.18.2 312d3d1cb6c72 133MB k8s.gcr.io/kube-scheduler v1.18.2 121edc8356c58 113MB k8s.gcr.io/pause 3.2 80d28bedfe5de 686kB

At times, we may fail to create an application pod in the above kind cluster due to an error or a behavior where it fails to pull the docker image of the applications deployed. In those cases, the workaround I followed was to create a kind cluster by nullifying the http_proxy configurations as shown below

sudo https_proxy=”” http_proxy=”” all_proxy=”” /usr/local/bin/kind create cluster

Now, go ahead and set up your cluster in 2 mins!! then play with it.

Update:

There was a question about whether kind has loadbalancer type service support?

Answer:

you can do load balancer with metallb [1] on Linux, but docker for Mac / windows Mac/windows have very limited network connectivity. There is an upstream issue that tracks the load balancer support https://github.com/kubernetes-sigs/kind/issues/702 .

Please take a look at https://github.com/kubernetes-sigs/kind/issues/702#issuecomment-624561998 which talks about how the metallb can be used to deploy a load balancer service in Linux setup.

[1] https://mauilion.dev/posts/kind-metallb/

Reference:

If you really got excited about kind and if you would like to deploy multi node cluster, please check this article.

Install a multi node kubernetes cluster using `kind` (kind.sigs.k8s.io)