Customize the hosts file of an ECI pod
In some situations, you may need to customize the pod-level hosts file (that is, /etc/hosts) of an ECI pod. For example, when you pull an image from a self-managed image repository, you need to specify the actual IP address of the image repository in the hosts file.
Configuration notes
Use the k8s.aliyun.com/eci-custom-hosts annotation to customize the hosts file of an ECI pod. The annotation accepts multiple mappings between IP addresses and domain names. The format of a single mapping is {\"host\":\"example.com\",\"ip\":\"100.100.XX.XX\"}.
Annotations must be added to the metadata in the configuration file of the pod. For example, when you create a Deployment, you must add annotations in the spec.template.metadata section.
Elastic Container Instance-related annotations are only applied when a pod is created. Adding or modifying these annotations on an existing pod will have no effect.
Configuration example
To pull images from a self-managed image repository, specify its actual IP address in the hosts file, as shown in the following YAML example:
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"]