开发者社区> 问答> 正文

如何处理virtual-kubelet 支持的 Annotations?

如何处理virtual-kubelet 支持的 Annotations?

展开
收起
小天使爱美 2020-03-20 17:42:54 1222 0
1 条回答
写回答
取消 提交回答
  • 通过virtual-kubelet创建Pod到ECI平台时,为充分利用ECI系统提供的功能,并且不改变kubernetes语义的前提下,我们借助了Annotation的作用,根据需求增加有意义的Annotation,virtual-kubelet做转译,提升与ECI平台的交互。 本文主要介绍virtual-kubelet目前支持的Annotation列表,会定期更新,并且介绍每个Annotation作用和影响。

    说明 下面介绍的注解,仅适用于创建到virtual-kubelet节点上的Pod。 指定ECI规格 增加k8s.aliyun.com/eci-use-specs注解, 创建Pod时允许使用的实例规格列表,遇到没库存时,按照顺序遍历规格列表购买ECI实例,应对库存问题。

    k8s.aliyun.com/eci-use-specs的值,支持列表,使用逗号分隔,列表中元素的格式:

    1.模糊匹配

    ${cpu}-${mem}Gi:例如: 2-4Gi;表示创建一个2核4G的ECI实例。 ecigpu-${gpuTpye}-${gpuCount}:例如: ecigpu-P100-4;ecigpu: 暗示使用GPU规格,P100: 表示GPU类型,4: 表示申请的GPU个数,目前virtual-kubelet支持的gpuType和gpuCount如下表: gputype gpuCount 匹配实例规格 P4 1 ecs.gn5i-c2g1.large P4 2 ecs.gn5i-c16g1.8xlarge P4 4 ecs.gn5i-c28g1.14xlarge V100 1 ecs.gn6v-c8g1.2xlarge V100 4 ecs.gn6v-c8g1.8xlarge V100 8 ecs.gn6v-c8g1.16xlarge P100 1 ecs.gn5-c8g1.2xlarge P100 2 ecs.gn5-c8g1.4xlarge P100 4 ecs.gn5-c8g1.8xlarge P100 8 ecs.gn5-c8g1.14xlarge 2.精确设置:明确指定创建ECI使用的实例规格,例如:ecs.c6.xlarge,ECI支持的实例规格,请参见实例规格族。

    apiVersion: apps/v1beta2 # for versions before 1.8.0 use apps/v1beta1 kind: Deployment metadata: name: vk-cos-use labels: app: cos spec: replicas: 1 selector: matchLabels: app: cos template: metadata: annotations: "k8s.aliyun.com/eci-use-specs": "64-512Gi, 2-4Gi,ecs.c6.xlarge,ecigpu-P100-4" labels: app: cos spec: containers: - name: u1 image: "registry-vpc.cn-beijing.aliyuncs.com/lxx/cos-4g" nodeName: virtual-node-eci-0 ImageCache 创建Pod时,利用镜像缓存技术,加速创建速度。请参见使用镜像缓存 CRD 加速创建 Pod。

    手工指定 创建Deployment时,可以指定已有ImageCacheID,加速Deployment创建。

    apiVersion: apps/v1beta2 # for versions before 1.8.0 use apps/v1beta1 kind: Deployment metadata: name: nginx-with-imagecache spec: replicas: 1 selector: matchLabels: app: nginx template: metadata: annotations: "k8s.aliyun.com/eci-image-snapshot-id": "${your_image_cache_id}" labels: app: nginx spec: containers: - name: nginx image: nginx:1.7.9 imagePullPolicy: IfNotPresent nodeName: virtual-node-eci-0 自动匹配 创建Deployment时,开启自动匹配镜像缓存,在创建过程中,会根据用户已有的镜像缓存,选择最优的镜像缓存,加速Deployment创建。

    apiVersion: apps/v1beta2 # for versions before 1.8.0 use apps/v1beta1 kind: Deployment metadata: name: nginx-dynamic-image-cache labels: app: nginx-dynamic-image-cache spec: replicas: 1 selector: matchLabels: app: nginx template: metadata: annotations: "k8s.aliyun.com/eci-image-cache": "true" labels: app: nginx spec: containers: - name: nginx image: nginx:latest imagePullPolicy: IfNotPresent nodeName: virtual-node-eci-0 弹性公网 IP 通过注解为ECI实例绑定弹性公网IP,赋予ECI实例公网访问能力,弹性公网IP详细信息,请参见什么是弹性公网IP。

    自动创建 创建Deployment时,同时创建弹性公网IP,绑定到ECI实例。

    自动创建的公网IP信息:

    带宽默认为5M,可以通过注解调整。 计费方式为按量计费。 apiVersion: apps/v1beta2 # for versions before 1.8.0 use apps/v1beta1 kind: Deployment metadata: name: cos-vk-resource-group-id labels: app: vk spec: replicas: 1 selector: matchLabels: app: nginx template: metadata: annotations: "k8s.aliyun.com/eci-with-eip": "true" "k8s.aliyun.com/eip-bandwidth": "10" labels: app: nginx spec: containers: - name: nginx image: nginx:latest nodeName: virtual-node-eci-0 手工指定 创建Deployment时,选择已有弹性公网IP,绑定到ECI实例。

    apiVersion: apps/v1beta2 # for versions before 1.8.0 use apps/v1beta1 kind: Deployment metadata: name: cos-vk-resource-group-id labels: app: vk spec: replicas: 1 selector: matchLabels: app: nginx template: metadata: annotations: "k8s.aliyun.com/eci-eip-instanceid": "${your_eip_Instance_Id}" labels: app: nginx spec: containers: - name: nginx image: nginx:latest nodeName: virtual-node-eci-0 设置NTP服务 通过注解为ECI实例设置ntp server,支持设置多个。请参见为 Pod 配置 NTP 服务。

    apiVersion: apps/v1beta2 # for versions before 1.8.0 use apps/v1beta1 kind: Deployment metadata: name: set-ngnix-ntp labels: app: vk spec: replicas: 1 selector: matchLabels: app: nginx template: metadata: annotations: "k8s.aliyun.com/eci-ntp-server": 100.100.5.1,100.100.5.2 # 设置您的NTP服务器地址 labels: app: nginx spec: containers: - name: nginx image: nginx:latest nodeName: virtual-node-eci-0 设置资源组 通过注解为ECI实例设定资源组。

    apiVersion: apps/v1beta2 # for versions before 1.8.0 use apps/v1beta1 kind: Deployment metadata: name: cos-vk-resource-group-id labels: app: vk spec: replicas: 1 selector: matchLabels: app: nginx template: metadata: annotations: "k8s.aliyun.com/eci-resource-group-id" : "${your_resource_group_id}" labels: app: nginx spec: containers: - name: nginx image: nginx:latest nodeName: virtual-node-eci-0 设置RamRole 通过注解为ECI实例设置已有RamRole,赋予在ECI实例内部可以访问阿里云产品能力。

    apiVersion: apps/v1beta2 # for versions before 1.8.0 use apps/v1beta1 kind: Deployment metadata: name: set-ram-role labels: app: vk spec: replicas: 1 selector: matchLabels: app: nginx template: metadata: annotations: "k8s.aliyun.com/eci-ram-role-name" : "${your_ram_role_name}" labels: app: nginx spec: containers: - name: nginx image: nginx:latest nodeName: virtual-node-eci-0 设置虚拟交换机 virtual-kubelet启动时,通过环境变量ECI_VSWITCH设置默认虚机交换机,所有创建在虚拟机节点上的Deployment默认使用virtual-kubelet配置的虚拟交换机创建ECI实例,如果用户希望使用同VPC下其他虚拟交换机创建ECI实例,可以通过注解方式显示指定虚拟交换机。

    apiVersion: apps/v1beta2 # for versions before 1.8.0 use apps/v1beta1 kind: Deployment metadata: name: set-vswitch labels: app: nginx spec: replicas: 1 selector: matchLabels: app: nginx template: metadata: annotations: "k8s.aliyun.com/eci-vswitch" : "${your_vsw_id}" labels: app: nginx spec: containers: - name: nginx image: nginx:latest nodeName: virtual-node-eci-0 设置安全组 virtual-kubelet启动时,通过环境变量ECI_SECURITY_GROUP设置默认安全组,所有创建在虚拟机节点上的Deployment默认使用virtual-kubelet配置的安全组创建ECI实例,如果用户希望使用同VPC下其他安全组创建ECI实例,可以通过注解方式显示指定安全组。

    apiVersion: apps/v1beta2 # for versions before 1.8.0 use apps/v1beta1 kind: Deployment metadata: name: set-security-group labels: app: nginx spec: replicas: 1 selector: matchLabels: app: nginx template: metadata: annotations: "k8s.aliyun.com/eci-security-group" : "${your_security_group_id}" labels: app: nginx spec: containers: - name: nginx image: nginx:latest nodeName: virtual-node-eci-0

    2020-03-20 17:44:05
    赞同 展开评论 打赏
问答地址:
问答排行榜
最热
最新

相关电子书

更多
“移”网打尽-Mobile Network as a Service 网络即服务 立即下载
“移”网打尽—— Mobile Network as a Service 网络即服务 立即下载
Azure Container Service The be 立即下载

相关实验场景

更多