主机准备
主机名 | IP 地址 | 主机配置 |
---|
k8s-master | 192.168.88.136 | 4核,4GB内存,40GB硬盘 |
k8s-worker-01 | 192.168.88.137 | 2核,4GB内存,40GB硬盘 |
k8s-worker-02 | 192.168.88.138 | 2核,4GB内存,40GB硬盘 |
环境
以下操作,在所有 4 台主机上均要进行,可以在 1 台主机上操作完后再进行克隆,但注意修改 IP 以及主机名。
禁用 Linux 的 swap 分区
1 2
| sed -ri 's/.*swap.*/#&/' /etc/fstab swapoff -a
|
添加DNS解析
我使用的是内网 DNS 服务器,若需要手动解析可编辑 /etc/hosts
文件,需要保证每台机器都能互相解析。
例如:
1 2 3 4 5
| cat >> /etc/hosts << EOF 192.168.88.136 k8s-master 192.168.88.137 k8s-node-01 192.168.88.138 k8s-node-02 EOF
|
时间同步
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
|
timedatectl status
sudo systemctl enable systemd-timesyncd sudo systemctl start systemd-timesyncd
apt install ntpdate -y
ntpdate ntp1.aliyun.com
|
配置网络
为了让 K8s 能够转发网络流量,需要修改 iptables 的配置。
1 2 3 4 5 6 7 8 9
| 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
sudo sysctl --system
|
设置hostname
1 2 3
| hostnamectl set-hostname k8s-master hostnamectl set-hostname k8s-node-01 hostnamectl set-hostname k8s-node-02
|
关闭 SELinux (Ubuntu跳过,因为没有SELinux)
1 2
| setenforce 0 sed -i --follow-symlinks 's/SELINUX=enforcing/SELINUX=disabled/g' /etc/sysconfig/selinux
|
关闭防火墙(一般默认状态是关闭的)
重启服务器