目录
1、文件准备
2、安装master节点
3、安装agent节点
4、查看详情信息
5、遇到问题
1、文件准备
- 安装docker
yum install -y docker
systemctl status docker
- 增加docker国内镜像源
vi /etc/docker/daemon.json
添加内容为:
{
"registry-mirrors":["https://hub-mirror.c.163.com","https://registry.aliyuncs.com","https://registry.docker-cn.com","https://docker.mirrors.ustc.edu.cn"]
}
然后执行:
systemctl daemon-reload
systemctl restart docker
- 获取部署k3s文件
文件准备,例如k3s,install.sh。
curl https://raw.githubusercontent.com/rancher/k3s/master/install.sh -o install.sh
wget https://github.com/k3s-io/k3s/releases/download/v1.23.16%2Bk3s1/k3s
2、安装master节点
chmod 777 install.sh k3s
cp k3s /usr/local/bin
INSTALL_K3S_MIRROR=cn INSTALL_K3S_SKIP_DOWNLOAD=true ./install.sh
kubectl get nodes
3、安装agent节点
获取master节点上的token:
cat /var/lib/rancher/k3s/server/node-token
在master和agent节点上都需要关闭防火墙:
systemctl stop firewalld.service
chmod 777 install.sh k3s
cp k3s /usr/local/bin
INSTALL_K3S_MIRROR=cn K3S_URL=https://197.168.11.31:6443 K3S_TOKEN=K10782535704e853507bd8d210a9710456a621e3d6784cb95979b2f43b7364b089e::server:6a3761aeb2b4ca6011adf204d5f0a735 INSTALL_K3S_SKIP_DOWNLOAD=true ./install.sh
4、查看详情信息
kubectl get nodes -o wide
5、遇到问题
- 自Kubernetes1.24以后,K8S就不再原生支持docker。
配置INSTALL_K3S_EXEC="--docker"不在支持。
- failed to pull image "rancher/mirrored-pause:3.6"...。(k3s通过containerd容器部署)
如果在master节点出现上述问题,解决方案:
cat >> /etc/rancher/k3s/registries.yaml <<EOF
mirrors:
"docker.io":
endpoint:
- "https://registry.cn-hangzhou.aliyuncs.com"
- "https://ustc-edu-cn.mirror.aliyuncs.com"
EOF
systemctl restart k3s
如果在agent节点上出现上述问题,解决方案:
cd /etc/rancher/
mkdir k3s
cd
cat >> /etc/rancher/k3s/registries.yaml <<EOF
mirrors:
"docker.io":
endpoint:
- "https://registry.cn-hangzhou.aliyuncs.com"
- "https://ustc-edu-cn.mirror.aliyuncs.com"
EOF
systemctl restart k3s-agent