Kubernetes v1.28.0安装详解
一.环境初始化
要在所有节点执行命令进行配置
1、检查操作系统的版本
此部署环境为CentOS 7.9
[root@CentOS7 ~]# cat /etc/redhat-release
CentOS Linux release 7.9.2009 (Core)
[root@CentOS7 ~]#
2、主机名解析
为了方便集群节点间的互相调用,配置主机名解析
hostnamectl set-hostname k8s-master
hostnamectl set-hostname k8s-noed1
hostnamectl set-hostname k8s-noed2
cat >>/etc/hosts<<-'EOF'
172.16.0.20 k8s-master
172.16.0.21 k8s-node1
172.16.0.22 k8s-node2
EOF
3、时间同步
kubernetes要求集群节点时间必须精确一致,使用chronyd服务从阿里云同步时间
yum install chrony -y
sed -i '3,6 s/^/# /' /etc/chrony.conf
sed -i '/server 3.centos/a\server ntp.aliyun.com iburst' /etc/chrony.conf
systemctl restart chronyd
chronyc sources
4、禁用swap分区
swap分区:虚拟内存分区,它的作用是物理内存使用完,之后将磁盘空间虚拟成内存来使用,启用swap设备会对系统性能产生很大的影响,kubernetes集群要求所有节点禁用swap分区
临时关闭:swapoff -a
永久关闭:sed -i 's/^[^#].*swap/#&/' /etc/fstab
5、关闭selinux
selinux是linux系统下的一个安全服务,一般选择直接关闭
临时关闭:setenforce 0
永久关闭:sed -i 's/^SELINUX=enforcing$/SELINUX=disabled/' /etc/selinux/config
#: s替换
#: ^开头匹配
#: [^#]:匹配非#
#: #&:中的&代表匹配整行,整个意思就是行前面加上#号
#: g:全部(只匹配特定行不加)
6、禁用iptable和firewalld服务
kubernetes集群在运行的中会产生大量的iptables规则,为了不和系统规则混淆,直接关闭系统的规则
systemctl stop iptables
systemctl disable iptables
systemctl stop firewalld
systemctl disable firewalld
7、修改linux的内核参数
1).修改linux的内核参数,添加网桥过滤和地址转发功能
cat >>/etc/sysctl.d/kubernetes.conf<<-'EOF'
net.bridge.bridge-nf-call-ip6tables = 1
net.bridge.bridge-nf-call-iptables = 1
net.ipv4.ip_forward = 1
EOF
2).重新加载配置
sysctl -p
3). 加载网桥过滤模块
modprobe br_netfilter