生產執行環境推薦
- k8s版本1.29、Istio1.21、knative1.13.1
- 單節點k8s:最少6C6G,30g儲存
- 多節點k8s:每節點最少2c4g,20g儲存
注意:部署中所屬檔案都將分別放置於kubeedge和kserver資料夾之中
1)安裝istio
方法1
istioctl install -y
方法2
mkdir -p kserver
cd !$
#映象名替換指令碼,需要將文件中的rep-docker-img.sh 放入資料夾中
../kserver/rep-docker-img.sh 指令碼檔案
------------------------------------------------------------------------------------------------------------------------
RED='\E[31;2m'
GREEN='\E[32;1m'
BLUE='\E[34;1m'
END='\E[0m'
#touch img.txt
img_list=(
gcr.io
k8s.gcr.io
registry.k8s.io
ghcr.io
docker.io
quay.io
)
find_args=''
relabel_reg='m.daocloud.io'
#入口,列印幫助、判斷給定引數是否存在
main(){
if [[ $1 = "" ]]; then
echo -e "${BLUE}[info]${END} 未指定路徑,使用預設路徑: ./"
rep_img
elif [ $1 = '-h' ]; then
echo -e "${BLUE} 搜尋替換國外容器映象地址為國內代理名稱"
echo -e " 使用方法: $0 目錄/檔案 ${END}"
else
test -d $1 || test -f $1 && rep_img $1 || { echo -e "${RED}[err]${END} 給定的目錄/檔案不存在: ${1} " && return 1; }
fi
}
#記錄日誌
log(){
echo -e "${BLUE}[info]${END} $1 映象替換完成: $2 "
echo -e "${BLUE}[info `date +'%F %T'`]${END} $1 映象替換完成: $2 " >> rep_img.log
}
run(){
filter_files="$*"
#從源映象列表迴圈判斷
for img_name in ${img_list[*]} ;do
#取出所有要替換的檔名
files=`egrep -H "[[:space:]]image: +[[:graph:]]+" $filter_files |grep $img_name |grep -v "$relabel_reg" |awk -F':' '{print $1}' |sort |uniq |tr -d '"' |tr -d "'"`
#取出所有要替換的映象名
old_img_name=`egrep "[[:space:]]image: +[[:graph:]]+" $filter_files |grep $img_name |grep -v "$relabel_reg" |awk '{print $NF}' |sort |uniq |tr -d '"' |tr -d "'"`
for img in ${old_img_name[*]} ;do
for file in ${files[*]} ;do
grep -sq $img $file
if [ $? = 0 ] ;then
sed -ri "s#($img)#$relabel_reg/\1#" $file
log $img $file
fi
done
done
done
}
#替換映象名
rep_img(){
#傳參判斷
if [[ $1 = "" ]]; then
filter_files=`find -iname '*.yaml' ! -type l ! -type d -o -iname '*.yml' ! -type l ! -type d`
run $filter_files
elif [ -f $1 ]; then
run $1
elif [ -d $1 ]; then
filter_files=`find $1 -iname "*.yaml" ! -type l ! -type d -o -iname "*.yml" ! -type l ! -type d`
run $filter_files
fi
}
main $1
-----------------------------------------------------------------------------------------------------------------------------
獲取istio
wget https://github.com/knative/net-istio/releases/download/knative-v1.13.1/istio.yaml
wget -o istio-2.yaml https://github.com/knative/net-istio/releases/download/knative-v1.13.1/istio.yaml
#替換映象名
sh rep-docker-img.sh
kubectl apply -l knative.dev/crd-install=true -f istio.yaml
kubectl apply -f istio-2.yaml
2)安裝Knative-serving
#映象名替換指令碼,由於kantive需要從谷歌下載映象,需要將文件中的rep-docker-img.sh 放入資料夾中
../kserver/rep-docker-img.sh
wget https://github.com/knative/serving/releases/download/knative-v1.13.1/serving-crds.yaml
wget https://github.com/knative/serving/releases/download/knative-v1.13.1/serving-core.yaml
#替換映象名
sh rep-docker-img.sh
#可選操作。注入sidecar envoy,注入後可以刪除istio-system名稱空間下的svc:knative-local-gateway
kubectl create ns knative-serving
kubectl label ns knative-serving istio-injection=enabled
kubectl apply -f serving-crds.yaml
kubectl apply -f serving-core.yaml
3)安裝Knative Istio 控制器
讓knative serving可以呼叫istio的功能
ip link a vip0 type dummy
ip add a 2.2.2.17/32 dev vip0
kubectl patch svc -n istio-system istio-ingressgateway -p '{"spec":{"externalIPs":["2.2.2.17"]}}'
wget https://github.com/knative/net-istio/releases/download/knative-v1.13.1/net-istio.yaml
#替換映象名
sh rep-docker-img.sh
kubectl apply -f net-istio.yaml
4)安裝證書管理器
wget https://github.com/cert-manager/cert-manager/releases/download/v1.16.1/cert-manager.yaml
sh rep-docker-img.sh
kubectl apply -f cert-manager.yaml
5)安裝kserver
wget https://github.com/kserve/kserve/releases/download/v0.13.0/kserve.yaml
sh rep-docker-img.sh
kubectl apply -f kserve.yaml
*** KServe 內建 ClusterServingRuntimes***
wget https://github.com/kserve/kserve/releases/download/v0.13.0/kserve-cluster-resources.yaml
sh rep-docker-img.sh
kubectl apply -f kserve-cluster-resources.yaml
6)部署第一個推理服務
注意:使用 KServe 無伺服器模式,它使用 Knative。
Knative 始終嘗試將影像標籤解析為摘要,這是一項需要訪問登錄檔的操作,需要透過:
kubectl edit configmap -n knative-serving config-deployment ————> index.docker.io新增進去
***執行命令,釋出推理服務***
kubectl creste ns kserver-test
kubectl apply -n kserve-test -f - <<EOF
apiVersion: "serving.kserve.io/v1beta1"
kind: "InferenceService"
metadata:
name: "sklearn-iris"
spec:
predictor:
model:
modelFormat:
name: sklearn
storageUri: "gs://kfserving-examples/models/sklearn/1.0/model"
EOF
成功釋出
7)安裝kubeedge(在master端和edge端進行)
mkdir kubeedge
cd kubeedge
wget https://github.com/kubeedge/kubeedge/releases/download/v1.19.0/keadm-v1.19.0-linux-amd64.tar.gz
tar -zxvf keadm-v1.19.0-linux-amd64.tar.gz
cp keadm-1.19.0-linux-amd64/keadm/keadm /usr/local/bin/keadm
安裝驗證
8)初始化CloudeCore
***在主節點執行,若是有多個CloudCore需要在初始化的時候,繼續追加IP如:192.168.3.17,192.168.3.18***
keadm init --advertise-address=192.168.3.17 --kubeedge-version=v1.19.0 --kube-config=/root/.kube/config
輸出:
Kubernetes version verification passed, KubeEdge installation will start...
CLOUDCORE started
=========CHART DETAILS=======
NAME: cloudcore
LAST DEPLOYED: Wed Oct 26 11:10:04 2022
NAMESPACE: kubeedge
STATUS: deployed
REVISION: 1
獲取token:
keadm gettoken
輸出:
ahbfoildhanfnddokjkhdkf15461adfaoindfolmadjkoinjfco;pajdiop;fjiao;dm;aldmfvoanhgvoiaofvpa
9)加入CloudCore
注意:容器執行時,需要提前配置好,可參照官網 https://kubeedge.io/zh/docs/welcome/getting-started
***加入CloudCore節點,這裡我們使用的容器執行時為docker,方便後期提供登入操作KubeEdge預設使用cgroupfs cgroup驅動,如果你使用systemd cgroup驅動,
你需要保證docker配置了systemd cgroup,在執行keadm join時
加入--cgroupdriver=systemd。***
加入命令:
keadm join --cloudcore-ipport=192.168.3.17:10000 --kubeedge-version=v1.19.0
--remote-runtime-endpoint=unix:///var/run/cri-dockerd.sock --cgroupdriver=systemd --token=
輸出:
...
KubeEdge edgecore is running, For logs visit: journalctl -u edgecore.service -xe
使用 systemctl status edgecore 來檢查edgecore是否正確執行。
# systemctl status edgecore
● edgecore.service
Loaded: loaded (/etc/systemd/system/edgecore.service; enabled; vendor preset: enabled)
Active: active (running) since Wed 2022-10-26 11:26:59 CST; 6s ago
Main PID: 2745865 (edgecore)
Tasks: 13 (limit: 4915)
CGroup: /system.slice/edgecore.service
└─2745865 /usr/local/bin/edgecore
10)邊緣節點部署演示
在您成功啟動CloudCore和EdgeCore以後,使用 kubectl get node
來確保EdgeCore成功註冊到CloudCore。
# kubectl get node
NAME STATUS ROLES AGE VERSION
ecs-8f95 Ready agent,edge 5m45s v1.22.6-kubeedge-v1.12.0
kind-control-plane Ready control-plane,master 13m v1.23.4
現在,我們可以執行下面的命令在邊緣節點釋出一個Pod
cat <<EOF | kubectl apply -f -
apiVersion: v1
kind: Pod
metadata:
name: nginx
spec:
containers:
- name: nginx
image: nginx:1.14.2
ports:
- containerPort: 80
nodeSelector:
"node-role.kubernetes.io/edge": ""
EOF
如下所示,我們的邊緣節點部署Pod就成功完成了:
# kubectl get pod -owide
NAME READY STATUS RESTARTS AGE IP NODE NOMINATED NODE READINESS GATES
nginx 1/1 Running 0 11s 172.17.0.2 ecs-8f95 <none> <none>