In this tutorial we will demonstrate how to use KinD (Kubernetes in Docker) to provision local kubernetes clusters for local development.
About
KinD uses container images to run as “nodes”, so spinning up and tearing down clusters becomes really easy or running multiple or different versions, is as easy as pointing to a different container image.
Configuration such as node count, ports, volumes, image versions can either be controlled via the command line or via configuration, more information on that can be found on their documentation:
Creating cluster "cluster-1" ...
â Ensuring node image (kindest/node:v1.24.0) đŧ
â Preparing nodes đĻ
â Writing configuration đ
â Starting control-plane đšī¸
â Installing CNI đ
â Installing StorageClass đž
Set kubectl context to "kind-cluster-1"You can now use your cluster with:
kubectl cluster-info --context kind-cluster-1
Have a question, bug, or feature request? Let us know! https://kind.sigs.k8s.io/#community đ
I highly recommend installing kubectx, which makes it easy to switch between kubernetes contexts.
Create a Cluster with Config
If you would like to define your cluster configuration as config, you can create a file default-config.yaml with the following as a 2 node cluster, and specifying version 1.24.0:
kubectl get nodes -o wide
NAME STATUS ROLES AGE VERSION INTERNAL-IP EXTERNAL-IP OS-IMAGE KERNEL-VERSION CONTAINER-RUNTIME
kind-cluster-control-plane Ready control-plane 2m11s v1.24.0 172.20.0.5 <none> Ubuntu 21.10 5.10.104-linuxkit containerd://1.6.4
kind-cluster-worker Ready <none> 108s v1.24.0 172.20.0.4 <none> Ubuntu 21.10 5.10.104-linuxkit containerd://1.6.4
Deploy Sample Application
We will create a deployment, a service and port-forward to our service to access our application. You can also specify port configuration to your cluster so that you don’t need to port-forward, which you can find in their port mappings documentation
I will be using the following commands to generate the manifests, but will also add them to this post:
kubectl get deployment,pod,service
NAME READY UP-TO-DATE AVAILABLE AGE
deployment.apps/hostname 2/2 22 9m27s
NAME READY STATUS RESTARTS AGE
pod/hostname-7ff58c5644-67vhq 1/1 Running 0 9m27s
pod/hostname-7ff58c5644-wjjbw 1/1 Running 0 9m27s
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
service/hostname-http ClusterIP 10.96.218.58 <none> 80/TCP 5m48s
service/kubernetes ClusterIP 10.96.0.1 <none> 443/TCP 24m