镜像下载、域名解析、时间同步请点击 阿里云开源镜像站
请注意k8s在1.24版本不支持docker容器,本文使用kubeadm进行搭建
file
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 EOF
1.6 修改hosts文件 方便查看域名映射
[root@hhdcloudrd7 /]# cat /etc/hosts 127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4 ::1 localhost localhost.localdomain localhost6 localhost6.localdomain6 192.168.34.7 k8s-master 192.168.5.129 k8s-node1 192.168.34.8 k8s-node2
1.7 查看系统版本信息 修改hostname
[root@localhost /]# hostnamectl Static hostname: localhost.localdomain Icon name: computer-vm Chassis: vm Machine ID: 5c2c4826a7cd442a85c37d3b4dba39e0 Boot ID: 3f70bab69c37412da8eada29d50cc12c Virtualization: vmware Operating System: CentOS Linux 7 (Core) CPE OS Name: cpe:/o:centos:centos:7 Kernel: Linux 3.10.0-1160.el7.x86_64 Architecture: x86-64
hostnamectl set-hostname k8s-node1 su root
1.8 查看cpu信息 k8s安装至少需要2核2G的环境,否则会安装失败
lscpu