Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to add extra hosts entries in helm charts

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

like image 651
Satyashil Deshpande Avatar asked Dec 31 '22 22:12

Satyashil Deshpande


2 Answers

A helm templated solution to the original question. I tested this with helm 3.

apiVersion: apps/v1
kind: Deployment
spec:
  template:
    spec:
    {{- with .Values.hostAliases }}
      hostAliases:
{{ toYaml . | indent 8 }}
    {{- end }}

For values such as:

hostAliases:
  - ip: "10.0.0.1"
    hostnames:
    - "host.domain.com"

If the hostAliases is omitted or commented out in the values, the hostAliases section is omitted when the template is rendered.

like image 54
Christian Avatar answered Jan 04 '23 02:01

Christian


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"
like image 24
Jakub Bujny Avatar answered Jan 04 '23 00:01

Jakub Bujny