k3s的運作方法
https://docs.rancher.cn/docs/k3s/quick-start/_index
1 直接安裝
curl -sfL https://rancher-mirror.rancher.cn/k3s/k3s-install.sh | INSTALL_K3S_MIRROR=cn sh -
2 docker 運作
rancher/k3s:v1.19.3-k3s2
本文使用第2種方法
運作k3s
前置條件
rancher/k3s:v1.19.3-k3s2鏡像沒有使用apk,沒有curl bash tcpdump等工具
使用如下的工具準備鏡像需要的檔案
https://gitee.com/wushifeng/devops/blob/master/k8s/k3s-docker/files/build-base.sh
主要内容
1 下載下傳必須的檔案放到約定的目錄
2 使用docker-compose運作k3s
3 将helm shell kube-explorer等内容挂入系統
#!/bin/bash
set -euo pipefail
BaseDir=$(cd "$(dirname "$0")"; pwd)
cd ${BaseDir}
#需要的一些基礎檔案不存在的話進行自動下載下傳
if [ ! -f ./pkg/v1.19.3-k3s2-k3s-airgap-images-amd64.tar ]; then
curl -o ./pkg/v1.19.3-k3s2-k3s-airgap-images-amd64.tar "http://rancher-mirror.cnrancher.com/k3s/v1.19.3-k3s2/k3s-airgap-images-amd64.tar"
curl -o ./pkg/kube-explorer-linux-amd64 "http://rancher-mirror.cnrancher.com/kube-explorer/v0.2.8/kube-explorer-linux-amd64"
curl -o ./pkg/helm-v3.8.1-linux-amd64.tar.gz "http://rancher-mirror.cnrancher.com/helm/v3.8.1/helm-v3.8.1-linux-amd64.tar.gz"
pushd pkg
tar -xzvf helm-v3.8.1-linux-amd64.tar.gz
mv linux-amd64 helm-linux-amd64
popd
docker images|grep "rancher/shell" ||{
docker pull rancher/shell:v0.1.6
}
docker save rancher/shell:v0.1.6 -o ./pkg/rancher-shell.0.1.6.tar
fi
docker ps --format '{{.Names}} {{.Status}}' | grep 'k3s' && {
echo "k3s is run"
exit 1
}
docker ps -a --format '{{.Names}} {{.Status}}' | grep 'k3s' && docker ps -a --format '{{.Names}} {{.Status}}' | grep 'k3s' |grep 'Exited'
if [ "$?" = "0" ]; then
echo "start stopped k3s"
./k3s.sh &> ./pkg/k3s.log &
while [ -z "$(curl -ks https://localhost:6443)" ]; do
echo "wait start"
done
else
#幹淨運作的話,執行這個
./k3s.sh down|| true
echo "start clean k3s"
./k3s.sh &> ./pkg/k3s.log &
while [ -z "$(./k3s.sh status|grep Ready)" ]; do
echo "not started"
sleep 3
done
#
echo "install helm and shell"
./k3s.sh helm
./k3s.sh shell
fi
#kube-explorer使用
echo "run kube-explorer: http://localhost:9898/dashboard/"
./k3s.sh exp
完整檔案參考
https://gitee.com/wushifeng/devops/tree/master/k8s/k3s-docker
正常運作後

可以檢視 http://localhost:9898/dashboard
k3s上安裝kubeapps
k8s的開源應用市場
如上的k3s運作起來後,可以在其上安裝應用。
kubeapps的安裝步驟
1 下載下傳kubeapps的鏡像
https://gitee.com/wushifeng/devops/blob/master/k8s/k3s-docker/kubeapps/offline.sh
2 運作
https://gitee.com/wushifeng/devops/blob/master/k8s/k3s-docker/kapp.sh
如上使用helm安裝和配置了kubeapps
通過導出的端口 http://localhost:8080 通路
添加helm倉庫
helm repo add azure http://mirror.azure.cn/kubernetes/charts/
helm repo add elastic https://helm.elastic.co
此時就可以部署各種服務了,如下圖
https://www.yuque.com/wushifengcn/kb/dph6oc