CLOUDLAUNCH/LAB

Chapter 13 · Kubernetes installation

Install Kubernetes on AWS EC2

A beginner-friendly single-node lab for Ubuntu 24.04 LTS using containerd, kubeadm, kubectl, and Flannel. Complete each step in order on your EC2 instance.

Lab requirements

Use Ubuntu Server 24.04 LTS, x86_64, a t3.large instance, 30 GB gp3 storage, and an EC2 security group that permits SSH from your IP. Running Jenkins, Docker builds, and Kubernetes on a small instance can cause out-of-memory errors.

1

Prepare Ubuntu

Update the EC2 host and install the tools needed for the lab.

EC2 terminal
sudo apt update
sudo apt upgrade -y
sudo apt install -y curl wget ca-certificates gnupg apt-transport-https software-properties-common
2

Disable swap

Kubernetes expects swap to be disabled under the standard kubelet configuration.

EC2 terminal
sudo swapoff -a
sudo sed -i '/ swap / s/^/#/' /etc/fstab
3

Load kernel modules

Enable overlay networking and bridge filtering.

EC2 terminal
sudo tee /etc/modules-load.d/k8s.conf <<EOF
overlay
br_netfilter
EOF
sudo modprobe overlay
sudo modprobe br_netfilter
4

Configure sysctl

Forward packets and allow bridged traffic to be inspected by iptables.

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

Install and configure containerd

containerd is the container runtime used by kubelet. Generate its config and use the systemd cgroup driver.

EC2 terminal
sudo apt install -y containerd
sudo mkdir -p /etc/containerd
containerd config default | sudo tee /etc/containerd/config.toml
sudo nano /etc/containerd/config.toml

In the runtimes.runc.options section set SystemdCgroup = true, then restart the service.

Restart containerd
sudo systemctl restart containerd
sudo systemctl enable containerd
sudo systemctl status containerd
6

Install Kubernetes components

Install matching versions of kubeadm, kubelet, and kubectl from the currently supported pkgs.k8s.io repository. Choose the current minor version from the official Kubernetes documentation rather than copying an old repository URL.

Repository pattern
# Select a currently supported Kubernetes minor version first
# Then add its matching pkgs.k8s.io repository
sudo apt-get update
sudo apt-get install -y kubelet kubeadm kubectl
sudo apt-mark hold kubelet kubeadm kubectl
7

Initialize the cluster

Initialize the control plane with the Flannel pod network range and containerd CRI socket. Save the join command printed at the end.

EC2 terminal
sudo kubeadm init --pod-network-cidr=10.244.0.0/16 --cri-socket=unix:///run/containerd/containerd.sock
8

Configure kubectl

Copy the admin kubeconfig into the Ubuntu user home directory.

EC2 terminal
mkdir -p $HOME/.kube
sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config
sudo chown $(id -u):$(id -g) $HOME/.kube/config
kubectl get nodes

The node may show NotReady until a CNI plugin is installed.

9

Install Flannel CNI

Flannel provides pod-to-pod networking. Its network must match the 10.244.0.0/16 CIDR used above.

EC2 terminal
kubectl apply -f https://github.com/flannel-io/flannel/releases/latest/download/kube-flannel.yml
kubectl get pods -A -w
10

Verify the cluster

Check node health, every namespace, and the API endpoint.

EC2 terminal
kubectl get nodes -o wide
kubectl get pods -A
kubectl cluster-info
11

Allow workloads on the control plane

For this single-node learning lab only, remove the scheduling taint. Production clusters should use separate worker nodes.

EC2 terminal
kubectl taint nodes --all node-role.kubernetes.io/control-plane-
kubectl describe nodes
Troubleshooting: if the node remains NotReady, inspect sudo systemctl status containerd, sudo systemctl status kubelet, sudo journalctl -u kubelet -xe, sudo crictl info, kubectl describe node, and kubectl get events -A --sort-by=.metadata.creationTimestamp. Check the actual error before applying a fix.