Screenshot from the article

Kubernetes is the go-to platform for container orchestration, but setting up a full-fledged cluster can be complex. Kind (Kubernetes in Docker) simplifies this by enabling users to run Kubernetes clusters inside Docker containers.

In this guide, we’ll cover:

  • Installing and configuring Kind (Install guide)
  • Creating and managing clusters
  • Deploying applications
  • Advanced Kind features
  • Frequently Asked Questions (FAQs) for troubleshooting and interview prep

Prerequisites

Before getting started, ensure you have:

  • Docker installed (Kind runs Kubernetes clusters inside Docker containers)
  • kubectl installed (to interact with the cluster)

Step 1: Installing Kind

macOS & Linux (via Homebrew)

brew install kind

Linux (Manual Installation)

curl -Lo ./kind https://kind.sigs.k8s.io/dl/v0.20.0/kind-linux-amd64
chmod +x kind
mv kind /usr/local/bin/

Windows (via Chocolatey)

choco install kind

Verify installation:

kind version

Step 2: Creating a Kubernetes Cluster

Creating a cluster is straightforward:

kind create cluster --name my-cluster

By default, Kind creates a single-node cluster. To verify the cluster:

kubectl cluster-info --context kind-my-cluster

Multi-Node Cluster Configuration

Kind allows multi-node clusters with a custom configuration file:

kind: Cluster
apiVersion: kind.x-k8s.io/v1alpha4
nodes:
- role: control-plane
- role: worker
- role: worker

Create the cluster:

kind create cluster --name my-multi-node-cluster --config kind-config.yaml

Check running nodes:

kubectl get nodes

Step 3: Deploying Applications on Kind

Deploy a Sample Nginx App

kubectl create deployment nginx --image=nginx
kubectl expose deployment nginx --port=80 --type=NodePort

Retrieve the service details:

kubectl get services nginx

To access the application, forward a local port:

kubectl port-forward service/nginx 8080:80

Now, visit http://localhost:8080 to see Nginx running.

Step 4: Persistent Storage with Kind

By default, Kind uses ephemeral storage, but you can configure persistent volumes:

apiVersion: v1
kind: PersistentVolume
metadata:
  name: kind-pv
spec:
  capacity:
    storage: 1Gi
  accessModes:
    - ReadWriteOnce
  hostPath:
    path: /mnt/kind-pv

Apply the storage configuration:

kubectl apply -f pv.yaml

Step 5: Networking and Ingress in Kind

Kind does not include an Ingress Controller by default. To enable it:

kubectl apply -f https://raw.githubusercontent.com/kubernetes/ingress-nginx/main/deploy/static/provider/kind/deploy.yaml

Verify installation:

kubectl get pods -n ingress-nginx

Create an Ingress resource:

apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: example-ingress
spec:
  rules:
  - host: example.local
    http:
      paths:
      - path: /
        pathType: Prefix
        backend:
          service:
            name: nginx
            port:
              number: 80

Apply the Ingress resource:

kubectl apply -f ingress.yaml

Update /etc/hosts to map example.local to 127.0.0.1 and test in the browser.

Step 6: Managing and Deleting Clusters

List clusters:

kind get clusters

Delete a cluster:

kind delete cluster --name my-cluster

Frequently Asked Questions (FAQs)

Q1: How do I troubleshoot Kind cluster issues?

Use the following commands:

kubectl get nodes
kubectl describe node <node-name>
kubectl logs <pod-name>

Additionally, check Kind logs:

docker logs kind-control-plane

Q2: Can Kind be used in CI/CD pipelines?

Yes! Kind is great for CI/CD as it runs entirely in Docker. Example (GitHub Actions):

jobs:
  test:
    runs-on: ubuntu-latest
    steps:
      - name: Set up Kind
        run: |
          kind create cluster
          kubectl cluster-info

Q3: How do I use Kind with Helm?

helm install my-app stable/nginx-ingress

Verify:

kubectl get all -n default

Q4: How do I persist data in Kind?

Mount a persistent volume:

apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  name: kind-pvc
spec:
  accessModes:
    - ReadWriteOnce
  resources:
    requests:
      storage: 1Gi
kubectl apply -f pvc.yaml

Q5: How do I expose services externally?

Use kubectl port-forward or an Ingress Controller:

kubectl port-forward service/my-service 8080:80

Conclusion

Kind provides a lightweight and powerful way to run Kubernetes locally. In this guide, we covered:

✅ Installing and setting up Kind

✅ Creating single and multi-node clusters

✅ Deploying applications and using persistent storage

✅ Managing networking and Ingress

✅ FAQs to help with troubleshooting and interview prep

By mastering Kind, you can efficiently test Kubernetes applications in a local environment. Stay tuned for more Kubernetes insights! 🚀

📢 Have questions or feedback? Drop a comment below or connect with me on Twitter/X@spysood!

Originally published on Medium.