在Kubernetes集群中创建ECI类型的Pod(即ECI实例)时,为充分使用ECI提供的功能,在不改变Kubernetes语义的前提下,您可以根据需求为Pod添加Annotation。 本文为您介绍ECI实例支持的和追加的Annotation及其配置示例。
ECI Pod支持的Annotation
创建ECI Pod时,支持添加的Annotation如下:
以下列举的Annotation仅适用于创建到虚拟节点上的Pod,即ECI实例,调度到普通节点上的Pod不受这些Annotation影响。
Annotation请添加在Pod的metadata下,例如:创建Deployment时,Annotation需添加在spec>template>metadata下。
仅支持在创建ECI Pod时添加ECI相关Annotation来生效ECI功能,更新ECI Pod时添加或者修改ECI相关Annotation均不会生效。
ECI Pod追加的Annotation
ECI Pod调度完成后会追加的Annotation如下表所示。您可以通过kubectl describe
命令进行查询。
参数 | 示例值 | 描述 |
k8s.aliyun.com/eci-request-id | 45942504-4688-51BA-BBAB-4B692C4F39C0 | 请求ID。 |
k8s.aliyun.com/eci-instance-id | eci-2ze1y0la40qgva09**** | ECI实例ID。 |
k8s.aliyun.com/eci-instance-spec | 2.0-4.0Gi | ECI实例规格,即实际计费规格。
|
k8s.aliyun.com/eci-instance-compute-category | economy | ECI实例规格的算力类别。
|
k8s.aliyun.com/allocated-eipInstanceId | eip-bp1q5n8cq4p7f6dzu**** | 绑定的EIP实例ID。 |
k8s.aliyun.com/allocated-eipAddress | 47.99.**.** | 绑定的EIP实例的IP地址。 |
k8s.aliyun.com/allocated-ipv6Address | 2001:d**:1:1:1:1:1:1 | 绑定的IPv6地址。 |
k8s.aliyun.com/eci-created-by-template | true | 是否使用模板创建。 |
k8s.aliyun.com/eni-instance-id | eni-2ze6d7oo5ukqj26o**** | 绑定的网卡ID。 |
k8s.aliyun.com/eci-vpc | vpc-2zeghwzptn5zii0w7**** | 所属VPC。 |
k8s.aliyun.com/eci-matched-image-cache | imc-2zedy3v37800iimu**** | 匹配的镜像缓存ID。 |
k8s.aliyun.com/eci-schedule-result | finished | 调度结果。该Annotation已弃用,请参考podStatus.condition ContainerInstanceCreated了解Pod调度结果。具体请参见ContainerInstanceCreated。 |
设置ECI重调度
调度Pod到虚拟节点时,可能会碰到调度失败的情况,您可以通过添加Annotation的方式为Pod开启重调度,即使异步调度失败了,仍会一直保持调度,不返回失败。
配置示例如下:
apiVersion: apps/v1
kind: Deployment
metadata:
name: set-eci
labels:
app: vk
spec:
replicas: 1
selector:
matchLabels:
app: nginx
template:
metadata:
annotations:
k8s.aliyun.com/eci-reschedule-enable: "true" # 开启ECI重调度。
labels:
app: nginx
spec:
containers:
- name: nginx
image: nginx:latest
nodeName: virtual-kubelet
Pod创建失败置为Failed
默认情况下,每个Pod在创建时,如果遇到错误,会重试一定次数,如果还是Failed,则Pod会处于Pending状态。对于一些Job类型的任务,您可能希望直接体现Failed状态。此时,您可以通过添加Annotation的方式,设置Pod遇到创建失败时,体现Failed状态。
配置示例如下:
apiVersion: apps/v1
kind: Deployment
metadata:
name: set-pod-fail-on-create-err
labels:
app: vk
spec:
replicas: 1
selector:
matchLabels:
app: nginx
template:
metadata:
annotations:
k8s.aliyun.com/pod-fail-on-create-err: "true" # 设置Pod创建失败时,状态为Failed。
labels:
app: nginx
spec:
containers:
- name: nginx
image: nginx:latest
nodeName: virtual-kubelet