k3s离线部署
前置条件
部署k3需要提前部署好docker环境
离线安装
离线包下载地址
https://github.com/k3s-io/k3s/releases/tag/v1.25.3+k3s1
- 下载:
- k3s:程序包
-
k3s-airgap-images-amd64.tar.gz:离线镜像包
部署步骤
程序包
# server
[root@k3s-server k3s-server]#chmod a+x k3s
[root@k3s-server k3s-server]#cp k3s /usr/bin
# agent
[root@k3s-agent-01 k3s-agent]#chmod a+x k3s
[root@k3s-agent-01 k3s-agent]#cp k3s /usr/bin
镜像导入
[root@k3s-server k3s-server]#tar -xvf k3s-airgap-images-amd64.tar.gz
[root@k3s-server k3s-server]#docker load -i k3s-airgap-images-amd64.tar
k3s Server启动
#!/bin/bash
nohup k3s server --docker >> ./k3s_server.out 2>&1 & #--docker 使用docker
PID=$!
echo $PID> pid
echo "k3s server [$PID] is running."
[root@k3s-server k3s-server]#k3s kubectl get nodes
NAME STATUS ROLES AGE VERSION
k3s-server.vm Ready control-plane,master 3d v1.25.3+k3s1
k3s Agent加入
#获取token
[root@k3s-server k3s-server]# cat /var/lib/rancher/k3s/server/node-token
#!/bin/bash
NODE_TOKEN=K1022e4b1ac405c47b7a76c295f0ab8c3e8609a222b2bfe24eaa0aa8e2d591b2a90::server:547d3343e2dbe937213b16715015f556
nohup k3s agent --server https://192.168.86.181:6443 --token ${NODE_TOKEN} >> ./k3s_agent.out 2>&1 &
PID=$!
echo $PID> pid
echo "k3s agent is running"
[root@k3s-server k3s-server]# k3s kubectl get nodes
NAME STATUS ROLES AGE VERSION
k3s-server.vm Ready control-plane,master 3d v1.25.3+k3s1
k3s-agent-01.vm Ready <none> 37m v1.25.3+k3s1
关闭服务脚本
#!/bin/bash
for line in `cat pid`
do
PID=$line
done
echo "Stop k3s [${PID}]..."
rm -rf pid
kill -9 $PID