Lesson 130 · Section 10: Cluster Installation & High Availability
Lesson 130: kubeadm init and join: build a cluster from prepared nodes
Create a cluster with kubeadm: what kubeadm init does phase by phase, the flags that matter, a CNI plugin so nodes become Ready, joining workers with a bootstrap token, printing a new join command, a config file, and kubeadm reset. · 22 min read · 3 min video
Official competencies this lesson covers
Narrated by the local narrator voice. Keys: Space plays and pauses, J and L step, C captions, F full screen.
Why it exists
With prepared machines (previous lesson), two kubeadm commands turn them into a cluster: kubeadm init on the
first control plane node and kubeadm join on every other node. Between the two sits one step kubeadm leaves to you:
installing a Pod network. This lesson builds a three-node cluster, controlplane (192.168.56.10), node01 and
node02, and explains what each command did, so that you can repair a half-built cluster as well as build a new
one.
Parts:
- kubeadm init (on controlplane)
- Control plane (NotReady at first)
- CNI plugin (kubectl apply)
- Nodes Ready (CoreDNS Running)
- kubeadm join (on each worker)
- node01, node02 (kubelet registered)
Connections:
- kubeadm init to Control plane: creates
- Control plane to CNI plugin: needs
- CNI plugin to Nodes Ready: makes
- kubeadm join to node01, node02: adds
- node01, node02 to Nodes Ready: becomes
How it works
What kubeadm init does
Parts:
- 1. preflight (checks the machine)
- 2. certs (/etc/kubernetes/pki)
- 3. kubeconfig (admin.conf and more)
- 4. static Pods (etcd + control plane)
- 5. kubelet-start (runs the manifests)
- 6. upload-config (kubeadm-config CM)
- 7. bootstrap-token (for kubeadm join)
- 8. addons (CoreDNS, kube-proxy)
Connections:
- 1. preflight to 2. certs: then
- 2. certs to 3. kubeconfig: then
- 3. kubeconfig to 4. static Pods: then
- 4. static Pods to 5. kubelet-start: then
- 5. kubelet-start to 6. upload-config: then
- 6. upload-config to 7. bootstrap-token: then
- 7. bootstrap-token to 8. addons: then
| Phase | What it creates | Where |
|---|---|---|
preflight | Nothing; checks CPU, memory, ports, swap, the runtime | |
certs | A cluster CA, an etcd CA, a front-proxy CA, and certificates for every component | /etc/kubernetes/pki/ |
kubeconfig | admin.conf, super-admin.conf, kubelet.conf, controller-manager.conf, scheduler.conf | /etc/kubernetes/ |
etcd, control-plane | Static Pod manifests for etcd, kube-apiserver, kube-controller-manager, kube-scheduler | /etc/kubernetes/manifests/ |
kubelet-start | The kubelet's configuration, then (re)starts the kubelet, which runs the static Pods | /var/lib/kubelet/config.yaml |
upload-config | The cluster configuration, so that join and upgrade can read it | ConfigMaps kubeadm-config, kubelet-config in kube-system |
mark-control-plane | The label node-role.kubernetes.io/control-plane and the NoSchedule taint | The Node object |
bootstrap-token | A token valid for 24 hours, and the RBAC rules that let it join nodes | Secret bootstrap-token-<id> |
addon | CoreDNS (Deployment) and kube-proxy (DaemonSet) | kube-system |
Every phase can be run alone with kubeadm init phase <name>, which is how you repair one piece, for example
regenerating a kubeconfig file, without rebuilding the cluster.
The flags that matter
| Flag | Meaning | Default |
|---|---|---|
--apiserver-advertise-address | The IP the API server announces and listens on | The address of the default route's interface |
--pod-network-cidr | The range Pods get IPs from; the CNI plugin must agree | None (some plugins need it) |
--service-cidr | The range Service ClusterIPs come from | 10.96.0.0/12 |
--control-plane-endpoint | A stable address for several control planes (next lesson) | The advertise address |
--kubernetes-version | Which control plane version to install | The newest patch of kubeadm's own minor version |
--cri-socket | Which runtime, if the machine has more than one | Auto-detected |
--node-name | The Node's name | The hostname |
Why the nodes are NotReady
The kubelet reports a node Ready only when the container runtime says its network is ready, and the runtime says
so only when it finds a CNI configuration in /etc/cni/net.d/. kubeadm installs no CNI plugin, so right after
init:
NAME STATUS ROLES AGE VERSION
controlplane NotReady control-plane 1m v1.37.0
and the CoreDNS Pods are Pending, because no node is ready to take them. The control plane static Pods run anyway:
they use the host's network, so they need no CNI. Applying a plugin's manifest (a DaemonSet that writes the CNI
config and binaries onto every node) fixes both.
| Plugin | Default Pod range | Install |
|---|---|---|
| Flannel | 10.244.0.0/16 | One manifest from its GitHub releases |
| Calico | 192.168.0.0/16 (configurable) | The Tigera operator, then a custom resource |
| Cilium | Its own IPAM, any range | The cilium CLI or Helm |
Use the range from the plugin's guide in --pod-network-cidr, or change the plugin's setting to match yours.
How kubeadm join works
Parts:
- node01 (kubeadm join)
- API server (192.168.56.10:6443)
- cluster-info (CA, signed by token)
- CA hash matches (sha256:...)
- Kubelet CSR (auto-approved)
- Node object (node01 registered)
Connections:
- node01 to API server: token
- API server to cluster-info: serves
- cluster-info to CA hash matches: verified
- CA hash matches to Kubelet CSR: then
- Kubelet CSR to Node object: certificate
kubeadm join 192.168.56.10:6443 --token 9vr73a.a8uxyaju799qwdjv \
--discovery-token-ca-cert-hash sha256:7c2e69131a36ae2a042a339b33381c6d0d43887e2de83720eff5359e26aec866
Each part has a job:
- The endpoint is where the API server is.
- The token (
<id>.<secret>) is a shared secret. The worker uses it to read thecluster-infoConfigMap inkube-public, which holds the cluster's CA and a signature made with the token, and later to authenticate as a member ofsystem:bootstrappers. - The CA certificate hash is the SHA-256 of the cluster CA's public key. The worker compares it with the CA it downloaded, so a fake API server cannot pose as the cluster. This is how trust goes both ways.
- With trust established, the kubelet sends a CertificateSigningRequest for its own client certificate. The
controller manager approves bootstrap CSRs automatically, the kubelet writes
/etc/kubernetes/kubelet.conf, and the Node object appears.
Tokens expire after 24 hours by default. The CA hash never changes for the life of the cluster.
Under the hood · Compute the CA hash yourself
If you have a token but not the hash, compute it on the control plane from the CA certificate:
openssl x509 -pubkey -in /etc/kubernetes/pki/ca.crt \
| openssl rsa -pubin -outform der 2>/dev/null \
| openssl dgst -sha256 -hex | sed 's/^.* //'
7c2e69131a36ae2a042a339b33381c6d0d43887e2de83720eff5359e26aec866
Prefix it with sha256: in the join command. In practice kubeadm token create --print-join-command does all of
this for you.
Using it
Example · 1. Initialise the control plane
On controlplane, with the node prepared as in the previous lesson:
sudo kubeadm init \
--apiserver-advertise-address=192.168.56.10 \
--pod-network-cidr=10.244.0.0/16
[init] Using Kubernetes version: v1.37.0
[preflight] Running pre-flight checks
[certs] Generating "ca" certificate and key
...
[control-plane] Creating static Pod manifest for "kube-apiserver"
...
[addons] Applied essential addon: CoreDNS
[addons] Applied essential addon: kube-proxy
Your Kubernetes control-plane has initialized successfully!
To start using your cluster, you need to run the following as a regular user:
mkdir -p $HOME/.kube
sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config
sudo chown $(id -u):$(id -g) $HOME/.kube/config
You should now deploy a pod network to the cluster.
...
Then you can join any number of worker nodes by running the following on each as root:
kubeadm join 192.168.56.10:6443 --token 9vr73a.a8uxyaju799qwdjv \
--discovery-token-ca-cert-hash sha256:7c2e69131a36ae2a042a339b33381c6d0d43887e2de83720eff5359e26aec866
Run the three kubeconfig lines it printed, then check:
kubectl get nodes
kubectl -n kube-system get pods
NAME STATUS ROLES AGE VERSION
controlplane NotReady control-plane 1m v1.37.0
NAME READY STATUS RESTARTS AGE
coredns-6f6b679f8f-7xk2p 0/1 Pending 0 1m
coredns-6f6b679f8f-qq8tn 0/1 Pending 0 1m
etcd-controlplane 1/1 Running 0 1m
kube-apiserver-controlplane 1/1 Running 0 1m
kube-controller-manager-controlplane 1/1 Running 0 1m
kube-proxy-5hx2m 1/1 Running 0 1m
kube-scheduler-controlplane 1/1 Running 0 1m
Exactly what you expect before a CNI plugin.
Example · 2. Install the CNI plugin
Flannel's default range is the one we passed to init:
kubectl apply -f https://github.com/flannel-io/flannel/releases/latest/download/kube-flannel.yml
kubectl -n kube-flannel get pods
kubectl get nodes
NAME READY STATUS RESTARTS AGE
kube-flannel-ds-4dq8w 1/1 Running 0 40s
NAME STATUS ROLES AGE VERSION
controlplane Ready control-plane 3m v1.37.0
CoreDNS turns Running at the same moment. For Calico or Cilium, follow the plugin's own quick start; the idea is
the same, one apply from the control plane, and a DaemonSet does the rest on every node.
Example · 3. Join the workers
If the join line from init is lost or older than 24 hours, print a new one on controlplane:
kubeadm token create --print-join-command
Then on node01 (prepared the same way), run it with sudo:
sudo kubeadm join 192.168.56.10:6443 --token 9vr73a.a8uxyaju799qwdjv \
--discovery-token-ca-cert-hash sha256:7c2e69131a36ae2a042a339b33381c6d0d43887e2de83720eff5359e26aec866
[preflight] Running pre-flight checks
[preflight] Reading configuration from the "kubeadm-config" ConfigMap in namespace "kube-system"...
[kubelet-start] Starting the kubelet
[kubelet-start] Waiting for the kubelet to perform the TLS Bootstrap
This node has joined the cluster:
* Certificate signing request was sent to apiserver and a response was received.
* The Kubelet was informed of the new secure connection details.
Run 'kubectl get nodes' on the control-plane to see this node join the cluster.
Repeat on node02, then back on controlplane:
kubectl get nodes -o wide
NAME STATUS ROLES AGE VERSION INTERNAL-IP
controlplane Ready control-plane 9m v1.37.0 192.168.56.10
node01 Ready <none> 2m v1.37.0 192.168.56.11
node02 Ready <none> 1m v1.37.0 192.168.56.12
ROLES shows <none> for workers; that is only a label. Add one if you like:
kubectl label node node01 node-role.kubernetes.io/worker=.
Example · 4. The same init from a config file
Flags are fine for one-off installs; a config file documents the cluster and is needed for options without flags. Generate the defaults and edit them:
kubeadm config print init-defaults > kubeadm.yaml
apiVersion: kubeadm.k8s.io/v1beta4
kind: InitConfiguration
localAPIEndpoint:
advertiseAddress: 192.168.56.10
bindPort: 6443
nodeRegistration:
criSocket: unix:///var/run/containerd/containerd.sock
name: controlplane
---
apiVersion: kubeadm.k8s.io/v1beta4
kind: ClusterConfiguration
kubernetesVersion: v1.37.0
networking:
podSubnet: 10.244.0.0/16
serviceSubnet: 10.96.0.0/12
dnsDomain: cluster.local
---
apiVersion: kubelet.config.k8s.io/v1beta1
kind: KubeletConfiguration
cgroupDriver: systemd
sudo kubeadm init --config kubeadm.yaml
The cluster keeps the ClusterConfiguration in the kubeadm-config ConfigMap, so you can always read back how it
was built: kubectl -n kube-system get cm kubeadm-config -o yaml.
Example · 5. Start over with kubeadm reset
A failed init leaves certificates, manifests and a running kubelet behind, and the next init stops in preflight.
Clean up on that node:
sudo kubeadm reset -f
sudo rm -rf /etc/cni/net.d $HOME/.kube/config
kubeadm reset removes what kubeadm created (manifests, certificates, the local etcd data) and stops the kubelet's
Pods. It does not remove the CNI configuration, iptables rules or your kubeconfig, which is why the second line
exists. To remove a worker from a running cluster, drain and delete it first, then reset it:
kubectl drain node02 --ignore-daemonsets --delete-emptydir-data # on controlplane
kubectl delete node node02 # on controlplane
sudo kubeadm reset -f # on node02
When a step fails
| What you see | Cause | Fix |
|---|---|---|
Nodes NotReady, CoreDNS Pending | No CNI plugin | Apply one |
| CNI Pods crash, logs mention the Pod CIDR | --pod-network-cidr and the plugin's range differ | Change the plugin's config, or reset and init with its range |
join hangs at "Waiting for the kubelet to perform the TLS Bootstrap" | The worker cannot reach port 6443, or the advertise address is wrong | nc -zv 192.168.56.10 6443 from the worker; check --apiserver-advertise-address |
join fails with token id ... is invalid or could not find a JWS signature | The token expired (24 h) | kubeadm token create --print-join-command |
join fails with a CA hash mismatch | Hash copied wrongly, or from another cluster | Print a fresh join command |
kubectl says connection to the server localhost:8080 was refused | No kubeconfig | Copy /etc/kubernetes/admin.conf to ~/.kube/config |
| Two workers show as one node | Cloned VMs with the same hostname | hostnamectl set-hostname, reset, join again |
Tricks
Common mistakes
- Forgetting the CNI plugin and then troubleshooting the
NotReadynodes for ten minutes. - A Pod range that does not match the plugin's. Flannel's default is
10.244.0.0/16, Calico's192.168.0.0/16. - Running
kubeadm joinwithoutsudo. It needs root to write/etc/kubernetesand start the kubelet. - Running
kubeadm initon a worker instead ofjoin. That node now has its own one-node cluster; reset it. - Re-running
initafter a failure withoutkubeadm reset. Preflight stops on the leftovers. - Leaving
--apiserver-advertise-addressto chance on multi-NIC VMs. Workers end up trying a NAT address.
Recap
kubeadm initcreates certificates, kubeconfigs, static Pods, a bootstrap token, CoreDNS and kube-proxy.- Copy
/etc/kubernetes/admin.confto~/.kube/configto usekubectl. - Without a CNI plugin, nodes are
NotReadyand CoreDNS isPending; match--pod-network-cidrto the plugin. kubeadm join <endpoint> --token ... --discovery-token-ca-cert-hash sha256:...; tokens last 24 hours, so print a new line withkubeadm token create --print-join-command.kubeadm resetundoesinitorjoinon one node; clean/etc/cni/net.dyourself.
Official docs
Quiz: check what you learned
5 questions on this lesson · about 3 min · instant feedback. Missed questions come back in your review queue.
Sign in to take the quiz and keep your score.
Practise: try it on a real cluster
2 hands-on labs for this lesson. You get goals, not steps: any solution that reaches them passes.
Two new machines have containerd, kubelet and kubeadm and nothing else. Build a cluster on them with kubeadm init and join, give it a pod network, and set up kubectl for your own user.
Build · Level 2 · standard · target 25 min
Larkspur's cluster has one control plane node and a load balancer already in front of it. Join two prepared machines as control plane nodes, so that the cluster and its etcd keep working when one of them is down.
Build · Level 3 · challenge · target 25 min
Discussion
Learners ask and answer questions here. Sign in to read and join the discussion.