基于KubeInfer的部署yaml文件说明
基于KubeInfer的部署,关键是定义部署所需的yaml文件,在下一小节可通过脚本生成,其中yaml文件整体结构如下:
kind: KubeInfer
apiVersion: infer.modelarts.huaweicloud/v1
metadata:
labels:
app.modelarts.huaweicloud/instanceGroupId: infer-vllm-2p1d
modelarts-services-type: infer
app.model: deepseek-r1 # 自定义label,可用于同一类型多实例场景下K8s service的label的选择
...
spec:
networkServices:
- name: svc-infer-vllm
spec:
ports:
- nodePort: 30090 # nodePort范围是30000-32767
port: 9000
protocol: TCP
targetPort: 9000
type: NodePort
replicas: 1 # kubeinfer实例instance数
strategy: # 升级策略定义
rollingUpdate:
maxSurge: 20%
maxUnavailable: 20%
type: InstanceRollingUpdate
template:
spec:
roles: # instance下各role的定义,每个role包含的结构一样
...
其中每个role下的定义内容结构如下:
recoveryPolicy:
restart: Instance # 重调度策略
type: Restart
replicas: 1 # role的Pod数
template:
metadata:
labels:
modelarts-infer-npu-reset-enable: "true" # KubeInfer联动DP,故障自动重调度机制
spec:
containers:
- env:
...
image: ${image_name} # Pod依赖的镜像
imagePullPolicy: IfNotPresent
command:
${start_cmd} # Pod启动命令
startupProbe:
exec:
command:
${health_cmd} # 探针健康检查命令
failureThreshold: 720
periodSeconds: 10
livenessProbe:
exec:
command:
${health_cmd} # 探针健康检查命令
periodSeconds: 5
timeoutSeconds: 10
failureThreshold: 6
successThreshold: 1
readinessProbe:
exec:
command:
${health_cmd} # 探针健康检查命令
periodSeconds: 5
timeoutSeconds: 10
failureThreshold: 3
successThreshold: 3
resources:
... # Pod运行所需资源
volumeMounts:
... # Pod内挂载信息
terminationGracePeriodSeconds: 120 # 优雅退出时间
volumes:
... # 外部存储挂载信息
基于KubeInfer部署定义的yaml主要包含下述功能:
- 部署:Pod启动关键是定义使用的镜像、启动命令、运行资源和挂载信息
上述yaml文件定义的是部署推理服务的基础信息,除此之外对于符合K8s标准的操作也可以定义。例如假设您对购买的资源做了分组,且不同分组内的节点打了标签,您希望将实例分组部署,此时您可以在每个role定义的templat.spec下添加亲和性配置。更详细的节点亲和性配置说明参考K8s社区指导:https://kubernetes.io/docs/tasks/configure-pod-container/assign-pods-nodes-using-node-affinity/。样例如下:
template: spec: affinity: nodeAffinity: requiredDuringSchedulingIgnoredDuringExecution: nodeSelectorTerms: - matchExpressions: - key: ${node_label_key} operator: In values: - ${node_label_value} - 升级:Pod升级的关键是定义策略,默认是滚动升级。
- maxSurge:用来指定可以创建的超出期望Pod个数的Pod数量。此值可以是绝对数或所需Pod的百分比。 如果maxUnavailable为0,则此值不能为0。百分比值会通过向上取整转换为绝对数。
- maxUnavailable:用来指定更新过程中不可用的Pod的个数上限。该值可以是绝对数字,也可以是所需Pod的百分比。百分比值会转换成绝对数并去除小数部分。如果maxSurge为0,则此值不能为0。
- 例如:maxSurge=0,maxUnavailable=1,即“先下后上”策略,先删除一个旧实例,然后再启动一个新实例。对于资源紧张的情况下可以使用此种升级策略;maxSurge=1,maxUnavailable=0,即“一上一下”策略,新建一个实例,ready后再删除一个旧实例。
- 故障发现与处理:
- 当前在故障发现上有两种方式:1)KubeInfer+DP,通过yaml中定义modelarts-infer-npu-reset-enable为true自动实时感知硬件故障;2)基于K8s的3大探针(startup、liveness和readiness)来感知Pod的健康状态,默认感知时间30s,健康检查日志默认保存在挂载路径下。更详细的探针配置说明参考K8s社区指导:https://kubernetes.io/docs/tasks/configure-pod-container/configure-liveness-readiness-startup-probes/
- 在故障处置上,KubeInfer支持Instance、Pod和Custom三种级别的恢复策略,默认使用Instance级别,即当故障感知后默认重启整个实例。