生产运行环境推荐
- 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>
标签:kubectl,kubeedge,img,AI,istio,yaml,sh,kserver,knative
From: https://www.cnblogs.com/zxlyy/p/18560260