<p>I would like to know if there is any way to externalize my hostaliases in order to read from values file to vary by environment.</p>

<p><code>
deployment.yaml
   ...
      hostAliases:
        valueFrom:
          configMapKeyRef:
            name: host-aliases-configuration
            key: hostaliases  </p>

<p>configmap.yaml
kind: ConfigMap
metadata:
  name: host-aliases-configuration
data:
  hostaliases: |
    {{ .Values.hosts }}</p>

<p>values.yaml
hosts:
  - ip: "13.21.219.253"
    hostnames:
      - "test-test.com"
  - ip: "13.71.225.255"
    hostnames:
      - "test-test.net"
</code></p>

<p>This doest work:</p>

<p>helm install --name gateway .</p>

<p>Error: release gateway failed: Deployment in version "v1" cannot be handled as a Deployment: v1.Deployment.Spec: v1.DeploymentSpec.Template: v1.PodTemplateSpec.Spec: v1.PodSpec.HostAliases: []v1.HostAlias: decode slice: expect [ or n, but found {, error found in #10 byte of ...|Aliases":{"valueFrom|..., bigger context ...|config","name":"config-volume"}]}],"hostAliases":{"valueFrom":{"configMapKeyRef":{"key":"hostaliases|...</p>

<p>I would like to know if there is any way to externalize this urls by env, using another approach maybe.</p>

Bruno Macedo
<p>I had the same problem.</p>

<p>the solution I finally came up with was to create an <code>external-hosts</code> chart which will include all my external IPs references, (abstracted as clusterIP services), and include that chart in the <code>requirements.yaml</code> of every chart</p>

<p><code>requirements.yaml</code> of every chart:</p>

<pre><code>dependencies:

- name: external-hosts
  version: "0.1.*"
  repository: "file://../external-hosts"
</code></pre>

<p><strong>the <code>external-hosts</code> chart</strong> itself contained:</p>

<p><code>values.yaml</code>: a list of hosts + the needed ports:</p>

<pre><code>headless:
- host: test-test.com
  ip: "13.21.219.253"
  ports:
  - 80
  - 443
- host: test-test.net
  ip: "13.71.225.255"
  ports:
  - 3306
</code></pre>

<p><code>templates/headless.yaml</code>- this one create for each host a clusterIP service with a single endpoint. a little overwhelming but it just works.</p>

<pre><code>{{ range .Values.headless }}
---
kind: Service
apiVersion: v1
metadata:
 name: {{ .host }}
 labels:
{{ include "external-hosts.labels" $ | indent 4 }}
spec:
 ports:
 {{ range .ports }}
 - name: {{ . | quote }}
   port: {{ . }}
   targetPort: {{ . }}
{{ end }}
{{ end }}
---

{{ range .Values.headless }}
---
kind: Endpoints
apiVersion: v1
metadata:
 name: {{ .host }}
 labels:
{{ include "external-hosts.labels" $ | indent 4 }}
subsets:
 - addresses:
     - ip: {{ .ip }}
   ports:
   {{ range .ports }}
     - name: {{ . | quote}}
       port: {{ . }}
  {{ end }}
  {{ end }}
</code></pre>
