- Published on
Building and running Kubernetes with kind
I use kind a lot to spin up Kubernetes clusters locally. Kind also lets you compile the Kubernetes source code into node images that you use to run clusters with. This is what I do to quickly build and test changes to the Kubernetes source code.
Note: You can also use the
hack/local-up-cluster.sh
script to spin up a Kubernetes cluster from source. local-up-cluster only works in Linux environments and is not supported for MacOS however.
Installing kind
I'm installing kind on my Mac with brew.
brew install kind
Once you've installed kind, you can quickly spin up clusters in your machine. Each node of your cluster would be running as a docker container in your machine.
kind create cluster --name test-cluster
Building your node image from source
You can clone kubernetes/kubernetes and run the following from inside the repository to build the source code into a kind node image which you can use to create clusters.
kind build node-image --arch arm64 .
I'm passing the arch flag as arm64
since I'm using an M1 MacBook Pro. Also note that I'm passing the path to the kubernetes source code as an argument here. Since we're running the command from inside the cloned repository, this is the .
directory.
kind cluster config
Once the above command finishes running, you can see that a new container image kindest/node:latest
will be created in your machine. This is the source code compiled into a container image. You can use the node image directly with kind create cluster
or you can setup your cluster with a configuration file. The kind config file lets you configure things like feature gates for different each components, set values for different flags and so on.
Here's an example config file for a cluster with 3 worker nodes and the PodLifecycleSleepActionAllowZero
feature gate turned on:
kind: Cluster
apiVersion: kind.x-k8s.io/v1alpha4
name: sleep-cluster
featureGates:
PodLifecycleSleepActionAllowZero: true
nodes:
- role: control-plane
image: kindest/node:latest
- role: worker
image: kindest/node:latest
- role: worker
image: kindest/node:latest
- role: worker
image: kindest/node:latest