Pre-Installation Checks
k8s-master01, k8s-worker01) using sudo hostnamectl set-hostname. Add entries to /etc/hosts mapping IPs to hostnames (e.g., 192.168.1.20 k8s-master01), ensuring name resolution works across the cluster.sudo swapoff -a to disable swap temporarily, then edit /etc/fstab to comment out or remove the swap line. Use sudo swapon --show to verify swap is off.Install Container Runtime
sudo apt update
sudo apt install -y containerd
Configure containerd to use required kernel modules by creating /etc/modules-load.d/containerd.conf with:overlay
br_netfilter
Load the modules immediately with sudo modprobe overlay && sudo modprobe br_netfilter. Set up sysctl rules for bridging in /etc/sysctl.d/99-kubernetes-k8s.conf:net.bridge.bridge-nf-call-iptables = 1
net.ipv4.ip_forward = 1
Apply sysctl changes with sudo sysctl --system.Install Kubernetes Components
sudo apt update
sudo apt install -y apt-transport-https curl
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.list
sudo apt update
sudo apt install -y kubelet kubeadm kubectl
sudo apt-mark hold kubelet kubeadm kubectl
Initialize Kubernetes Cluster
kubeadm init with critical parameters for networking. For example:sudo kubeadm init --apiserver-advertise-address=<MASTER_IP> --pod-network-cidr=10.244.0.0/16 --service-cidr=10.100.0.0/16 --image-repository registry.aliyuncs.com/google_containers
Replace <MASTER_IP> with the master’s static IP. The --pod-network-cidr must match your chosen network plugin’s requirements (e.g., Flannel uses 10.244.0.0/16).kubectl to communicate with the cluster:mkdir -p $HOME/.kube
sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config
sudo chown $(id -u):$(id -g) $HOME/.kube/config
Deploy a Network Plugin
kubectl apply -f https://raw.githubusercontent.com/coreos/flannel/master/Documentation/kube-flannel.yml
wget https://docs.projectcalico.org/v3.26.1/manifests/calico.yaml
kubectl apply -f calico.yaml
sudo ufw allow 179/tcp
sudo ufw allow 4789/udp
sudo ufw reload
Verify Network Configuration
kube-system namespace:kubectl get pods -n kube-system
Look for Running status next to Flannel/Calico pods.kubectl create deployment nginx-app --image=nginx --replicas=2
kubectl expose deployment nginx-app --name=nginx-web-svc --type=NodePort --port=80 --target-port=80
Get the NodePort assigned to the service (kubectl get svc nginx-web-svc) and access it from any node or external machine using <NODE_IP>:<NODE_PORT>.Join Worker Nodes (Optional)
kubeadm token create --print-join-command to generate a command like:sudo kubeadm join <MASTER_IP>:6443 --token <TOKEN> --discovery-token-ca-cert-hash sha256:<HASH>
Ready with kubectl get nodes.