Add Entries to a Pod's /etc/hosts with HostAliases
Add entries to a pod's /etc/hosts file with hostAliases in the deployment YAML.
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:
apiVersion : apps/v1kind: Deploymentmetadata: name: "backend-cluster"spec: replicas: 1 selector: matchLabels: app: "backend" template: metadata: labels: app: "backend" spec: containers: - name: "backend" image: "exampleregistry.gcr.io/backend" ports: - containerPort: 80 hostAliases: - hostnames: - "www.example.com" ip: "10.0.2.4"The important part is hostAliases:
... hostAliases: - hostnames: - "www.example.com" ip: "10.0.2.4"