k3s离线安装-创新互联
测试环境kubernetes的有点臃肿,k3s是不错的选择(主要是由于没有公网、生产环境建议是用kubernetes)
k3s 默认使用的网络是fannel,如果需要其他网络cni的请自行搜索相关文档
部署环境:
系统: ubuntu 16.04
组件: docker-ce18.06 (请提前安装,如果不是docker的,k3s会提供containerd的方式,只是操作没docker方便,这里以docker为示例)
一、下载离线包(放在同一目录)
1.所有的container images
https://github.com/rancher/k3s/releases/download/v1.17.0%2Bk3s.1/k3s-airgap-images-amd64.tar
2.主要的二进制文件k3s
https://github.com/rancher/k3s/releases/download/v1.17.0%2Bk3s.1/k3s
3.下载官方提供的install.sh
https://github.com/rancher/k3s/blob/master/install.sh
二、部署
1.部署master
主要添加跳过镜像下载的参数:
export INSTALL_K3S_SKIP_DOWNLOAD=true
服务端脚本:
#/bin/bash
set -e
sudo cp k3s /usr/local/bin/
#use docker
sudo docker load < k3s-airgap-images-amd64.tar.gz
if [ $(cat install.sh|grep "export INSTALL_K3S_SKIP_DOWNLOAD=true"|wc -l) -eq 0 ];then
sudo sed -i 3i"export INSTALL_K3S_SKIP_DOWNLOAD=true" install.sh
fi
sudo bash install.sh
#use docker
if [ $(cat /etc/systemd/system/k3s.service|grep server|grep docker|wc -l) -eq 0 ];then
sudo sed -i 's?server?server --docker?g' /etc/systemd/system/k3s.service
fi
sudo systemctl daemon-reload
sudo systemctl restart k3s
bash create-client.sh docker
2.生成agent脚本,添加token到服务的文件中
模板脚本client-tmp-docker.sh:
#!/bin/bash
set -e
cp -f k3s /usr/local/bin/
K3S_TOKEN="TOKENK3S-SERVER"
cat >k3s-agent.service<
生成client.sh的脚本create-client.sh
#!/bin/bash
set -e
K3S_TOKEN=$(sudo cat /var/lib/rancher/k3s/server/node-token)
if [ "$1" != "docker" ];then
cat client-tmp-containerd > client-k3s.sh
sed -i "s?TOKENK3S-SERVER?$K3S_TOKEN?g" client-k3s.sh
sed -i "s?SEVERKESIP?$(hostname -i)?g" client-k3s.sh
else
cat client-tmp-docker > client-k3s.sh
sed -i "s?TOKENK3S-SERVER?$K3S_TOKEN?g" client-k3s.sh
sed -i "s?SEVERKESIP?$(hostname -i)?g" client-k3s.sh
fi
3.部署agent
复制client.sh、k3s、k3s-airgap-images-amd64.tar、install.sh到需要部署agent的主机上,一定要放在同一目录下
执行cd /path && bash client.sh
完成后验证:
如果需要更多个性话的,请参考https://rancher.com/docs/k3s/latest/en/
当前题目:k3s离线安装-创新互联
路径分享:http://ybzwz.com/article/dhsjcc.html