---
title: 所有节点公共操作
description: "在所有master和工作节点下完成K8s集群软件安装、Containerd配置以及其他相关操作。"
url: https://www.hikunpeng.com/document/detail/zh/kunpengboostkithistory/2400/armnative/kunpengcpsvideo_20_0079.html
sourcePath: /source/zh/kunpengboostkithistory/2400/armnative/kunpengcpsvideo_20_0079.html
indexId: d513c2ed30dbd5906f5568f502edb9656c320126ac978bdb0a0205dee1f56d0377
---
# 所有节点公共操作

在所有master和工作节点下完成K8s集群软件安装、Containerd配置以及其他相关操作。

1. 修改hostname，保证每台服务器hostname不重复。
例如：

  - 在master节点上将hostname修改为k8s-master。

```
hostnamectl set-hostname k8s-master
bash
```


  - 在工作节点上将hostname修改为k8s-slave1。

```
hostnamectl set-hostname k8s-slave1
bash
```


2. 将所有服务器密码修改为相同的。
3. 关闭防火墙。
  1 2 systemctl stop firewalld systemctl disable firewalld

4. 关闭交换分区。

  - 单次生效，执行如下命令。
    1 swapoff -a

  - 永久生效，在“fstab”文件中注释swap自动挂载。
    1 sed -i "/\/dev\/mapper\/openeuler-swap/ s|^|#|" /etc/fstab

5. 禁用SELinux。
  1 sed -i "s|SELINUX=.*|SELINUX=disabled|g" /etc/selinux/config

6. 配置安装K8s集群所需软件的源。
  1 2 3 4 5 6 7 8 9 10 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 exclude=kubelet kubeadm kubectl cri-tools kubernetes-cni EOF

7. 安装K8s集群软件。
  1 2 yum install -y kubelet kubeadm kubectl kubernetes-cni --disableexcludes=kubernetes systemctl enable --now kubelet

8. 请参见（可选）部署Containerd环境的1至3安装Containerd和runc组件。在完成Containerd和runc的组件安装后，工作节点需要额外执行6进行docker服务的重启。
9. 修改Containerd配置。
  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

10. 配置crictl，并重启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

11. 配置网络转发。该步骤服务器重启后需重新执行。
  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
