文档

自定义设置ECI Pod的hosts

更新时间:

某些场景下,您可能需要自定义设置ECI Pod的hosts,例如拉取自建镜像仓库的镜像时,需要通过hosts明确镜像仓库的实际IP地址。本文介绍如何自定义设置ECI Pod级别的hosts(即/etc/hosts)。

配置说明

您可以通过k8s.aliyun.com/eci-custom-hosts的Annotation自定义设置ECI Pod的hosts,支持传入多组IP和域名的映射关系,单组格式为{\"host\":\"example.com\",\"ip\":\"100.100.XX.XX\"}

重要
  • Annotation请添加在Pod的metadata下,例如:创建Deployment时,Annotation需添加在spec>template>metadata下。

  • 仅支持在创建ECI Pod时添加ECI相关Annotation来生效ECI功能,更新ECI Pod时添加或者修改ECI相关Annotation均不会生效。

配置示例

例如拉取自建镜像仓库的镜像时,需要通过hosts明确镜像仓库的实际IP地址时,可参考以下YAML示例。

apiVersion: apps/v1
kind: Deployment
metadata:
  name: test
  labels:
    app: test
spec:
  replicas: 1
  selector:
    matchLabels:
      app: test
  template:
    metadata:
      name: test
      labels:
        app: test
        alibabacloud.com/eci: "true" 
      annotations:
        k8s.aliyun.com/eci-custom-hosts: "[{\"host\":\"example.com\",\"ip\":\"100.100.XX.XX\"},{\"host\":\"aliyundoc.com\",\"ip\":\"100.100.XX.XX\"}]"
    spec:
      containers:
      - name: nginx
        image: example.com/test/nginx:latest
        ports:
        - containerPort: 80
      - name: busybox
        image: aliyundoc.com/test/busybox:1.30
        command: ["sleep"]
        args: ["999999"]

  • 本页导读 (1)
文档反馈