所有节点公共操作
在所有master和工作节点下完成K8s集群软件安装、Containerd配置以及其他相关操作。
- 修改hostname,保证每台服务器hostname不重复。
例如:
- 在master节点上将hostname修改为k8s-master。
hostnamectl set-hostname k8s-master bash
- 在工作节点上将hostname修改为k8s-slave1。
hostnamectl set-hostname k8s-slave1 bash
- 在master节点上将hostname修改为k8s-master。
- 将所有服务器密码修改为相同的密码。
- 关闭防火墙。
1 2
systemctl stop firewalld systemctl disable firewalld
- 关闭交换分区。
- 单次生效,执行如下命令。
1
swapoff -a
- 永久生效,在“fstab”文件中注释swap自动挂载。
1
sed -i "/\/dev\/mapper\/openeuler-swap/ s|^|#|" /etc/fstab
- 单次生效,执行如下命令。
- 禁用SELinux。
1
sed -i "s|SELINUX=.*|SELINUX=disabled|g" /etc/selinux/config
- 配置安装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
- 安装K8s集群软件。
1 2
yum install -y kubelet kubeadm kubectl kubernetes-cni --disableexcludes=kubernetes systemctl enable --now kubelet
- 请参见(可选)部署Containerd环境的1至3安装Containerd和runc组件。在完成Containerd和runc的组件安装后,工作节点需要额外执行6进行docker服务的重启。
- 修改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
- 配置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
- 配置网络转发。该步骤服务器重启后需重新执行。
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
父主题: 搭建K8s集群