Sub topic 15
Configuring multi-node clusters
This chapter assumes you can create a kind cluster, read its kubeconfig context, and apply a manifest. A single-node cluster hides problems that appear when pods spread across machines. A multi-node cluster lets you test scheduling, replica spread, and node failure on your own machine.
Why add nodes
On one node, every pod shares the same host. With several nodes, the scheduler places replicas on different nodes. You can then watch how a Deployment behaves when a node is drained or stopped. Each node costs memory, so keep the count small. One control plane and one or two workers is enough for most tests.
Defining nodes in kind
kind reads a configuration file. Each entry under nodes becomes one container. The file below also maps host port 8080 to NodePort 30080 on the control-plane node container.
kind: Cluster
apiVersion: kind.x-k8s.io/v1alpha4
nodes:
- role: control-plane
extraPortMappings:
- containerPort: 30080
hostPort: 8080
protocol: TCP
- role: workerPass the file when you create the cluster.
kind create cluster --name dev --config kind-config.yamlThe port mapping is attached to the control-plane container. Traffic sent to localhost:8080 reaches NodePort 30080 there. Because a NodePort listens on every node, the Service from the earlier chapter still answers even when its pods run on the worker.
Multiple nodes in minikube
minikube takes a node count as a flag instead of a file.
minikube start -p dev --nodes 2
kubectl get nodesThe first node is the control plane. The second is a worker.
Checking the result
kubectl get nodes
kubectl get pods -o wideThe NODE column of kubectl get pods -o wide shows where each pod landed. With two replicas of the web Deployment and a worker present, you may see the pods on different nodes. Placement is the scheduler's choice, so an even split is not guaranteed.
In practice, kind taints the control-plane node so ordinary pods do not run there. The diagram shows the Service reaching pods wherever they run. In a default kind cluster, the pods will usually sit on the worker.
Common errors
- Config file ignored. The file is only read at creation time. To change the node layout, delete the cluster and create it again.
- Port 8080 already in use. The
hostPortmust be free on your machine. Choose another value and recreate the cluster. - Pods stuck in Pending. The nodes may lack memory or CPU. Check
kubectl describe podfor scheduling events, then reduce replicas or raise the Docker or VM resource limit. - Loaded image missing on some nodes.
kind load docker-imagecopies to all nodes of the named cluster. Pass--name devso it targets the right one.
Exercise
You created a kind cluster with one control-plane and one worker, then decided you need a second worker. What do you do, and why?
Show answer
Edit the config file to add another - role: worker entry, delete the cluster with kind delete cluster --name dev, and create it again with --config. kind reads the configuration only at creation time, so an existing cluster cannot be changed this way.