镜像下载、域名解析、时间同步请点击 阿里云开源镜像站
请注意k8s在1.24版本不支持docker容器,本文使用kubeadm进行搭建
1.查看系统版本信息以及修改配置信息
1.1 安装k8s时,临时关闭swap ,如果不关闭在执行kubeadm部分命令会报错
swapoff -a
或直接注释swap(需要重启生效)
[root@hhdcloudrd7 /]# cat /etc/fstab
#
# /etc/fstab
# Created by anaconda on Tue Apr 19 11:43:17 2022
#
# Accessible filesystems, by reference, are maintained under '/dev/disk'
# See man pages fstab(5), findfs(8), mount(8) and/or blkid(8) for more info
#
/dev/mapper/centos_hhdcloudrd6-root / xfs defaults 0 0
UUID=13a8fe45-33c8-4258-a434-133ce183d3c3 /boot xfs defaults 0 0
#/dev/mapper/centos_hhdcloudrd6-swap swap swap defaults 0 0
1.2 安装k8s时,可以临时关闭selinux,减少额外配置
setenforce 0
或修改 /etc/sysconfig/selinux 文件 后重启
[root@localhost /]# cat /etc/sysconfig/selinux
# This file controls the state of SELinux on the system.
# SELINUX= can take one of these three values:
# enforcing - SELinux security policy is enforced.
# permissive - SELinux prints warnings instead of enforcing.
# disabled - No SELinux policy is loaded.
SELINUX=disabled
# SELINUXTYPE= can take one of three values:
# targeted - Targeted processes are protected,
# minimum - Modification of targeted policy. Only selected processes are protected.
# mls - Multi Level Security protection.
SELINUXTYPE=targeted
1.3 关闭防火墙
systemctl stop firewalld
systemctl disable firewalld
1.4 启用 bridge-nf-call-iptables 预防网络问题
echo 1 > /proc/sys/net/bridge/bridge-nf-call-iptables
1.5 设置网桥参数
cat << EOF > /etc/sysctl.d/k8s.conf
net.bridge.bridge-nf-call-ip6tables = 1
net.bridge.bridge-nf-call-iptables = 1
net.ipv4.ip_forward = 1