
- Kubernetes Tutorial
- Kubernetes - Home
- Kubernetes - Overview
- Kubernetes - Architecture
- Kubernetes - Setup
- Kubernetes - Setup on Ubuntu
- Kubernetes - Images
- Kubernetes - Jobs
- Kubernetes - Labels & Selectors
- Kubernetes - Namespace
- Kubernetes - Node
- Kubernetes - Service
- Kubernetes - POD
- Kubernetes - Replication Controller
- Kubernetes - Replica Sets
- Kubernetes - Deployments
- Kubernetes - Volumes
- Kubernetes - Secrets
- Kubernetes - Network Policy
- Advanced Kubernetes
- Kubernetes - API
- Kubernetes - Kubectl
- Kubernetes - Kubectl Commands
- Kubernetes - Creating an App
- Kubernetes - App Deployment
- Kubernetes - Autoscaling
- Kubernetes - Dashboard Setup
- Kubernetes - Helm Package Management
- Kubernetes - CI/CD Integration
- Kubernetes - Persistent Storage and PVCs
- Kubernetes - RBAC
- Kubernetes - Logging & Monitoring
- Kubernetes - Service Mesh with Istio
- Kubernetes - Backup and Disaster Recovery
- Managing ConfigMaps and Secrets
- Running Stateful Applications
- Multi-Cluster Management
- Security Best Practices
- Kubernetes CRDs
- Debugging Pods and Nodes
- K9s for Cluster Management
- Managing Taints and Tolerations
- Horizontal and Vertical Pod Autoscaling
- Minikube for Local Development
- Kubernetes in Docker
- Deploying Microservices
- Blue-Green Deployments
- Canary Deployments with Commands
- Troubleshooting Kubernetes with Commands
- Scaling Applications with Kubectl
- Advanced Scheduling Techniques
- Upgrading Kubernetes Clusters
- Kubernetes Useful Resources
- Kubernetes - Quick Guide
- Kubernetes - Useful Resources
- Kubernetes - Discussion
Kubernetes in Docker
As Kubernetes becomes the backbone of modern infrastructure, many of us look for efficient ways to spin up local clusters for development, experimentation, and testing. Minikube is one popular choice, but there's another powerful, lightweight alternative worth knowing about: KinD (Kubernetes in Docker).
KinD lets us run Kubernetes clusters in Docker containers, making it incredibly fast and resource-efficient. In this chapter, weâll walk through the steps to install KinD, spin up a cluster, interact with it, and deploy a basic application â all on our local machine.
Why KinD?
Letâs take a quick look at why KinD is important:
- Designed for local development and CI pipelines.
- Lightweight and fast â runs on Docker containers.
- Supports multi-node clusters.
- Actively maintained by the Kubernetes SIG community.
- No need for VirtualBox or VMs â just Docker.
Prerequisites
Before we get started, letâs make sure we have everything we need:
- A modern Linux, macOS, or Windows machine with at least:
- 4 GB of RAM
- 2+ CPU cores
- Internet connectivity (to download KIND images)
- Docker installed and running.
- Kubernetes Cluster installed and running.
Install KinD
The easiest way is to grab the binary using curl:
$ curl -Lo ./kind https://kind.sigs.k8s.io/dl/v0.22.0/kind-linux-amd64 $ chmod +x ./kind $ sudo mv ./kind /usr/local/bin/kind
Output
100 97 100 97 0 0 814 0 --:--:-- --:--:-- --:--:-- 815 100 6245k 100 6245k 0 0 5972k 0 0:00:01 0:00:01 --:--:-- 121M
To confirm the installation:
$ kind version
Output
kind v0.22.0 go1.20.13 linux/amd64
Create a Cluster
With Docker running in the background, we can now create our first KinD cluster. Simply run:
$ kind create cluster
Output
Creating cluster "kind" ... â Ensuring node image (kindest/node:v1.29.2) ð¼ â Preparing nodes ð¦ â Writing configuration ð â Starting control-plane ð¹ï¸ â Installing CNI ð â Installing StorageClass ð¾ Set kubectl context to "kind-kind"
To see if the cluster is running:
$ kubectl get nodes
Output
NAME STATUS ROLES AGE VERSION kind-control-plane Ready control-plane 1m v1.29.2
Create a Multi-Node Cluster (Optional)
If we want to simulate a real-world cluster with multiple nodes, KinD lets us define it using a config file.
Create a file called kind-multinode.yaml with the following lines:
kind: Cluster apiVersion: kind.x-k8s.io/v1alpha4 nodes: - role: control-plane - role: worker - role: worker
Then create the cluster:
$ kind create cluster --name my-multinode-cluster --config kind-multinode.yaml
Output
Creating cluster "my-multinode-cluster" ... â Ensuring node image (kindest/node:v1.29.2) ð¼ â Preparing nodes ð¦ â Writing configuration ð â Starting control-plane ð¹ï¸ â Installing CNI ð â Installing StorageClass ð¾ Set kubectl context to "kind-my-multinode-cluster"
Check the nodes
To check the status of your cluster nodes, run:
$ kubectl get nodes
Output
NAME STATUS ROLES AGE VERSION kind-my-cluster-control-plane Ready control-plane 2m v1.29.2 kind-my-cluster-worker-1 Ready worker 2m v1.29.2 kind-my-cluster-worker-2 Ready worker 2m v1.29.2
Deploy an Application
Letâs deploy a simple NGINX app to test our setup:
$ kubectl create deployment nginx --image=nginx
Output
deployment.apps/nginx created
Expose the deployment:
$ kubectl expose deployment nginx --port=80 --type=NodePort
Output
service/nginx exposed
Get the Service
$ kubectl get svc
Output
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE kube-dns ClusterIP 10.96.0.10 <none> 53/UDP,53/TCP 2m nginx NodePort 10.96.0.175 <none> 80:32123/TCP 1m
Access the Service
To access the service, we need the Docker container's IP:
$ docker exec -it kind-control-plane curl localhost:32123
Output
<!DOCTYPE html> <html> <head> <title>Welcome to nginx!</title> </head> <body> <h1>Welcome to nginx!</h1> <p>If you see this page, the nginx web server is successfully installed and working. Further configuration is required.</p> <p>For online documentation and support please refer to <a href="http://nginx.org/">nginx.org</a>.<br/> Commercial support is available at <a href="http://nginx.com/">nginx.com</a>. </p> <p><em>Thank you for using nginx.</em></p> </body> </html>
Managing KinD Clusters
List All Clusters:
$ kind get clusters
Output
kind my-multinode-cluster
Delete a Cluster:
$ kind delete cluster
Output
deleting cluster "kind"
Or delete a specific one:
$ kind delete cluster --name my-multinode-cluster
Output
deleting cluster "my-multinode-cluster"
Load Docker Images into KinD
If we build an image locally and want to use it inside KinD:
$ kind load docker-image my-custom-image:latest
Output
Loaded image: my-custom-image:latest
Useful Tips
- KinD is great for CI/CD: You can spin up and tear down clusters quickly during test pipelines.
- Great for testing Kubernetes releases, as you can specify the version when creating a cluster:
$ kind create cluster --image kindest/node:v1.29.0
KinD is not meant for production â itâs a dev/test tool. You can also install Ingress controllers, MetalLB, and other components manually in KinD clusters.
Troubleshooting
Docker Not Running? KinD wonât work unless Docker is up and running. Make sure to start the Docker daemon.
kubectl context mismatch? KinD automatically updates the kubeconfig file. To switch contexts:
$ kubectl config use-context kind-kind
Conclusion
KinD is a fantastic tool when we want quick access to a Kubernetes environment on our local machine. Itâs lightweight, easy to configure, and fits perfectly into our dev and CI workflows. Using Docker containers, we avoid the overhead of VMs, making cluster startup and teardown incredibly fast.
Whether weâre building controllers, testing applications, or working on Kubernetes itself, KinD gives us a production-like environment locally â no VMs or cloud needed.