Setting up a Kubernetes Cluster with Kubeadm
Scenario
As a Kubernetes administrator, you need to set up a new, highly available Kubernetes cluster from scratch using kubeadm
. This cluster will host critical applications, so a proper and robust setup is essential. You will configure two nodes: one control plane node and one worker node.
Requirements
-
Prepare the Nodes:
- Ensure you have at least two machines (VMs or physical) running a compatible Linux distribution (e.g., Ubuntu 22.04, CentOS 7/8).
- For local VMs (MacBook M-series): You can use free virtualization software like VirtualBox (requires ARM-based Linux guests like Ubuntu for ARM), UTM, or Multipass to create ARM-based Linux virtual machines. These tools provide excellent performance for running Linux VMs on M-series chips.
- Alternatively, use Cloud VMs: If local virtualization is not feasible or preferred, you can provision two virtual machines on any cloud provider (e.g., AWS EC2, Google Cloud Compute Engine, Azure VMs) running a compatible Linux distribution.
- Each node must have at least 2GB of RAM and 2 CPUs.
- Disable swap on all nodes.
- Install a container runtime (e.g., containerd) on all nodes.
- Install
kubelet
, kubeadm
, and kubectl
on all nodes.
-
Initialize the Control Plane:
- Initialize the Kubernetes control plane on the designated control plane node using
kubeadm
.
- Ensure the Pod Network Add-on (e.g., Calico or Flannel) is installed.
-
Join the Worker Node:
- Join the worker node to the cluster using the
kubeadm join
command generated during control plane initialization.
-
Verify Cluster Health:
- Confirm that all nodes are in the
Ready
state.
- Verify that all core Kubernetes components (pods in
kube-system
namespace) are running.
Acceptance Criteria:
- A functional Kubernetes cluster with one control plane node and one worker node is established.
kubectl get nodes
shows both nodes in Ready
status.
kubectl get pods -n kube-system
shows all system pods running.
- You can deploy a simple application (e.g., Nginx) and access it.
Resources
Possible Ways to Implement
- Disable Swap: Use
sudo swapoff -a
and remove the swap entry from /etc/fstab
.
- Install Containerd: Follow the official Docker/containerd documentation for your OS.
- Install Kubeadm, Kubelet, Kubectl: Add Kubernetes apt/yum repositories and install the packages.
- Kubeadm Init: Use
sudo kubeadm init
with appropriate flags (e.g., --pod-network-cidr
).
- Pod Network Add-on: Apply the YAML manifest for your chosen CNI (e.g.,
kubectl apply -f https://docs.projectcalico.org/manifests/calico.yaml
).
- Kubeadm Join: Execute the command provided by
kubeadm init
on the worker node.
Real-World Significance
Setting up a Kubernetes cluster is the foundational task for any administrator. Mastering kubeadm
provides a deep understanding of how Kubernetes components interact and how a cluster is bootstrapped. This knowledge is critical for troubleshooting, maintaining, and scaling production Kubernetes environments. It directly prepares you for the CKA exam's focus on cluster architecture and installation, enabling you to build and manage robust Kubernetes infrastructure.