测试环境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<<EOF
[Unit]
Description=Lightweight Kubernetes
Documentation=https://k3s.io
Wants=network-online.target
[Install]
WantedBy=multi-user.target
[Service]
Type=notify
EnvironmentFile=/etc/systemd/system/k3s.service.env
KillMode=process
Delegate=yes
LimitNOFILE=infinity
LimitNPROC=infinity
LimitCORE=infinity
TasksMax=infinity
TimeoutStartSec=0
Restart=always
RestartSec=5s
ExecStartPre=-/sbin/modprobe br_netfilter
ExecStartPre=-/sbin/modprobe overlay
ExecStart=/usr/local/bin/k3s \
agent --server https://SEVERKESIP:6443 --token "${K3S_TOKEN}" --docker\
EOF
sudo bash install.sh agent
if [ ! -f /etc/systemd/system/k3s.service.env ];then
touch /etc/systemd/system/k3s.service.env
fi
sudo docker load < k3s-airgap-images-amd64.tar.gz
sudo cp -f k3s-agent.service /etc/systemd/system/
sudo systemctl daemon-reload
sudo systemctl restart k3s-agent.service
sudo systemctl enable 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/
免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。