Recently, I needed to deploy a KinD (Kubernetes in Docker) cluster that would be accessible remotely. I had done this before, but never documented the process—so here’s a simple, step-by-step guide for future reference.
1. Create a KinD Cluster Config#
Save the following content as kind-config.yaml
:
kind: Cluster
apiVersion: kind.x-k8s.io/v1alpha4
networking:
apiServerAddress: "0.0.0.0"
nodes:
- role: control-plane
kubeadmConfigPatches:
- |
kind: ClusterConfiguration
apiServer:
certSANs:
- "172.27.13.254" # <-- REPLACE with your host IP
- "localhost"
- "127.0.0.1"
extraPortMappings:
- containerPort: 6443
hostPort: 6443
listenAddress: "0.0.0.0"
protocol: TCP
- role: worker
- role: worker
containerdConfigPatches:
- |-
[plugins."io.containerd.grpc.v1.cri".containerd]
discard_unpacked_layers = false
2. Create the Cluster#
Run:
kind create cluster --name c9s --config kind-config.yaml
Once the cluster is up, run docker ps
on your host. You should see the c9s-control-plane
container, and its PORTS
section should include 0.0.0.0:6443->6443/tcp
. You might also see a 127.0.0.1:RANDOM_PORT->6443/tcp
—this is KinD’s default internal mapping, which you can ignore.
3. Export the Kubeconfig#
kind get kubeconfig --name c9s > c9s-external-kubeconfig.yaml
Now, edit c9s-external-kubeconfig.yaml
. Find the server:
line (it will likely point to https://0.0.0.0:6443
). Change it to use your host IP and port 6443.
4. Test Your Setup#
To quickly test:
cp c9s-external-kubeconfig.yaml ~/.kube/config
kubectl get nodes
You should see output similar to:
NAME STATUS ROLES AGE VERSION
c9s-control-plane Ready control-plane 6m3s v1.33.1
c9s-worker Ready <none> 5m48s v1.33.1
c9s-worker2 Ready <none> 5m48s v1.33.1
That’s it! You now have a KinD cluster accessible from outside your host.