您好,登錄后才能下訂單哦!
測試環境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進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。