How to add extra hosts entries in helm charts

5/31/2019

So i'm deploying my application stack on kubernetes sing helm charts and now i need to add some dependant server ip's and hostnames inside my pods /etc/hosts file so need help on this scenario

-- Satyashil Deshpande
kubernetes
kubernetes-helm

2 Answers

5/31/2019

As standing in documentation you can add extra hosts to POD by using host aliases feature

Example from docs:

apiVersion: v1
kind: Pod
metadata:
  name: hostaliases-pod
spec:
  restartPolicy: Never
  hostAliases:
  - ip: "127.0.0.1"
    hostnames:
    - "foo.local"
    - "bar.local"
  - ip: "10.1.2.3"
    hostnames:
    - "foo.remote"
    - "bar.remote"
  containers:
  - name: cat-hosts
    image: busybox
    command:
    - cat
    args:
    - "/etc/hosts"
-- Jakub Bujny
Source: StackOverflow

5/31/2019

Kubernetes provides a DNS service that all pods get to use. In turn, you can define an ExternalName service that just defines a DNS record. Once you do that, your pods can talk to that service the same way they'd talk to any other Kubernetes service, and reach whatever server.

You could deploy a set of ExternalName services globally. You could do it in a Helm chart too, if you wanted, something like

apiVersion: v1
kind: Service
metadata:
  name: {{ .Release.Name }}-{{ .Chart.Name }}-foo
spec:
  type: ExternalName
  externalName: {{ .Values.fooHostname }}

The practice I've learned is that you should avoid using /etc/hosts if at all possible.

-- David Maze
Source: StackOverflow