1、关闭selinux(每台服务器)
sed -i '/SELINUX/s/enforcing/disabled/' /etc/selinux/config
setenforce 0
2、关闭交换分区(每台服务器)
vim /etc/fstab
找到 swap一行 注释掉
swapoff -a
3、关闭防火墙(每台服务器)
systemctl stop firewalld
systemctl disable firewalld
4、设置三台服务器主机名并修改hosts文件
master上输入
hostnamectl set-hostname k3s-master
cat >> /etc/hosts << EOF
192.168.95.138 k3s-master
192.168.95.139 k3s-slave1
192.168.95.140 k3s-slave2
EOF
主机名立即生效
bash
salve1上输入
hostnamectl set-hostname k3s-slave1
cat >> /etc/hosts << EOF
192.168.95.138 k3s-master
192.168.95.139 k3s-slave1
192.168.95.140 k3s-slave2
EOF
主机名立即生效
bash
salve2上输入
hostnamectl set-hostname k3s-slave2
cat >> /etc/hosts << EOF
192.168.95.138 k3s-master
192.168.95.139 k3s-slave1
192.168.95.140 k3s-slave2
EOF
主机名立即生效
bash
5、时间同步(每台服务器)
yum install ntpdate -y
ntpdate time.windows.com
6、添加源并安装containerd(每台服务器)
yum install -y yum-utils
yum-config-manager --add-repo http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
yum install containerd -y
7、启动服务并设置为开机自启(每台服务器)
systemctl start containerd && systemctl enable containerd
8、安装k3s
先在server上安装
curl -sfL https://rancher-mirror.rancher.cn/k3s/k3s-install.sh | INSTALL_K3S_MIRROR=cn sh -
查看是否安装成功
kubectl get nodes
k3s check-config
卸载server命令
sh /usr/local/bin/k3s-uninstall.sh
9、调整启动参数
vim /etc/default/grub
# 原始值
GRUB_CMDLINE_LINUX="crashkernel=auto rd.lvm.lv=centos/root rd.lvm.lv=centos/swap rhgb quiet"
# 修改后
GRUB_CMDLINE_LINUX="user_namespace.enable=1 crashkernel=auto rd.lvm.lv=centos/root rd.lvm.lv=centos/swap rhgb quiet"
10、部署agent
首先在master上获取token
cat /var/lib/rancher/k3s/server/node-token
得到后复制粘贴下
然后去到slave1和slave2上去下载
curl -sfL https://rancher-mirror.rancher.cn/k3s/k3s-install.sh | INSTALL_K3S_MIRROR=cn K3S_URL=https://k3s-master:6443 K3S_TOKEN=K1013e20e34297fb0021ff6386a4caec078eb41ef1b81aa7ac9ad159dd3b9ee4890::server:6bfc85eb956fe9c8168dd14b291d7f52 sh -
注意:
K3S_URL写master的IP地址
K3S_TOKEN写刚刚在master上获取的token
11、查看节点数量
在master上输入
kubectl get nodes
可以看到
NAME STATUS ROLES AGE VERSION
k3s-master Ready control-plane,master 8m39s v1.27.3+k3s1
k3s-slave1 Ready <none> 102s v1.27.3+k3s1
k3s-slave2 Ready <none> 44s v1.27.3+k3s1
12、卸载agent命令
/usr/local/bin/k3s-agent-uninstall.sh