安装环境
系统:centos 7.9
集群:
10.0.11.11 centos001
10.0.11.12 centos002
10.0.11.13 centos003
其中centos001作为master。
如果是克隆出来的虚拟机,可能存在worker的主机名和master一样而无法加入的问题,解决方法是修改主机名,比如对于centos002:
$ hostnamectl set-hostname centos002
# 验证结果:
$ hostname
centos002
$ hostnamectl
Static hostname: centos002
Icon name: computer-vm
Chassis: vm
Machine ID: fda972291bd24829b839fe4b9d276761
Boot ID: c3ee12b5cc6b4ae6ad8fb1173ef9d138
Virtualization: microsoft
Operating System: CentOS Linux 7 (Core)
CPE OS Name: cpe:/o:centos:centos:7
Kernel: Linux 3.10.0-1160.el7.x86_64
Architecture: x86-64
分别修改三台主机名为centos001、002、003。
然后更改hosts文件,添加下面三行:
$ vim /etc/hosts
10.0.11.11 centos001
10.0.11.12 centos002
10.0.11.13 centos003
服务环境准备
为了k8s集群能正常运行,需要完成四项准备工作:
- 关闭防火墙
- 禁用SeLinux
- 关闭Swap
- 修改k8s.conf
三台服务器上需各自执行以下操作:
#!/bin/bash
#关闭防火墙,禁用防火墙开机自启动
systemctl stop firewalld
systemctl disable firewalld
# 临时禁用SeLinux,重启失效
setenforce 0
# 修改SeLinux配置,永久禁用
sed -i 's/^SELINUX=.*/SELINUX=disabled/' /etc/selinux/config
# 临时关闭Swap
swapoff -a
# 修改 /etc/fstab 删除或者注释掉swap的挂载,可永久关闭swap
sed -i '/swap/s/^/#/' /etc/fstab
#修改k8s.conf
cat <<EOF > /etc/sysctl.d/k8s.conf
net.bridge.bridge-nf-call-ip6tables = 1
net.bridge.bridge-nf-call-iptables = 1
EOF
sysctl --system
安装docker
sudo yum remove docker \
docker-client \
docker-client-latest \
docker-common \
docker-latest \
docker-latest-logrotate \
docker-logrotate \
docker-engine
su