Common Operations on All Nodes
Install Kubernetes cluster software, configure containerd, and perform other related operations on all master and worker nodes.
- Change the host names to ensure that the host name of each server is unique.
For example:
- On the master node, change the host name to k8s-master.
hostnamectl set-hostname k8s-master bash
- On the worker node, change the host name to k8s-slave1.
hostnamectl set-hostname k8s-slave1 bash
- On the master node, change the host name to k8s-master.
- Change the passwords of all servers to the same.
- Disable the firewall.
1 2
systemctl stop firewalld systemctl disable firewalld
- Disable SWAP partitions.
- Run the following command. The setting becomes invalid after the server restarts.
1swapoff -a
- Comment out the code for automatic mounting of SWAP partitions in the fstab file. The setting is still valid after the server restarts.
1sed -i "/\/dev\/mapper\/openeuler-swap/ s|^|#|" /etc/fstab
- Run the following command. The setting becomes invalid after the server restarts.
- Disable SELinux.
1sed -i "s|SELINUX=.*|SELINUX=disabled|g" /etc/selinux/config
- Configure the source required for installing Kubernetes cluster software.
1 2 3 4 5 6 7 8 9
touch /etc/yum.repos.d/kubernetes.repo cat >/etc/yum.repos.d/kubernetes.repo <<EOF [kubernetes] name=Kubernetes baseurl=https://pkgs.k8s.io/core:/stable:/v1.28/rpm/ enabled=1 gpgcheck=1 gpgkey=https://pkgs.k8s.io/core:/stable:/v1.28/rpm/repodata/repomd.xml.key EOF
- Install Kubernetes cluster software.
1 2
yum install -y kubelet kubeadm kubectl kubernetes-cni --disableexcludes=kubernetes systemctl enable --now kubelet
- Install containerd and runC based on 1 to 3 in (Optional) Deploying the Containerd Environment. After the installation is successful, restart the Docker service based on 6 on the worker node.
- Modify the containerd configuration file.
1 2 3 4
mkdir -p /etc/containerd/ cd /etc/containerd/ containerd config default > /etc/containerd/config.toml sed -i "s|SystemdCgroup =.*|SystemdCgroup = true|g" /etc/containerd/config.toml
- Configure crictl and restart containerd.
1 2 3 4 5
echo "runtime-endpoint: unix:///run/containerd/containerd.sock" >> /etc/crictl.yaml echo "image-endpoint: unix:///run/containerd/containerd.sock" >> /etc/crictl.yaml echo "timeout: 10" >> /etc/crictl.yaml systemctl daemon-reload systemctl restart containerd
- Configure network forwarding. Perform this step again after the server is restarted.
1 2 3 4 5 6
modprobe overlay modprobe br_netfilter echo "net.bridge.bridge-nf-call-ip6tables=1" >> /etc/sysctl.d/k8s.conf echo "net.bridge.bridge-nf-call-iptables=1" >> /etc/sysctl.d/k8s.conf echo "net.ipv4.ip_forward=1" >> /etc/sysctl.d/k8s.conf sysctl -p /etc/sysctl.d/k8s.conf
Parent topic: Setting Up a Kubernetes Cluster