UPDATE: 2017-07-03 Kunbernetes 1.7 now supports adding entries to Pod / etc / hosts with HostAliases .
The solution is not related to kube-dns, but / etc / hosts. Anyway, the next trick seems to work so far ...
EDIT: Changing / etc / hosts may have a race state with the kubernet system. Try again.
1) create configMap
apiVersion: v1 kind: ConfigMap metadata: name: db-hosts data: hosts: | 10.0.0.1 db1 10.0.0.2 db2
2) Add a script called ensure_hosts.sh .
#!/bin/sh while true do grep db1 /etc/hosts > /dev/null || cat /mnt/hosts.append/hosts >> /etc/hosts sleep 5 done
Do not forget chmod a+x ensure_hosts.sh .
3) Add a wrapper script start.sh your image
#!/bin/sh $(dirname "$(realpath "$0")")/ensure_hosts.sh & exec your-app args...
Do not forget chmod a+x start.sh
4) Use configmap as the volume and run start.sh
apiVersion: extensions/v1beta1 kind: Deployment ... spec: template: ... spec: volumes: - name: hosts-volume configMap: name: db-hosts ... containers: command: - ./start.sh ... volumeMounts: - name: hosts-volume mountPath: /mnt/hosts.append ...
source share