Kubernetes on CentOS: Essential Installation Resources & Requirements
Installing Kubernetes (K8s) on CentOS requires careful preparation of system resources, configuration adjustments, and sequential execution of steps. Below are critical resources and recommendations to ensure a successful deployment.
Before starting, verify your CentOS system meets the minimum hardware and software specifications:
Preparation is key to avoiding conflicts during installation. Follow these critical steps:
sudo setenforce 0  # Temporary disable
sudo sed -i 's/^SELINUX=enforcing/SELINUX=disabled/' /etc/selinux/config  # Permanent disable
sudo swapoff -a  # Temporary disable
sudo sed -i '/swap/s//#/' /etc/fstab  # Comment out swap entry in fstab (permanent disable)
/etc/sysctl.d/k8s.conf and add:net.bridge.bridge-nf-call-ip6tables = 1
net.bridge.bridge-nf-call-iptables = 1
net.ipv4.ip_forward = 1
Load the changes with sudo sysctl --system.master-node, worker-node1) using hostnamectl set-hostname <name>. Then, edit /etc/hosts on all nodes to map IP addresses to hostnames (e.g., 192.168.1.10 master-node).ntpdate or chrony to sync system time across nodes. For example:sudo yum install -y ntpdate
sudo ntpdate time.windows.com  # Or use a local NTP server
These steps ensure system stability and compatibility with Kubernetes.
Kubernetes relies on Docker (or another compatible container runtime) and its own components (kubelet, kubeadm, kubectl). Follow these steps to install them:
sudo yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo
sudo yum install -y docker-ce docker-ce-cli containerd.io
sudo systemctl enable docker && sudo systemctl start docker
/etc/yum.repos.d/kubernetes.repo with the following content:[kubernetes]
name=Kubernetes
baseurl=https://packages.cloud.google.com/yum/repos/kubernetes-el7-x86_64
enabled=1
gpgcheck=1
repo_gpgcheck=1
gpgkey=https://packages.cloud.google.com/yum/doc/yum-key.gpg https://packages.cloud.google.com/yum/doc/rpm-package-key.gpg
kubelet, kubeadm, and kubectl:sudo yum install -y kubelet kubeadm kubectl --disableexcludes=kubernetes
Enable and start kubelet:sudo systemctl enable kubelet && sudo systemctl start kubelet
Docker is the most commonly used container runtime, but you can also use containerd or CRI-O if preferred.
The kubeadm tool simplifies cluster setup. Here’s how to initialize a Master node:
<Master_IP> with your Master node’s IP and adjust --pod-network-cidr if needed):sudo kubeadm init --apiserver-advertise-address=<Master_IP> --pod-network-cidr=10.244.0.0/16
This command generates a kubeadm join command (save it—you’ll need it for Worker nodes) and sets up the Master node.mkdir -p $HOME/.kube
sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config
sudo chown $(id -u):$(id -g) $HOME/.kube/config
kubectl apply -f https://raw.githubusercontent.com/coreos/flannel/master/Documentation/kube-flannel.yml
For Calico (recommended for production):kubectl apply -f https://docs.projectcalico.org/manifests/tigera-operator.yaml
kubectl apply -f https://docs.projectcalico.org/manifests/custom-resources.yaml
The Master node is now ready. Verify its status with kubectl get nodes (it should show “NotReady” until Worker nodes join).
To scale your cluster, join Worker nodes using the kubeadm join command generated during Master initialization. On each Worker node:
sudo kubeadm join <Master_IP>:6443 --token <token> --discovery-token-ca-cert-hash <hash>
Replace <token> and <hash> with values from the Master’s kubeadm init output. After joining, run kubectl get nodes on the Master to confirm the Worker node status (should change to “Ready”).
Check the health of your cluster with these commands:
kubectl get nodes
kubectl get pods -A
kubectl create deployment nginx --image=nginx
kubectl expose deployment nginx --type=NodePort --port=80
kubectl get svc nginx
Access the Nginx service using the NodePort (e.g., http://<Master_IP>:<NodePort>).
By following these recommendations and steps, you can successfully install Kubernetes on CentOS. Always refer to the official Kubernetes documentation for the latest updates and troubleshooting tips.