Kubernetes 1.21.1集群1M2W 环境搭建
集群说明
操作系统& 内核 | ip | 角色 | kubeadm version | docker version |
---|---|---|---|---|
Centos7 3.10.0-1160.25.1.el7.x86_64 | 192.168.56.186 | Master | 1.21.1 | 20.10.7 |
Centos7 3.10.0-1160.25.1.el7.x86_64 | 192.168.56.187 | worker | 1.21.1 | 20.10.7 |
Centos7 3.10.0-1160.25.1.el7.x86_64 | 192.168.56.188 | worker | 1.21.1 | 20.10.7 |
官方参考
官网
:https://kubernetes.io/zh/docs/setup/production-environment/tools/kubeadm/install-kubeadm/
GitHub
:https://github.com/kubernetes/kubeadm
配置要求
每个节点的检查环节
MAC 地址唯一性
- 你可以使用命令
ip link
或ifconfig -a
来获取网络接口的 MAC 地址
# mac 地址校验
ifconfig -a
product_uuid 的唯一性
- 可以使用
sudo cat /sys/class/dmi/id/product_uuid
命令对 product_uuid 校验
一般来讲,硬件设备会拥有唯一的地址,但是有些虚拟机的地址可能会重复。 Kubernetes 使用这些值来唯一确定集群中的节点。
# product_uuid 校验
sudo cat /sys/class/dmi/id/product_uuid
允许 iptables 检查桥接流量
确保 br_netfilter
模块被加载。这一操作可以通过运行 lsmod | grep br_netfilter
来完成。若要显式加载该模块,可执行 sudo modprobe br_netfilter
。
[root@w2 ~]# lsmod | grep br_netfilter
br_netfilter 22256 0
bridge 151336 1 br_netfilter
为了让你的 Linux 节点上的 iptables 能够正确地查看桥接流量,你需要确保在你的 sysctl
配置中将 net.bridge.bridge-nf-call-iptables
设置为 1
cat <<EOF | sudo tee /etc/modules-load.d/k8s.conf
br_netfilter
EOF
cat <<EOF | sudo tee /etc/sysctl.d/k8s.conf
net.bridge.bridge-nf-call-ip6tables = 1
net.bridge.bridge-nf-call-iptables = 1
EOF
sudo sysctl --system
系统版本统一
内核版本
Docker 要求 CentOS 系统的内核版本高于 3.10
$ uname -r
3.10.0-1160.25.1.el7.x86_64
系统基础前提配置
# 关闭防火墙
systemctl stop firewalld && systemctl disable firewalld
# 关闭selinux
setenforce 0
sed -i 's/^SELINUX=enforcing$/SELINUX=permissive/' /etc/selinux/config
# 关闭swap
swapoff -a
sed -i '/swap/s/^\(.*\)$/#\1/g' /etc/fstab
# 配置iptables的ACCEPT规则
iptables -F && iptables -X && iptables -F -t nat && iptables -X -t nat && iptables -P FORWARD ACCEPT
# 时钟同步
yum install ntpdate -y && ntpdate time.windows.com
网络配置
访问外网
每个节点需要开启NAT网络模式,可访问宿主机的外网环境
配置网卡网段
大家根据自己的情况来准备centos7的虚拟机。
要保证彼此之间能够ping通,也就是处于同一个网络中。
也可以按如下操作: