<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>

<p>For the main question you got an error while configMapKeyRef is expecting key - value parameters instead of the array provide by configmap.</p>

<p><strong>1.</strong> You can try:</p>

<pre><code>deployment.yaml
...
 hostAliases:
{{ toYaml .Values.hosts | indent 4 }}  

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

<p>Note - hostAliases:</p>

<blockquote>
  <p>Because of the managed-nature of the file, any user-written content will be overwritten whenever the hosts file is remounted by Kubelet in the event of a container restart or a Pod reschedule. Thus, <strong>it is not suggested to modify the contents of the file</strong>.</p>
</blockquote>

<p>Please refer to <a href="https://kubernetes.io/docs/concepts/services-networking/add-entries-to-pod-etc-hosts-with-host-aliases/" rel="nofollow noreferrer">HostAliases</a></p>

<p>In addition those addressees will be used only from the POD level. </p>

<p><strong>2.</strong> It's not clear what you are trying to do.</p>

<p>Take a look at <strong><a href="https://kubernetes.io/docs/concepts/services-networking/service/#external-ips" rel="nofollow noreferrer">external IPs</a></strong> it should be done at service level.</p>

<blockquote>
  <p>If there are external IPs that route to one or more cluster nodes, Kubernetes Services can be exposed on those externalIPs. Traffic that ingresses into the cluster with the external IP (as destination IP), on the Service port, will be routed to one of the Service endpoints. externalIPs are not managed by Kubernetes and are the responsibility of the cluster administrator.</p>
</blockquote>

<p>hope this help</p>
