Adding entries to Pod /etc/hosts with HostAliases

Abdul Aziz
Cat Administrator

To add host to /etc/hosts file inside the container, you can define the hosts aliases inside your deployment yaml file.
For example like the following yaml file:
1apiVersion : apps/v12kind: Deployment3metadata:4 name: "backend-cluster"5spec:6 replicas: 17 selector:8 matchLabels:9 app: "backend"10 template:11 metadata:12 labels:13 app: "backend"14 spec:15 containers:16 - name: "backend"17 image: "exampleregistry.gcr.io/backend"18 ports:19 - containerPort: 8020 hostAliases:21 - hostnames:22 - "www.example.com"23 ip: "10.0.2.4"
The important part is hostAliases:
1...2 hostAliases:3 - hostnames:4 - "www.example.com"5 ip: "10.0.2.4"