1、Kubeadm环境准备
1.、k8s各节点组件说明
1.1、master节点
# 主机硬件配置要求最低双核以上
kube-apiserver kube-controller-manager kube-scheduler docker etcd
1.2、node节点
kube-proxy
kubelet
docker
2、主机规划
# 所有主机都配置
cat >> /etc/hosts <<'EOF'
192.168.10.26 master1.k8test.com master1
192.168.10.27 master2.k8test.com master2
192.168.10.28 master3.k8test.com master3
192.168.10.29 node1.k8test.com node1
192.168.10.30 node2.k8test.com node2
192.168.10.31 ha1.k8test.com ha1
192.168.10.32 ha2.k8test.com ha2
192.168.10.33 register.k8test.com register
EOF
3、同步服务的时间
yum install ntpdate -y
timedatectl set-timezone Asia/Shanghai
cat >> /var/spool/cron/root <<'EOF'
*/1 * * * * /sbin/ntpdate ntp5.aliyun.com &>/dev/null
EOF
4、跨主机免密码认证
4.1、需求
需求:我们将 192.168.10.26 master1主机作为源文件所在主机,与其他主机处于免密码的方式来进行认证。
4.2、master生成秘钥和公钥
# 安装自动确认的软件
[root@master1 ~]# yum install expect -y
# 生成秘钥和公钥
[root@master1 ~]# ssh-keygen -t rsa -P "" -f /root/.ssh/id_rsa
4.3、使用IP地址分发
[root@master1 script]# cat no_password.sh
#!/bin/bash
# IP Address
for i in 192.168.10.{27..33}
do
expect -c "
spawn ssh-copy-id -i /root/.ssh/id_rsa.pub root@${i}
expect {
\"*yes/no*\" {send \"yes\r\"; exp_continue}
\"*password*\" {send \"root1234\r\"; exp_continue}
\"*Password*\" {send \"root1234\r\";}
}"
done
4.4、使用主机名分发
[root@master1 script]# cat no_password.sh
#!/bin/bash
# hostname
for i in master{1..3} node{1..2} ha{1..2} register
do
expect -c "
spawn ssh-copy-id -i /root/.ssh/id_rsa.pub root@${i}
expect {
\"*yes/no*\" {send \"yes\r\"; exp_continue}
\"*password*\" {send \"root1234\r\"; exp_continue}
\"*Password*\" {send \"root1234\r\";}
}"
done
5、禁用swap
5.1、所有主机禁用swap
swapoff -a
sed -i 's/.*swap.*/#&/' /etc/fstab # &代表前面匹配的整行内容
# 内核(禁用swap)参数
cat >> /etc/sysctl.d/k8s.conf << EOF
vm.swappiness=0
EOF
sysctl -p /etc/sysctl.d/k8s.conf
6、安装前参数配置
cat >> /etc/sysctl.d/k8s.conf << EOF
net.bridge.bridge-nf-call-ip6tables = 1
net.bridge.bridge-nf-call-iptables = 1
net.ipv4.ip_forward = 1
EOF
# 加载模块
cat <<EOF | sudo tee /etc/modules-load.d/k8s.conf
overlay
br_netfilter
EOF
# 配置生效
modprobe br_netfilter
modprobe overlay
sysctl -p /etc/sysctl.d/k8s.conf
7、修改系统字符集为中文【非必要】
# 修改系统字符集为中文UTF-8 localedef -c -f UTF-8 -i zh_CN zh_CN.UTF-8 export LC_ALL=zh_CN.UTF-8 # 修改字符集配置文件 echo 'LANG="zh_CN.UTF-8"' >/etc/locale.conf