To add custom entries in the /etc/hosts
file of pods, you can utilize the hostAliases
field in the deployment configuration. This field allows you to define a list of custom hostname and IP address mappings.
Here’s an example of how you can add a custom entry using the oc
command-line tool:
$ oc get deployment httpd1 -o yaml | grep -A4 -B14 hostAliases
spec:
containers:
- image: image-registry.openshift-image-registry.svc:5000/iamgini-dev/httpd1@sha256:b58b0719265d8b1a5beacfb42f4f2e946905c1ba4069c9949834edf97db3ace2
imagePullPolicy: Always
name: httpd1
ports:
- containerPort: 8080
protocol: TCP
- containerPort: 8443
protocol: TCP
resources: {}
terminationMessagePath: /dev/termination-log
terminationMessagePolicy: File
dnsPolicy: ClusterFirst
hostAliases:
- hostnames:
- myadded.example.com
ip: 192.168.1.1
restartPolicy: Always
https://www.techbeatly.com/adding-custom-entries-in-etc-hosts-file-in-kubernetes-and-openshift-containers/