服务器环境与要求:
三台服务器
k8s-master01 192.168.26.130 操作系统: Ubuntu20.04
k8s-woker01 192.168.26.140 操作系统: Ubuntu20.04
k8s-woker02 192.168.26.150 操作系统: Ubuntu20.04
最低配置:2核 2G内存 20G硬盘
1、环境准备:(所有服务器都需要操作)
1、时间同步
timedatectl set-timezone Asia/Shanghai
sudo apt install ntpdate
sudo ntpdate ntp.ubuntu.com
2、固定IP
Ubuntu系统设置静态固定IP保姆级教程_ubuntu 设置固定ip-优快云博客
可按照本人上面的文档来操作
3、修改主机名
sudo hostnamectl set-hostname k8s-master
sudo reboot
4、 关闭swap分区
就是说ha-1和ha-2不需要安装
临时禁用:
sudo swapoff /swapfile
永久禁用:
vim /etc/fstab 打开文件按照下图注释一行。
使用
free -m
命令来查看确认交换分区已经被禁用
5、关闭防火墙
sudo systemctl disable --now ufw
6、修改改为国内镜像源地址
备份配置文件
sudo cp -a /etc/apt/sources.list /etc/apt/sources.list.bak
修改镜像源为华为云镜像
sudo sed -i "s@http://.*archive.ubuntu.com@http://repo.huaweicloud.com@g" /etc/apt/sources.list
sudo sed -i "s@http://.*security.ubuntu.com@http://repo.huaweicloud.com@g" /etc/apt/sources.list
7、主机名与IP地址解析配置
cat >> /etc/hosts << EOF
192.168.26.130 k8s-master01
192.168.26.140 k8s-worker01
192.168.26.150 k8s-worker02
EOF
配置内核转发及网桥过滤:
cat > /etc/modules-load.d/k8s.conf << EOF
overlay
br_netfilter
EOF
加载配置:
modprobe overlay
modprobe br_netfilter
查看是否加载:
lsmod |grep overlay
lsmod |grep br_netfilter
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
让配置生效:
sysctl -p /etc/sysctl.d/k8s.conf