Installing the Container Runtime
Docker serves as the underlying container runtime for Kubernetes. Update the package index and install Docker using the following commands:
sudo apt-get update
sudo apt-get install -y docker.ioOnce installed, ensure the Docker service is running:
sudo systemctl start docker
sudo systemctl enable dockerDeploying Kubernetes Components
Install the essential Kubernetes administration tools: kubeadm, kubelet, and kubectl. First, add the Kubernetes repository and GPG key:
sudo apt-get update && sudo apt-get install -y apt-transport-https
curl -s https://packages.cloud.google.com/apt/doc/apt-key.gpg | sudo apt-key add -
echo "deb https://apt.kubernetes.io/ kubernetes-xenial main" | sudo tee /etc/apt/sources.list.d/kubernetes.listUpdate the package list and install the components. It is recommended to hold the packages at their current version to prevent automatic updates:
sudo apt-get update
sudo apt-get install -y kubelet kubeadm kubectl
sudo apt-mark hold kubelet kubeadm kubectlInitializing the Control Plane Node
With the binaries installed, initialize the control plane (Master node). Specify a Pod network CIDR to enable network add-ons later. Flannel, for instance, typically requires 10.244.0.0/16:
sudo kubeadm init --pod-network-cidr=10.244.0.0/16Upon completion, the output will display a join command for worker nodes. Make sure to record this token and hash for future use.
Configuring User Access and Networking
To allow a non-root user to interact with the cluster, configure the kubectl client configuration:
mkdir -p $HOME/.kube
sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config
sudo chown $(id -u):$(id -g) $HOME/.kube/configInstall a Container Network Interface (CNI) plugin so Pods can communicate. Apply the Flannel manifest:
kubectl apply -f https://raw.githubusercontent.com/coreos/flannel/master/Documentation/kube-flannel.ymlJoining Worker Nodes
On each worker node, execute the join command provided during the initialization of the control plane. Replace the placeholders with the actual IP address, token, and certificate hash:
sudo kubeadm join <CONTROL_PLANE_IP>:<PORT> --token <TOKEN> --discovery-token-ca-cert-hash sha256:<HASH>Verifying the Cluster Status
Check the health of the cluster by listing the nodes and verifying their status is Ready:
kubectl get nodesInspect the core components running in the kube-system namespace to ensure all Pods are operational:
kubectl get pods --all-namespaces