Installing the Latest Kubernetes Version on CentOS
This guide provides a step-by-step workflow to install the latest stable Kubernetes version (e.g., 1.28 as of July 2025) on CentOS 7/8/9, covering environment preparation, container runtime setup, Kubernetes component installation, and cluster initialization.
1. Environment Preparation
Before starting, ensure your CentOS nodes meet the following requirements:
- Hardware: At least 2 CPU cores, 2GB RAM, and 20GB storage.
- Network: All nodes must be able to communicate with each other (no firewall blocking critical ports).
- OS: CentOS 7.9+ or 8/9 (minimal installation recommended).
Execute the following commands on all nodes to configure prerequisites:
# Disable SELinux (Kubernetes requires this for pod network communication)
sudo setenforce 0
sudo sed -i 's/SELINUX=enforcing/SELINUX=disabled/g' /etc/selinux/config
# Disable swap (Kubernetes does not support swap by default)
sudo swapoff -a
sudo sed -i '/swap/s/^/#/' /etc/fstab
# Configure kernel parameters for bridge networking
cat <<EOF | sudo tee /etc/modules-load.d/k8s.conf
br_netfilter
EOF
sudo modprobe br_netfilter
cat <<EOF | sudo tee /etc/sysctl.d/k8s.conf
net.bridge.bridge-nf-call-ip6tables = 1
net.bridge.bridge-nf-call-iptables = 1
net.ipv4.ip_forward = 1
EOF
sudo sysctl --system
# Install essential utilities
sudo yum install -y conntrack ipvsadm ipset jq iptables curl sysstat libseccomp wget vim net-tools git
2. Install Container Runtime (Containerd)
Kubernetes recommends containerd as the default container runtime. Follow these steps to install it:
# Create containerd configuration directory
sudo mkdir -p /etc/containerd
# Generate default containerd configuration
sudo containerd config default | sudo tee /etc/containerd/config.toml
# Modify the configuration to use systemd as cgroup driver (required for Kubernetes)
sudo sed -i 's/SystemdCgroup = false/SystemdCgroup = true/g' /etc/containerd/config.toml
# Restart containerd to apply changes
sudo systemctl restart containerd
sudo systemctl enable containerd
3. Add Kubernetes YUM Repository
To install the latest Kubernetes components (kubelet, kubeadm, kubectl), add the official Kubernetes YUM repository:
# Create Kubernetes repository file
cat <<EOF | sudo tee /etc/yum.repos.d/kubernetes.repo
[kubernetes]
name=Kubernetes
baseurl=https://mirrors.aliyun.com/kubernetes-new/core/stable/v1.28/rpm/
enabled=1
gpgcheck=1
gpgkey=https://mirrors.aliyun.com/kubernetes-new/core/stable/v1.28/rpm/repodata/repomd.xml.key
EOF
4. Install Kubernetes Components
Install the latest versions of kubelet, kubeadm, and kubectl (replace 1.28 with your desired version if needed):
# Install components (ignore GPG errors if using Alibaba Cloud mirrors)
sudo yum install -y --nogpgcheck kubelet-1.28.3 kubeadm-1.28.3 kubectl-1.28.3
# Enable and start kubelet (required for cluster operation)
sudo systemctl enable kubelet
sudo systemctl start kubelet
5. Initialize Master Node
On the master node, use kubeadm to initialize the cluster. This command sets up the control plane (API server, scheduler, controller manager) and generates a token for worker nodes to join:
# Initialize the cluster with Flannel network plugin (recommended for beginners)
sudo kubeadm init \
--kubernetes-version=v1.28.3 \
--pod-network-cidr=10.244.0.0/16 \
--cri-socket=unix:///var/run/containerd/containerd.sock \
--apiserver-advertise-address= # Replace with your master node's IP
After initialization, kubeadm will output a join command (e.g., kubeadm join ). Save this command—you’ll need it to add worker nodes later.
Configure kubectl to connect to the cluster:
# Create .kube directory and copy admin.conf
mkdir -p $HOME/.kube
sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config
sudo chown $(id -u):$(id -g) $HOME/.kube/config
6. Install Network Plugin (Flannel)
Kubernetes requires a network plugin for pod-to-pod communication. Flannel is a popular choice for its simplicity:
# Apply Flannel manifest (downloads and installs the plugin)
kubectl apply -f https://raw.githubusercontent.com/flannel-io/flannel/master/Documentation/kube-flannel.yml
7. Join Worker Nodes
On each worker node, execute the join command obtained from the master node initialization step. For example:
sudo kubeadm join 192.168.1.10:6443 --token abcdef.1234567890abcdef \
--discovery-token-ca-cert-hash sha256:1234567890abcdef1234567890abcdef1234567890abcdef1234567890abcdef
8. Verify Cluster Status
On the master node, run the following commands to confirm the cluster is healthy:
# Check node status (should show "Ready" for all nodes)
kubectl get nodes
# Check pod status (all pods should be "Running" or "Completed")
kubectl get pods -A
Troubleshooting Tips
- CRI Socket Errors: If you encounter errors related to the CRI socket (e.g.,
cri-dockerdnot found), ensure you’re usingcontainerd(not Docker) and specify the correct socket path (--cri-socket=unix:///var/run/containerd/containerd.sock) duringkubeadm init. - Image Pull Errors: If
kubeadmfails to pull images, manually pull them usingkubeadm config images pullor configure a private container registry mirror. - Firewall Issues: Ensure all nodes allow traffic on Kubernetes ports (e.g., 6443 for API server, 10250 for kubelet).
For further assistance, refer to the official Kubernetes documentation or community forums.
以上就是关于“centos k8s安装最新版本”的相关介绍,筋斗云是国内较早的云主机应用的服务商,拥有10余年行业经验,提供丰富的云服务器、租用服务器等相关产品服务。云服务器资源弹性伸缩,主机vCPU、内存性能强悍、超高I/O速度、故障秒级恢复;电子化备案,提交快速,专业团队7×24小时服务支持!
简单好用、高性价比云服务器租用链接:https://www.jindouyun.cn/product/cvm