# Building a kubeadm Cluster (Part 2): Initializing the Cluster and Its Components

> Use kubeadm on the prepared VMs to build the cluster used in later practice, while getting to know the Control Plane and Worker Node components and the roles CRI and CNI play during installation

- URL: https://lcxlab.com/en/post/cka-kubeadm-cluster
- Author: Miles Hsu
- Published: 2026-10-23
- Updated: 2026-10-30
- Category: DevOps
- Series: Certified Kubernetes Administrator (CKA) #4
- Tags: kubeadm, CKA, Kubernetes, ubuntu
- License: CC BY 4.0 (https://creativecommons.org/licenses/by/4.0/deed.en)

---

## Building a Cluster with kubeadm

In the previous post I installed three Ubuntu VMs. Now I will follow the steps on [Kubernetes.io](https://kubernetes.io/docs/setup/production-environment/tools/kubeadm/create-cluster-kubeadm/) to build a three-node Kubernetes cluster.

[Building a kubeadm Cluster (Part 1)](https://lcxlab.com/en/post/cka-kubeadm-lab-setup)

From the very top of the documentation:

>The `kubeadm` tool is good if you need:
>
>- A simple way for you to try out Kubernetes, possibly for the first time.
>- A way for existing users to automate setting up a cluster and test their application.
>- A building block in other ecosystem and/or installer tools with a larger scope.
>

![kubeadm-stacked-color](https://lcxlab.com/images/posts/cka-kubeadm-cluster/kubeadm-stacked-color.webp)

`kubeadm` can build a cluster on all kinds of hardware, whether it is a laptop, a server in the cloud, or a board like the Raspberry Pi. It works both in the cloud and on-premises, and it can be integrated into automation tools such as Ansible and Terraform.

`kubeadm` only handles the minimum steps needed to stand a cluster up. Networking (CNI), storage, monitoring and other components are building blocks you pick and assemble yourself. Because it is not tied to any particular platform, it runs on very different hardware. This do-it-yourself feeling reminds me a bit of Gentoo[^Gentoo].

---

### Before You Begin

The officially recommended requirements are:

- One or more machines running a deb/rpm-compatible Linux OS, such as Ubuntu or CentOS.
- At least 2 GiB of RAM per machine.
- At least 2 CPUs on the control-plane node.
- Full network connectivity between all machines in the cluster (public or private network is fine).

The documentation currently targets Kubernetes v1.37, which is the version the CKA exam uses, so from here on it is mostly a matter of following the docs.

![111952](https://lcxlab.com/images/posts/cka-kubeadm-cluster/111952.webp)

>[!NOTE] The docs are split across pages
>[Creating a cluster with kubeadm](https://kubernetes.io/docs/setup/production-environment/tools/kubeadm/create-cluster-kubeadm/) assumes kubeadm is already installed, so you will not find the installation steps there. Installation lives on a separate page, [Installing kubeadm](https://kubernetes.io/docs/setup/production-environment/tools/kubeadm/install-kubeadm/), and the container runtime prerequisites are on [Container Runtimes](https://kubernetes.io/docs/setup/production-environment/container-runtimes/). Read them in this order: Installing kubeadm → Container Runtimes → back to Creating a cluster with kubeadm.

---

## Creating the Cluster

I do not want to go into too much detail here, since the docs already cover everything. This section walks through each step and the problems you may run into. The steps are grouped by which node runs them:

| Steps | Run on |
|--|--|
| 1–5: disable swap, kernel parameters, containerd, kubeadm/kubelet/kubectl | All three nodes |
| 6–7: `kubeadm init`, install a CNI | Control plane only (k8s-cp1) |
| 8: `kubeadm join` | Workers only |

Steps 3 and 5 each have two installation methods: apt packages, or downloading the binaries directly from GitHub / `dl.k8s.io`. Pick one per machine and do not mix them.

### 1. Disable swap

By default kubelet refuses to start when it sees swap (`failSwapOn: true`). Kubernetes scheduling relies on each Pod's memory requests and limits; with swap, memory usage is no longer accurate and OOM behavior becomes hard to predict. Newer versions can be configured to let kubelet tolerate swap, but in a practice environment it is simplest to turn it off, and kubeadm's preflight checks will not complain.

```bash
sudo swapoff -a                                          # turn it off now
sudo sed -i -E '/^[^#].*\sswap\s/ s/^/#/' /etc/fstab     # comment out swap in fstab so it stays off after a reboot
swapon --show                                            # no output means swap is off
free -h                                                  # the Swap row should be 0B
```

![231007](https://lcxlab.com/images/posts/cka-kubeadm-cluster/231007.webp)
>My three Ubuntu VMs never had swap configured, so I could skip this step

### 2. Load kernel modules and enable IP forwarding

Pod traffic has to be forwarded by the node to other nodes or Services, so Linux must allow IPv4 forwarding. `br_netfilter` makes traffic that crosses a bridge go through iptables as well, which kube-proxy and most CNIs depend on. `overlay` is needed by containerd's overlayfs snapshotter.

```bash
cat <<EOF | sudo tee /etc/modules-load.d/k8s.conf
overlay
br_netfilter
EOF
sudo modprobe overlay
sudo modprobe br_netfilter

cat <<EOF | sudo tee /etc/sysctl.d/k8s.conf
net.ipv4.ip_forward                 = 1
net.bridge.bridge-nf-call-iptables  = 1
net.bridge.bridge-nf-call-ip6tables = 1
EOF
sudo sysctl --system

sysctl net.ipv4.ip_forward    # should be 1
```
>The official Container Runtimes page currently lists only `ip_forward` as required; the other two depend on the CNI. Almost every tutorial sets all three anyway, and setting them has no side effects.

### 3. Install containerd (CRI)

kubelet does not run containers itself. It uses the CRI (Container Runtime Interface) to ask containerd to pull images and create containers. Kubernetes removed dockershim in 1.24, so these days you install containerd directly.

#### Method 1: apt

The containerd package in the Ubuntu repositories installs runc along with it:

```bash
sudo apt-get update
sudo apt-get install -y containerd
```

#### Method 2: Download from GitHub

When downloading yourself, you install three components separately:

| Component | Role |
|--|--|
| containerd | The CRI implementation; kubelet manages containers through it |
| runc | The low-level runtime that actually calls Linux namespaces/cgroups to run the container |
| CNI plugins | Basic network plugins such as `bridge`, `host-local` and `loopback`, used by CNIs like Flannel |

First set up a few variables. `latest` uses the GitHub API to fetch the tag of a repo's latest release:

```bash
ARCH="amd64"
latest() { curl -fsSL "https://api.github.com/repos/$1/releases/latest" | grep -oP '"tag_name":\s*"\K[^"]+'; }
```

```bash
# containerd: extract into /usr/local/bin
CONTAINERD_VERSION=$(latest containerd/containerd)
V=${CONTAINERD_VERSION#v}
curl -LO "https://github.com/containerd/containerd/releases/download/${CONTAINERD_VERSION}/containerd-${V}-linux-${ARCH}.tar.gz"
curl -LO "https://github.com/containerd/containerd/releases/download/${CONTAINERD_VERSION}/containerd-${V}-linux-${ARCH}.tar.gz.sha256sum"
sha256sum -c containerd-${V}-linux-${ARCH}.tar.gz.sha256sum   # verify the file was not tampered with
sudo tar Cxzvf /usr/local containerd-${V}-linux-${ARCH}.tar.gz

# containerd's systemd unit (not included in the tarball, download it separately)
sudo mkdir -p /usr/local/lib/systemd/system
sudo curl -L -o /usr/local/lib/systemd/system/containerd.service \
  https://raw.githubusercontent.com/containerd/containerd/main/containerd.service

# runc: a single statically compiled binary
RUNC_VERSION=$(latest opencontainers/runc)
curl -LO "https://github.com/opencontainers/runc/releases/download/${RUNC_VERSION}/runc.${ARCH}"
sudo install -m 755 runc.${ARCH} /usr/local/sbin/runc

# CNI plugins
CNI_VERSION=$(latest containernetworking/plugins)
sudo mkdir -p /opt/cni/bin
curl -L "https://github.com/containernetworking/plugins/releases/download/${CNI_VERSION}/cni-plugins-linux-${ARCH}-${CNI_VERSION}.tgz" \
  | sudo tar -C /opt/cni/bin -xz
```

>This section is based on containerd's official [Getting started](https://github.com/containerd/containerd/blob/main/docs/getting-started.md) guide (Option 1: From the official binaries).

### 4. Switch containerd's cgroup driver to systemd

kubelet and the container runtime must use the same cgroup driver. Ubuntu manages cgroups with systemd, and since v1.22 kubeadm also makes kubelet use systemd by default, but containerd defaults to cgroupfs.

>[!WARNING] ❗Watch out
>If the two do not match, the control plane Pods keep restarting. This is one of the most common pitfalls.

```bash
sudo mkdir -p /etc/containerd
containerd config default | sudo tee /etc/containerd/config.toml > /dev/null
sudo sed -i 's/SystemdCgroup = false/SystemdCgroup = true/' /etc/containerd/config.toml
grep -n SystemdCgroup /etc/containerd/config.toml   # confirm it is now true
sudo systemctl daemon-reload                         # method 2 added a unit file, so reload first
sudo systemctl enable containerd
sudo systemctl restart containerd
```

>[!WARNING] containerd 2.x uses a different config format
>containerd installed with apt on Ubuntu 24.04 is 1.7, while the latest release from GitHub is 2.x. Its config file uses `version = 3` and the section names are different. If the `grep` above finds nothing, open `config.toml` and add `SystemdCgroup = true` under `[plugins.'io.containerd.cri.v1.runtime'.containerd.runtimes.runc.options]` by hand.

### 5. Install kubeadm, kubelet and kubectl

These three are:
- `kubeadm`: the tool that builds the cluster
- `kubelet`: the agent on every node that actually runs the Pods
- `kubectl`: the CLI for working with the cluster

#### Method 1: apt

```bash
sudo apt-get install -y apt-transport-https ca-certificates curl gpg
sudo mkdir -p -m 755 /etc/apt/keyrings
curl -fsSL https://pkgs.k8s.io/core:/stable:/v1.37/deb/Release.key \
  | sudo gpg --dearmor -o /etc/apt/keyrings/kubernetes-apt-keyring.gpg
echo 'deb [signed-by=/etc/apt/keyrings/kubernetes-apt-keyring.gpg] https://pkgs.k8s.io/core:/stable:/v1.37/deb/ /' \
  | sudo tee /etc/apt/sources.list.d/kubernetes.list

sudo apt-get update
sudo apt-get install -y kubelet kubeadm kubectl
sudo apt-mark hold kubelet kubeadm kubectl   # pin the versions so apt upgrade does not quietly upgrade them
sudo systemctl enable --now kubelet
```

- There is one repo per minor version, and the `v1.37` in the URL selects the version. The CKA also tests cluster upgrades, and that is exactly the line you change then.

#### Method 2: Download from dl.k8s.io

The Kubernetes binaries are not published on GitHub Releases (the kubernetes/kubernetes Releases page only has release notes). They are hosted on the official `dl.k8s.io`. The "Without a package manager" section of the Installing kubeadm page does it this way, but the versions hard-coded in the docs are older, so here they are fetched automatically.

The apt kubelet package pulls in `conntrack` and `socat` as dependencies. With the binaries you have to install them yourself. Without `conntrack`, kubeadm's preflight check fails right away:

```bash
sudo apt-get install -y conntrack socat
```

```bash
ARCH="amd64"
K8S_MINOR="1.37"
# stable-1.37.txt pins the latest 1.37 patch release
# the official example uses stable.txt, which gets the overall latest release, not necessarily 1.37
RELEASE=$(curl -sSL https://dl.k8s.io/release/stable-${K8S_MINOR}.txt)
DOWNLOAD_DIR=/usr/local/bin

cd /tmp
curl -L --remote-name-all https://dl.k8s.io/release/${RELEASE}/bin/linux/${ARCH}/{kubeadm,kubelet,kubectl}
sudo install -m 755 kubeadm kubelet kubectl ${DOWNLOAD_DIR}/

# crictl: kubeadm uses it to check the CRI; its version follows the Kubernetes minor
CRICTL_VERSION="v${K8S_MINOR}.0"
curl -L "https://github.com/kubernetes-sigs/cri-tools/releases/download/${CRICTL_VERSION}/crictl-${CRICTL_VERSION}-linux-${ARCH}.tar.gz" \
  | sudo tar -C ${DOWNLOAD_DIR} -xz
```

kubelet needs a systemd unit to be managed. The apt package ships these two files; when installing yourself, download them from the kubernetes/release repo and change the path from `/usr/bin` to `/usr/local/bin`:

```bash
RELEASE_VERSION="v0.16.2"   # version of the kubernetes/release repo, as in the official docs
curl -sSL "https://raw.githubusercontent.com/kubernetes/release/${RELEASE_VERSION}/cmd/krel/templates/latest/kubelet/kubelet.service" \
  | sed "s:/usr/bin:${DOWNLOAD_DIR}:g" | sudo tee /usr/lib/systemd/system/kubelet.service
sudo mkdir -p /usr/lib/systemd/system/kubelet.service.d
curl -sSL "https://raw.githubusercontent.com/kubernetes/release/${RELEASE_VERSION}/cmd/krel/templates/latest/kubeadm/10-kubeadm.conf" \
  | sed "s:/usr/bin:${DOWNLOAD_DIR}:g" | sudo tee /usr/lib/systemd/system/kubelet.service.d/10-kubeadm.conf

sudo systemctl daemon-reload
sudo systemctl enable --now kubelet
```

`10-kubeadm.conf` tells kubelet to read `/var/lib/kubelet/config.yaml` and `/etc/kubernetes/kubelet.conf`. Those two files are only created by `kubeadm init` or `kubeadm join`.

Check the versions:

```bash
kubeadm version -o short
kubelet --version
kubectl version --client
sudo crictl --runtime-endpoint unix:///run/containerd/containerd.sock version
```

![175648](https://lcxlab.com/images/posts/cka-kubeadm-cluster/175648.webp)

The first line of the crictl output is `WARN[0000] Config "/etc/crictl.yaml" does not exist, trying next: "/usr/local/bin/crictl.yaml"`, and you can ignore it. crictl looks for `/etc/crictl.yaml` and then a `crictl.yaml` next to the binary, and carries on with defaults if neither exists. Since `--runtime-endpoint` already points at containerd, it is connected, as `RuntimeName: containerd` below shows.

`crictl ps` and `crictl logs` come up a lot when debugging later, and passing the endpoint every time is tedious, so write a config file on all three nodes:

```bash
cat <<EOF | sudo tee /etc/crictl.yaml
runtime-endpoint: unix:///run/containerd/containerd.sock
image-endpoint: unix:///run/containerd/containerd.sock
timeout: 10
EOF

sudo crictl version   # no --runtime-endpoint needed, and no WARN
```

#### Comparing the two methods

| | apt (pkgs.k8s.io) | Direct download (GitHub / dl.k8s.io) |
|--|--|--|
| Dependencies | Handled automatically | Install conntrack and socat yourself |
| systemd units | Included in the package | Download them yourself |
| Upgrades | Change the repo version, `apt-mark unhold`, then upgrade | Download again and replace the binaries |
| Strengths | Simple, and matches the CKA exam environment | Distribution-independent, and you see exactly where each component lives |

>[!TIP] 💡CKA exam tip
>The CKA upgrade tasks are done with apt, so for exam prep stick mainly to method 1. Method 2 is better for understanding what each component does.

>Whichever method you use, `systemctl status kubelet` will now show kubelet restarting every few seconds. That is expected: it has no config yet and is waiting for `kubeadm init` or `kubeadm join`.

### 6. Initialize the control plane (k8s-cp1 only)

```bash
sudo kubeadm init \
  --apiserver-advertise-address=<cp1 IP> \
  --pod-network-cidr=10.244.0.0/16
```

![180720](https://lcxlab.com/images/posts/cka-kubeadm-cluster/180720.webp)

- `--pod-network-cidr`: the range Pod IPs come from. It must not overlap with the network the VMs are on.

>[!WARNING] ❗Watch out
> In my case the VMs are on libvirt's `192.168.122.0/24`, and Calico's default Pod range `192.168.0.0/16` contains it. So I use `10.244.0.0/16` here, which is safe whichever CNI you pick.

- `--apiserver-advertise-address`: the IP the API server listens on. You can leave it out if the VM has only one network interface.

What init actually does:
1. Preflight checks (swap, ports, CRI and so on)
2. Generates the certificates under `/etc/kubernetes/pki`
3. Generates kubeconfig files
4. Writes etcd, kube-apiserver, kube-controller-manager and kube-scheduler as static Pods (in `/etc/kubernetes/manifests/`, started directly by kubelet)
5. Installs CoreDNS and kube-proxy

When it finishes, set up kubectl as the output tells you:

```bash
mkdir -p $HOME/.kube
sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config
sudo chown $(id -u):$(id -g) $HOME/.kube/config
```

![181540](https://lcxlab.com/images/posts/cka-kubeadm-cluster/181540.webp)

Remember to copy the `kubeadm join ...` line at the end of the output; you will need it in step 8.

### 7. Install a CNI (k8s-cp1 only)

If you run `kubectl get nodes` now, cp1 shows `NotReady` and CoreDNS is stuck in `Pending`. kubeadm does not install Pod networking for you; this is the "pick your own building blocks" part mentioned earlier.

What a CNI actually does, and how Pods talk across Nodes, is covered in a separate post:

[Kubernetes Networking: How Do Pods Communicate?](https://lcxlab.com/en/post/cni-plugins-for-kubernetes)

I chose Calico here because it supports NetworkPolicy, which the CKA tests. Flannel does not support it, yet applying a NetworkPolicy does not fail either; the policy just sits there and has no effect. If you get it wrong while practicing you cannot tell, so you have no way to check your answers.

#### Calico (recommended)

Calico is now installed with the tigera-operator: install the operator first, then use an `Installation` resource to tell it how to set up networking.

```bash
CALICO_VERSION=v3.33.0
BASE=https://raw.githubusercontent.com/projectcalico/calico/${CALICO_VERSION}/manifests

# CRDs and operator. The files are large, so use create; apply exceeds the annotation size limit
kubectl create -f ${BASE}/v3_projectcalico_org.yaml    # use this one for Kubernetes 1.36 and later
kubectl create -f ${BASE}/tigera-operator.yaml

# The default Pod range is 192.168.0.0/16; change it to the 10.244.0.0/16 used in kubeadm init
curl -sSLO ${BASE}/custom-resources.yaml
sed -i 's#cidr: 192.168.0.0/16#cidr: 10.244.0.0/16#' custom-resources.yaml
grep cidr custom-resources.yaml    # confirm the change
kubectl create -f custom-resources.yaml

kubectl get pods -n calico-system -w    # wait for calico-node and the other components to be Running
kubectl get tigerastatus                # it is installed only when every component shows AVAILABLE True
```

>[!WARNING] ❗Watch out
>You must change the `cidr` in `custom-resources.yaml`. Otherwise Calico hands out Pod IPs from `192.168.0.0/16`, which overlaps with the VMs' `192.168.122.0/24`, and traffic between Pods or from Pods to nodes takes the wrong route. Older tutorials say to change `CALICO_IPV4POOL_CIDR`; that setting belongs to the old `calico.yaml` manifest install. With the operator, this is the place to change it.

Calico's Pods run in the `calico-system` namespace, not `kube-system`. When workers join later, the operator automatically runs a `calico-node` on each new node.

>[!WARNING] ❗Watch out: the host must not rewrite the source IP of VM-to-VM traffic
>Check this on the **physical host** (the machine running libvirt), not inside the VMs.
>
>With Calico's default `vxlanMode: CrossSubnet`, traffic is only encapsulated across subnets; within the same subnet, nodes exchange routes over BGP (TCP 179). BIRD only accepts connections from known node IPs. If the host masquerades VM-to-VM packets as `192.168.122.1`, BIRD rejects them as an unknown peer. `calico-node` then stays at `0/1` until the startup probe restarts it, and new Pods get stuck in `Pending`.
>
>The problem appears when both of these are **true at the same time**:
>
>1. The host has `br_netfilter` loaded and `net.bridge.bridge-nf-call-iptables = 1`. This is common if the host has ever run Docker, k3s or kind. Bridged traffic on `virbr0` then also goes through the host's iptables/nft rules.
>2. The firewalld `libvirt` zone has masquerade enabled. Zone masquerade does not exclude the local subnet, so VM-to-VM traffic is rewritten too. libvirt's own NAT rules already exclude the local subnet and do not need this.
>
>```bash
># On the libvirt host: if both are true, you need to fix it
>sysctl net.bridge.bridge-nf-call-iptables        # 1 means bridged traffic goes through iptables
>firewall-cmd --zone=libvirt --query-masquerade   # yes means the zone masquerades
>```
>
>The recommended fix is to remove masquerade from the libvirt zone. You do not have to touch `br_netfilter`, and Docker on the host is unaffected:
>
>```bash
>sudo firewall-cmd --zone=libvirt --remove-masquerade
>
># Inside a VM, check that it can still reach the internet
>ping -c 3 8.8.8.8
>sudo apt update
>
># If it works, make it permanent
>sudo firewall-cmd --permanent --zone=libvirt --remove-masquerade
>```
>
>If the host does not use firewalld, or the VMs lose internet access after removing masquerade (add it back with `--add-masquerade`), turn off bridge netfilter on the host instead:
>
>```bash
>sudo sysctl -w net.bridge.bridge-nf-call-iptables=0 \
>  net.bridge.bridge-nf-call-ip6tables=0 \
>  net.bridge.bridge-nf-call-arptables=0
>```
>
>This has two drawbacks: Docker's filtering between containers on the same bridge (such as `--icc=false`) stops working, and dockerd may set it back to `1` when it starts, bringing the problem back.
>
>Do not confuse this with step 2: `br_netfilter` and `bridge-nf-call-iptables = 1` **inside the VMs** are required by Kubernetes and must stay. This section is about the settings **on the host**.

#### Flannel (alternative)

If you just want the cluster running and do not plan to practice NetworkPolicy, Flannel installs in one line. Its default range happens to be `10.244.0.0/16`, so nothing needs changing:

```bash
kubectl apply -f https://github.com/flannel-io/flannel/releases/latest/download/kube-flannel.yml
kubectl get pods -n kube-flannel -w    # wait for kube-flannel-ds to be Running
```

Pick either Calico or Flannel. Do not install both.

#### Calico vs. Flannel

| | Calico | Flannel |
|--|--|--|
| NetworkPolicy | Supported | Not supported (apply does not fail, but nothing is enforced) |
| Installation | Operator + CRDs, three steps, `cidr` must be changed | One manifest, one line |
| Default Pod range | `192.168.0.0/16` (must be changed in this setup) | `10.244.0.0/16` (no change needed) |
| Packet forwarding | VXLAN by default (encapsulated only across subnets); also BGP direct routing or eBPF | VXLAN overlay |
| Resource usage | More components (operator, calico-node, typha, apiserver and so on) | One DaemonSet Pod per node, very light |
| Best for | CKA prep and environments that need NetworkPolicy | Practice environments that only need Pod networking to work |

### 8. Join the workers (k8s-w1, k8s-w2)

Run the `kubeadm join ...` command from step 6 on w1 and w2 to add both nodes to the cluster.

```bash
sudo kubeadm join <cp1 IP>:6443 --token <token> \
  --discovery-token-ca-cert-hash sha256:<hash>
```

If the token has expired (it is valid for 24 hours) or you did not copy it, generate a new one on cp1:

```bash
kubeadm token create --print-join-command
```

Finally, verify on cp1:

```bash
kubectl get nodes -o wide   # all three are Ready
```

![184120](https://lcxlab.com/images/posts/cka-kubeadm-cluster/184120.webp)

A node being `Ready` only means the CNI config is in place; it does not prove Calico is healthy. BGP sessions only start once the workers have joined, so check Calico again now:

```bash
kubectl get pods -n calico-system -l k8s-app=calico-node   # every node should be 1/1 Running
kubectl get tigerastatus                                    # calico should be AVAILABLE=True

# BGP must be established with the other two nodes; a three-node cluster should show = 2
kubectl logs -n calico-system -l k8s-app=calico-node -c calico-node --tail=5 | grep "BGP peering"
```

Then run a few Pods to confirm cross-node Pod networking works:

```bash
kubectl create deployment nginx --image=nginx:1.29 --replicas=3
kubectl get po -l app=nginx -o wide    # all Running, spread across w1 and w2

# Connect to each nginx Pod IP from another Pod; every line should print Welcome to nginx!
for ip in $(kubectl get po -l app=nginx -o jsonpath='{.items[*].status.podIP}'); do
  kubectl run tmp --rm -i --image=busybox:1.37 --restart=Never -- wget -qO- -T 3 $ip | grep -o "Welcome to nginx!" || echo "FAIL $ip"
done

kubectl delete deployment nginx    # clean up when done
```

If `calico-node` stays at `0/1` and RESTARTS keeps going up, check the logs first:

```bash
kubectl logs -n calico-system -l k8s-app=calico-node -c calico-node --tail=20
```

If you see `BGP not established` together with `Unexpected connect from unknown address 192.168.122.1`, it is the host masquerade problem described above. After fixing the host, delete `calico-node` so it gets recreated:

```bash
kubectl delete pod -n calico-system -l k8s-app=calico-node
```

> [!TIP] 📌 Other notes
> The CKA exam environment usually has the `k` alias for `kubectl` already set up, so you can run commands like `k get nodes` directly.
> If your own Linux environment does not have it yet, add it for the shell you use.
> 
> **Bash (exam environment)**
> ```bash
> echo "alias k='kubectl'" >> ~/.bashrc
> source ~/.bashrc
> ```
> 
> **Zsh**
> ```bash
> echo "alias k='kubectl'" >> ~/.zshrc
> source ~/.zshrc
> ```
> 
> **Fish**
> ```fish
> alias k kubectl
> funcsave k
> ```
> 
> After that, you can use k instead of kubectl, for example:
> ```bash
> k get nodes
> k get pods -A
> k describe node k8s-cp1
> ```
>
> **One more exam detail:** the CKA terminal usually has kubectl completion set up too, but it is still worth getting comfortable with k, kubectl and Tab completion rather than relying too much on the alias.

---

## Common Problems

| Problem | Cause |
|--|--|
| Preflight reports a swap error | Step 1 was skipped, or fstab was not changed and swap came back after a reboot |
| Preflight reports `conntrack not found` | conntrack was not installed when using method 2 |
| Control plane Pods keep CrashLooping | containerd was not changed to `SystemdCgroup = true` |
| Nodes stay `NotReady` | No CNI installed yet |
| Pods cannot reach each other | The Pod range overlaps with the VM network (192.168.122.0/24) |
| `calico-node` stays `0/1`, new Pods stuck in `Pending`, logs show `Unexpected connect from unknown address 192.168.122.1` | The libvirt host's `br_netfilter` plus masquerade in the firewalld `libvirt` zone rewrite the source of VM-to-VM BGP traffic to `192.168.122.1`; see the warning in step 7 |
| Join fails or nodes break after a reboot | The VMs get their IPs over DHCP and the IPs changed; give the three VMs fixed IPs in libvirt |

---

That takes us from zero to a Kubernetes cluster built with `kubeadm`. It is still very basic: a single control plane, no high availability, and no storage, Ingress or monitoring yet. But having gone through it once, you at least know where each of these pieces lives:

- **containerd** is the container runtime kubelet calls through the CRI, and its cgroup driver must be systemd, the same as kubelet
- **kubeadm init** generates the certificates and kubeconfig files and writes the control plane components as static Pods under `/etc/kubernetes/manifests/`
- **The CNI** is yours to install, and nodes stay `NotReady` until it is; Calico was chosen so NetworkPolicy can be practiced later
- **kubeadm join** lets workers join the cluster with a token and the CA hash

Every cluster in the CKA exam is built with kubeadm, so where static Pods live, where the certificates are and how kubelet loads its config all come up again in the upgrade and troubleshooting tasks.

>[!TIP] 💡 Take a snapshot first
>Once the cluster is built and all three nodes are `Ready`, take a snapshot of each VM. Practicing upgrades, etcd restores and troubleshooting will inevitably break the cluster at some point, and with snapshots you can go straight back to a clean state instead of reinstalling from scratch:
>
>```bash
>for vm in k8s-cp1 k8s-w1 k8s-w2; do sudo virsh snapshot-create-as "$vm" cluster-ready; done
>sudo virsh snapshot-list k8s-cp1    # confirm the snapshot exists
>```
>
>To restore, revert all three together so etcd's data stays consistent with the workers:
>
>```bash
>for vm in k8s-cp1 k8s-w1 k8s-w2; do sudo virsh snapshot-revert "$vm" cluster-ready; done
>```
>
>A snapshot taken while the VM is running includes its memory, so after reverting the VM is running again exactly as it was, but its clock is also back at the moment the snapshot was taken. If `kubectl` shows certificate or lease errors right after the revert, give chrony a minute or two to correct the time.

From the next post on, this cluster is used for hands-on practice, starting with the most common topic, workloads and scheduling: rolling updates, resource limits and autoscaling.

[Workloads and Scheduling](https://lcxlab.com/en/post/cka-workloads-scheduling)

---

[^Gentoo]: Gentoo is a Linux distribution known for its high degree of customization: users choose, compile and configure the software and components in their system to fit their own needs. The point here is the same philosophy of control and customization: kubeadm only provides the basic flow for initializing a Kubernetes cluster, and the user picks and integrates everything else.

---

References:

[1] Creating a cluster with kubeadm - https://kubernetes.io/docs/setup/production-environment/tools/kubeadm/create-cluster-kubeadm/

[2] Installing kubeadm - https://kubernetes.io/docs/setup/production-environment/tools/kubeadm/install-kubeadm/

[3] Container Runtimes - https://kubernetes.io/docs/setup/production-environment/container-runtimes/

[4] Getting started with containerd - https://github.com/containerd/containerd/blob/main/docs/getting-started.md

[5] Calico Documentation - https://docs.tigera.io/calico/latest/about/

[6] Flannel - https://github.com/flannel-io/flannel
