Common Operations on All 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.
systemctl stop firewalld systemctl disable firewalld
- Disable SWAP partitions.
- Run the following command. The setting becomes invalid after the server restarts.
swapoff -a
- Comment out the code for automatic mounting of SWAP partitions in the fstab file. The setting is still valid after the server restarts.
- Open the fstab file.
vi /etc/fstab
- Press i to enter the insert mode and comment out the line where /dev/mapper/openeuler-swap is located.
- Press Esc, type :wq, and press Enter to save the file and exit.
- Open the fstab file.
- Run the following command. The setting becomes invalid after the server restarts.
- Disable SELinux.
- Configure the source required for installing Kubernetes cluster software.
- Go to the /etc/yum.repos.d/ directory.
cd /etc/yum.repos.d/
- Open the kubernetes.repo file.
vi kubernetes.repo
- Press i to enter the insert mode and add the following content:
[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 exclude=kubelet kubeadm kubectl cri-tools kubernetes-cni
- Press Esc, type :wq!, and press Enter to save the file and exit.
- Go to the /etc/yum.repos.d/ directory.
- Install Kubernetes cluster software.
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.
mkdir -p /etc/containerd/ cd /etc/containerd/ containerd config default > /etc/containerd/config.toml
- Open the /etc/containerd/config.toml file.
vi /etc/containerd/config.toml
- Press i to enter the insert mode and change the value of SystemdCgroup to true.
SystemdCgroup = true
- Press Esc, type :wq!, and press Enter to save the file and exit.
- Open the /etc/containerd/config.toml file.
- Configure crictl.
- Open the crictl.yaml file.
vi /etc/crictl.yaml
- Press i to enter the insert mode and add the following content:
runtime-endpoint: unix:///run/containerd/containerd.sock image-endpoint: unix:///run/containerd/containerd.sock timeout: 10
- Press Esc, type :wq!, and press Enter to save the file and exit.
- Restart containerd.
systemctl daemon-reload systemctl restart containerd
- Open the crictl.yaml file.
- Configure network forwarding. Perform this step again after the server is restarted.
modprobe overlay modprobe br_netfilter
- Open the k8s.conf file.
vi /etc/sysctl.d/k8s.conf
- Press i to enter the insert mode and add the following content:
net.bridge.bridge-nf-call-ip6tables=1 net.bridge.bridge-nf-call-iptables=1 net.ipv4.ip_forward=1
- Press Esc, type :wq!, and press Enter to save the file and exit.
- Make the configuration take effect.
sysctl -p /etc/sysctl.d/k8s.conf
- Open the k8s.conf file.
Parent topic: Setting Up a Kubernetes Cluster