Deploying a Kubernetes Cluster with Containerd Runtime

Preparing Host System Configuration on All Nodes

Configure System Package Repository

Replace the default system repository with an Aliyun mirror for faster package downloads.

mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.backup
curl -o /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-7.repo
sed -i -e '/mirrors.cloud.aliyuncs.com/d' -e '/mirrors.aliyuncs.com/d' /etc/yum.repos.d/CentOS-Base.repo

Configure Network, Security, and System Parameters

Configure static hostname resolution, disable security modules, and modify system settings required for Kubernetes.

cat <<EOF >> /etc/hosts
10.0.8.15 master-node-01
10.0.8.5 worker-node-01
EOF

# Disable SELinux
sed -i 's/SELINUX=enforcing/SELINUX=disabled/g' /etc/selinux/config

# Disable swap
swapoff -a
sed -i 's/\/dev\/mapper\/centos-swap/\#\/dev\/mapper\/centos-swap/g' /etc/fstab

# Configure time synchronization
yum install -y chrony
systemctl enable chronyd --now

# Set timezone
ln -sf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime

# Set hostname
hostnamectl set-hostname master-node-01

# Disable firewall
systemctl stop firewalld
systemctl disable firewalld

Optimize Kernel Parameters

Operating System Level Tuning

Apply system-wide kernel optimizations for network performance and resource limits.

cat <<EOF > /etc/sysctl.d/99-system-tuning.conf
net.ipv4.tcp_syncookies = 1
net.ipv4.tcp_abort_on_overflow = 1
net.ipv4.tcp_max_tw_buckets = 18000
net.ipv4.tcp_sack = 1
net.ipv4.tcp_window_scaling = 1
net.ipv4.tcp_rmem = 32768 699040 50331648
net.ipv4.tcp_wmem = 32768 131072 33554432
net.ipv4.tcp_slow_start_after_idle = 0
net.ipv4.tcp_synack_retries = 2
net.ipv4.tcp_mem = 94500000 915000000 927000000
net.core.optmem_max = 81920
net.core.rmem_default = 8388608
net.core.wmem_default = 8388608
net.core.rmem_max = 50331648
net.core.wmem_max = 50331648
net.ipv4.tcp_max_syn_backlog = 10240000
net.core.netdev_max_backlog = 862144
net.ipv4.tcp_max_orphans = 327680
net.ipv4.tcp_timestamps = 0
net.ipv4.tcp_syn_retries = 1
net.ipv4.tcp_fin_timeout = 10
net.ipv4.tcp_keepalive_time = 300
net.ipv4.tcp_keepalive_probes = 3
net.ipv4.tcp_keepalive_intvl = 15
net.ipv4.ip_local_port_range = 1024 65000
net.ipv4.ip_nonlocal_bind = 1
net.ipv4.neigh.default.gc_thresh1 = 2048
net.ipv4.neigh.default.gc_thresh2 = 4096
net.ipv4.neigh.default.gc_thresh3 = 8192
fs.inotify.max_user_instances = 8192
fs.file-max = 2097152
fs.inotify.max_user_watches = 524288
vm.max_map_count = 262144
kernel.threads-max = 300580
EOF
Kubernetes-Specific Kernel Configuration

Enable kernel modules and settings required for Kubernetes networking.

cat <<EOF > /etc/sysctl.d/99-kubernetes-cri.conf
net.bridge.bridge-nf-call-ip6tables = 1
net.bridge.bridge-nf-call-iptables = 1
net.ipv4.ip_nonlocal_bind = 1
net.ipv4.ip_forward = 1
EOF
sysctl --system
modprobe br_netfilter

Load IPVS Kernel Modules

cat <<EOF > /etc/sysconfig/modules/ipvs.modules
#!/bin/bash
modprobe -- ip_vs
modprobe -- ip_vs_rr
modprobe -- ip_vs_wrr
modprobe -- ip_vs_sh
modprobe -- nf_conntrack
EOF
chmod 755 /etc/sysconfig/modules/ipvs.modules && bash /etc/sysconfig/modules/ipvs.modules && lsmod | grep -e ip_vs -e nf_conntrack

Install IPVS Management Utilities

yum install -y ipset ipvsadm
reboot

Install and Configure Containerd Runtime

Add Container Runtime Repository

