Version note: examples use the Kubernetes v1.35 documentation snapshot, not necessarily the newest release. Check current support and component compatibility. These commands were not tested on a live cluster.
What this guide covers
Kubernetes runs applications across machines called nodes. The control-plane node manages cluster state; the worker node runs the application containers. This guide builds one of each for learning.
Before you start
Use two fresh Ubuntu Server 24.04 machines with sudo access, unique hostnames and stable private IP addresses. Allow at least 2 CPUs and 2 GiB RAM per machine; more memory is useful. Do not run these host-changing commands on a production server.
The examples use cp1 at 192.168.50.10, worker1 at 192.168.50.11, and DNS name cp1.lab.example. Replace these consistently. Both machines must resolve the DNS name. Keep clocks synchronized. This cluster is not highly available.
Step 1: Plan network access
The Pod network is 10.244.0.0/16 and the Service network is 10.96.0.0/12. These ranges must not overlap your LAN or VPN.
Allow TCP 6443 from the worker and administrators to the control plane, TCP 10250 between required cluster hosts, and UDP 8472 between the nodes for Flannel. Keep etcd ports 2379–2380 and other control-plane ports private. Preserve SSH access when changing firewalls.
Step 2: Prepare both machines
Run on both machines:
sudo swapoff -a
swapon --show
sudo modprobe overlay
sudo modprobe br_netfilter
printf 'overlay\nbr_netfilter\n' | sudo tee /etc/modules-load.d/kubernetes.conf
cat <<'SYSCTL' | sudo tee /etc/sysctl.d/99-kubernetes.conf
net.ipv4.ip_forward = 1
net.bridge.bridge-nf-call-iptables = 1
net.bridge.bridge-nf-call-ip6tables = 1
SYSCTL
sudo sysctl --system
sudo apt-get update
sudo apt-get install -y containerd ca-certificates curl gpg
containerd --version
swapon --show should be empty. Inspect /etc/fstab and swap services so swap stays disabled after reboot. The remaining settings enable the packet forwarding used by the cluster.
Step 3: Configure containerd on both machines
containerd starts containers for Kubernetes. On each fresh machine, generate its configuration:
sudo install -d /etc/containerd
containerd config default > /tmp/containerd-default.toml
sudo install -m 0644 /tmp/containerd-default.toml /etc/containerd/config.toml
sudoedit /etc/containerd/config.toml
In that file, ensure cri is not in disabled_plugins. Set SystemdCgroup = true under the installed version’s runc options: containerd 1.x uses plugins."io.containerd.grpc.v1.cri".containerd.runtimes.runc.options; 2.x uses plugins."io.containerd.cri.v1.runtime".containerd.runtimes.runc.options. This makes the runtime and Kubernetes use the same resource-management system.
sudo systemctl enable --now containerd
sudo systemctl restart containerd
sudo systemctl status containerd --no-pager
Step 4: Install Kubernetes tools on both machines
Use the same supported package version on each machine:
sudo install -d -m 0755 /etc/apt/keyrings
curl -fsSL https://pkgs.k8s.io/core:/stable:/v1.35/deb/Release.key \
| sudo gpg --dearmor -o /etc/apt/keyrings/kubernetes-apt-keyring.gpg
printf '%s\n' 'deb [signed-by=/etc/apt/keyrings/kubernetes-apt-keyring.gpg] https://pkgs.k8s.io/core:/stable:/v1.35/deb/ /' \
| sudo tee /etc/apt/sources.list.d/kubernetes.list
sudo apt-get update
apt-cache madison kubeadm
read -r -p 'Approved full package version, including distribution suffix: ' KUBE_PACKAGE
sudo apt-get install -y kubelet="$KUBE_PACKAGE" kubeadm="$KUBE_PACKAGE" kubectl="$KUBE_PACKAGE"
sudo apt-mark hold kubelet kubeadm kubectl
sudo systemctl enable kubelet
The example repository is for v1.35. If selecting another minor release, update the repository, configuration API and compatibility checks together. A restarting kubelet before cluster setup can be expected; it must settle after joining.
Step 5: Initialize the control plane
On cp1 only, save this as kubeadm-init.yaml. Replace the addresses and use the exact approved Kubernetes patch version you installed:
apiVersion: kubeadm.k8s.io/v1beta4
kind: InitConfiguration
localAPIEndpoint:
advertiseAddress: 192.168.50.10
bindPort: 6443
nodeRegistration:
name: cp1
criSocket: unix:///run/containerd/containerd.sock
---
apiVersion: kubeadm.k8s.io/v1beta4
kind: ClusterConfiguration
kubernetesVersion: v1.35.10
controlPlaneEndpoint: cp1.lab.example:6443
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
Run:
sudo kubeadm config validate --config kubeadm-init.yaml
sudo kubeadm init --config kubeadm-init.yaml
mkdir -p "$HOME/.kube"
sudo install -o "$(id -u)" -g "$(id -g)" -m 0600 /etc/kubernetes/admin.conf "$HOME/.kube/config"
The copied kubeconfig grants administration access. Keep it private. Do not run kubeadm init on the worker.
Step 6: Install networking and join the worker
On cp1, choose a Flannel release compatible with your cluster. Download and inspect it, and compare its checksum with your reviewed artifact record before applying:
FLANNEL_RELEASE=v0.28.1
curl --fail --location --proto '=https' --tlsv1.2 \
-o kube-flannel.yml "https://github.com/flannel-io/flannel/releases/download/${FLANNEL_RELEASE}/kube-flannel.yml"
sha256sum kube-flannel.yml
# Review the downloaded manifest and verify it against your approved artifact record.
kubectl apply -f ./kube-flannel.yml
kubectl -n kube-flannel rollout status daemonset/kube-flannel-ds --timeout=180s
sudo kubeadm token create --ttl 30m --print-join-command
Copy the printed kubeadm join command to worker1 and run it there with sudo. It contains the real token and CA hash. Do not add --control-plane or skip CA verification. Add the containerd socket option if the host has multiple runtimes.
Flannel supplies Pod networking but does not enforce NetworkPolicy by itself. Do not install a second network plugin on top of it.
Step 7: Run a test web server
Wait until both nodes are Ready. On cp1, save this as smoke.yaml:
apiVersion: v1
kind: Namespace
metadata:
name: k8s-lab
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: web
namespace: k8s-lab
spec:
replicas: 1
selector:
matchLabels:
app: web
template:
metadata:
labels:
app: web
spec:
containers:
- name: web
image: nginx:1.28.0
ports:
- name: http
containerPort: 80
resources:
requests:
cpu: 100m
memory: 64Mi
limits:
memory: 128Mi
readinessProbe:
httpGet:
path: /
port: http
initialDelaySeconds: 2
periodSeconds: 5
---
apiVersion: v1
kind: Service
metadata:
name: web
namespace: k8s-lab
spec:
selector:
app: web
ports:
- port: 80
targetPort: http
Apply and check it:
kubectl get nodes -o wide
kubectl -n kube-system get pods -o wide
kubectl apply --dry-run=server -f smoke.yaml
kubectl apply -f smoke.yaml
kubectl -n k8s-lab rollout status deployment/web --timeout=120s
kubectl -n k8s-lab get pods -o wide
kubectl -n k8s-lab get endpointslices -l kubernetes.io/service-name=web
kubectl -n k8s-lab port-forward service/web 8080:80
The last command stays running. In another terminal, open http://127.0.0.1:8080; stop forwarding with Ctrl+C. To test cluster DNS and Service routing separately, run an in-cluster client and request http://web.k8s-lab.svc.cluster.local.
Check the result
Confirm both nodes and the web Pod are Ready, the HTTP request works and the worker returns after a planned reboot. If a Pod is Pending, read its events before changing settings. One worker cannot keep applications available when it is down. Delete only the test namespace when finished; do not use kubeadm reset as a routine repair.
Conversation
0 commentsNo comments yet. Start the conversation below.