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

在所有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. 配置安装K8s集群所需软件的源。
  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

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

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

9. 配置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

10. 安装yq工具，用于后续通过脚本动态调整yaml文件
  1 2 wget https://github.com/mikefarah/yq/releases/latest/download/yq_linux_arm64 --no-check-certificate -O /usr/local/bin/yq chmod +x /usr/local/bin/yq

11. 配置网络转发。该步骤服务器重启后需重新执行。
  1 2 3 4 5 6 7 modprobe overlay modprobe br_netfilter modprobe xt_multiport 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