yum install -y yum-utils
yum-config-manager --add-repo https://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo

Install Containerd

yum install -y containerd.io
systemctl enable containerd --now

Modify Containerd Configuration

Generate a default configuration file and adjust storage paths.

containerd config default > /etc/containerd/config.toml
# Edit /etc/containerd/config.toml, modify the following parameters:
#   root = "/data/containerd"
#   sandbox_image = "registry.cn-hangzhou.aliyuncs.com/google_containers/pause-amd64:3.2"
systemctl daemon-reload
systemctl restart containerd

Install Kubernetes Components

Configure Kubernetes Repository

cat <<EOF > /etc/yum.repos.d/kubernetes.repo
[kubernetes]
name=Kubernetes
baseurl=https://mirrors.aliyun.com/kubernetes/yum/repos/kubernetes-el7-x86_64/
enabled=1
gpgcheck=1
repo_gpgcheck=0
gpgkey=https://mirrors.aliyun.com/kubernetes/yum/doc/yum-key.gpg https://mirrors.aliyun.com/kubernetes/yum/doc/rpm-package-key.gpg
EOF

Install Kubeadm, Kubelet, and Kubectl

yum install -y kubelet-1.27.3 kubeadm-1.27.3 kubectl-1.27.3
systemctl enable kubelet --now

Initialize the Kubernetes Control Plane

Generate Initial Configuration

kubeadm config print init-defaults > cluster-config.yaml

Edit the generated cluster-config.yaml file:

apiVersion: kubeadm.k8s.io/v1beta3
kind: InitConfiguration
localAPIEndpoint:
  advertiseAddress: 192.168.10.128
  bindPort: 6443
nodeRegistration:
  criSocket: unix:///var/run/containerd/containerd.sock
  name: master-node-01
---
apiVersion: kubeadm.k8s.io/v1beta3
kind: ClusterConfiguration
kubernetesVersion: v1.27.3
controlPlaneEndpoint: "192.168.10.128:6443"
networking:
  podSubnet: "10.244.0.0/16"
imageRepository: registry.aliyuncs.com/google_containers
---
apiVersion: kubeproxy.config.k8s.io/v1alpha1
kind: KubeProxyConfiguration
mode: ipvs

Pre-download Container Images

kubeadm config images pull --config cluster-config.yaml

Enitialize the Control Plane Node

kubeadm init --config=cluster-config.yaml --upload-certs | tee init-output.log

Configure kubectl

mkdir -p $HOME/.kube
cp -i /etc/kubernetes/admin.conf $HOME/.kube/config
chown $(id -u):$(id -g) $HOME/.kube/config

Configure Kubelet Resource Reservations

Modify /var/lib/kubelet/kubeadm-flags.env to include resource management arguments:

KUBELET_KUBEADM_ARGS="--network-plugin=cni --pod-infra-container-image=registry.aliyuncs.com/google_containers/pause:3.4.1 --max-pods=130 \
--system-reserved=cpu=20m,memory=100Mi \
--eviction-hard=memory.available<1Mi,nodefs.available<1Mi,imagefs.available<1Mi \
--eviction-minimum-reclaim=memory.available=1Gi,nodefs.available=500Mi,imagefs.available=1Gi \
--node-status-update-frequency=10s --eviction-pressure-transition-period=30s"

Restart the kubelet service to apply chenges.

Deploy Pod Network Add-on (Flannel Example)

kubectl apply -f https://github.com/flannel-io/flannel/releases/latest/download/kube-flannel.yml

Configure crictl for Containerd

crictl config runtime-endpoint unix:///run/containerd/containerd.sock
crictl config image-endpoint unix:///run/containerd/containerd.sock

Cluster Reset Procedure

Execute the following to reset a node to its pre-Kubernetes state:

kubeadm reset
systemctl stop kubelet
iptables -F && iptables -t nat -F && iptables -t mangle -F && iptables -X
ipvsadm --clear
rm -rf /var/lib/cni/*
rm -rf /var/lib/kubelet/*
rm -rf /etc/cni/*
rm -rf $HOME/.kube/config

Generate Join Command for Worker Nodes

kubeadm token create --print-join-command

Tags: kubernetes containerd kubeadm cluster-deployment Linux

Posted on Fri, 28 Aug 2026 16:54:09 +0000 by swordske