<p>I'm trying to 'push' entries into a containers /etc/hosts file by using the 'hostAliases' element of a Pod when defining a Replication Controller.</p>

<p>This is the Replication Controller definition:</p>

<pre><code>{
  "kind": "ReplicationController",
  "apiVersion": "v1",
  "metadata": {
    "name": "my-test",
    "namespace": "default",
    "selfLink": "/api/v1/namespaces/default/replicationcontrollers/my-test",
    "uid": "1f80363b-5a1d-11e8-b352-08002725d524",
    "resourceVersion": "70872",
    "generation": 1,
    "creationTimestamp": "2018-05-17T21:56:16Z",
    "labels": {
      "name": "my-test"
    }
  },
  "spec": {
    "replicas": 2,
    "selector": {
      "name": "my-test"
    },
    "template": {
      "metadata": {
        "creationTimestamp": null,
        "labels": {
          "name": "my-test"
        }
      },
      "spec": {
        "containers": [
          {
            "name": "cont0",
            "image": "192.168.97.10:5000/test_img:kubes",
            "command": [
              "/usr/local/bin/php"
            ],
            "args": [
              "/opt/code/myscript.php",
              "myarg"
            ],
            "resources": {},
            "terminationMessagePath": "/dev/termination-log",
            "terminationMessagePolicy": "File",
            "imagePullPolicy": "IfNotPresent"
          }
        ],
        "hostAliases": [
          {
            "ip": "10.0.2.2",
            "hostnames": [ "mylaptop"],
          }
        ],
        "restartPolicy": "Always",
        "terminationGracePeriodSeconds": 30,
        "dnsPolicy": "ClusterFirst",
        "securityContext": {},
        "schedulerName": "default-scheduler"
      }
    }
  },
  "status": {
    "replicas": 2,
    "fullyLabeledReplicas": 2,
    "observedGeneration": 1
  }
}
</code></pre>

<p>However the hostAliases just seems to be ignored...</p>

<p>Any pointers on whether this is supported, and if not, any alternative methods of achieving the same?</p>

KennetRunner
<p>I hope this is the solution, as I quickly verified it and it worked. I created a simple nginx deployment and then edited it to add the <code>hostAliases</code> entry:</p>

<p>With below snippet, I was getting an error and could not save the deployment</p>

<pre><code>"hostAliases": [
          {
            "ip": "10.0.2.2",
            "hostnames": [ "mylaptop"],
          }
        ],
</code></pre>

<p>The problem is that comma <code>,</code> after the <code>[ "mylaptop"]</code> - once I removed it and then saved deployment:</p>

<pre><code>"hostAliases": [
          {
            "ip": "10.0.2.2",
            "hostnames": [ "mylaptop"]
          }
        ],
</code></pre>

<p>I could see entry in the hosts file:</p>

<pre><code>$kubectl exec -i -t nginx-5f6bbbdf97-m6d92 -- sh
# 
# 
# cat /etc/hosts
# Kubernetes-managed hosts file.
127.0.0.1   localhost
::1 localhost ip6-localhost ip6-loopback
fe00::0 ip6-localnet
fe00::0 ip6-mcastprefix
fe00::1 ip6-allnodes
fe00::2 ip6-allrouters
10.8.4.147  nginx-5f6bbbdf97-m6d92

# Entries added by HostAliases.
10.0.2.2    mylaptop
</code></pre>
