測試環(huán)境kubernetes的有點臃腫,k3s是不錯的選擇(主要是由于沒有公網(wǎng)、生產(chǎn)環(huán)境建議是用kubernetes)
k3s 默認(rèn)使用的網(wǎng)絡(luò)是fannel,如果需要其他網(wǎng)絡(luò)cni的請自行搜索相關(guān)文檔
部署環(huán)境:
系統(tǒng): ubuntu 16.04
組件: docker-ce18.06 (請?zhí)崆鞍惭b,如果不是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
主要添加跳過鏡像下載的參數(shù):
export INSTALL_K3S_SKIP_DOWNLOAD=true
服務(wù)端腳本:
#/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到服務(wù)的文件中
模板腳本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
復(fù)制client.sh、k3s、k3s-airgap-images-amd64.tar、install.sh到需要部署agent的主機上,一定要放在同一目錄下
執(zhí)行cd /path && bash client.sh
完成后驗證:
如果需要更多個性話的,請參考https://rancher.com/docs/k3s/latest/en/