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.
Prepare Ubuntu
Update the EC2 host and install the tools needed for the lab.
sudo apt update
sudo apt upgrade -y
sudo apt install -y curl wget ca-certificates gnupg apt-transport-https software-properties-commonDisable swap
Kubernetes expects swap to be disabled under the standard kubelet configuration.
sudo swapoff -a
sudo sed -i '/ swap / s/^/#/' /etc/fstabLoad kernel modules
Enable overlay networking and bridge filtering.
sudo tee /etc/modules-load.d/k8s.conf <<EOF
overlay
br_netfilter
EOF
sudo modprobe overlay
sudo modprobe br_netfilterConfigure sysctl
Forward packets and allow bridged traffic to be inspected by iptables.
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 --systemInstall and configure containerd
containerd is the container runtime used by kubelet. Generate its config and use the systemd cgroup driver.
sudo apt install -y containerd
sudo mkdir -p /etc/containerd
containerd config default | sudo tee /etc/containerd/config.toml
sudo nano /etc/containerd/config.tomlIn the runtimes.runc.options section set SystemdCgroup = true, then restart the service.
sudo systemctl restart containerd
sudo systemctl enable containerd
sudo systemctl status containerdInstall 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.
# 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 kubectlInitialize the cluster
Initialize the control plane with the Flannel pod network range and containerd CRI socket. Save the join command printed at the end.
sudo kubeadm init --pod-network-cidr=10.244.0.0/16 --cri-socket=unix:///run/containerd/containerd.sockConfigure kubectl
Copy the admin kubeconfig into the Ubuntu user home directory.
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 nodesThe node may show NotReady until a CNI plugin is installed.
Install Flannel CNI
Flannel provides pod-to-pod networking. Its network must match the 10.244.0.0/16 CIDR used above.
kubectl apply -f https://github.com/flannel-io/flannel/releases/latest/download/kube-flannel.yml
kubectl get pods -A -wVerify the cluster
Check node health, every namespace, and the API endpoint.
kubectl get nodes -o wide
kubectl get pods -A
kubectl cluster-infoAllow workloads on the control plane
For this single-node learning lab only, remove the scheduling taint. Production clusters should use separate worker nodes.
kubectl taint nodes --all node-role.kubernetes.io/control-plane-
kubectl describe nodessudo 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.