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:
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"