<p>I have an issue with the DNS mapping in kubernetes.</p>
<p>We have some servers which can be accessed from internet. The global DNS translates these servers's domain names to public internet IPs.
Some services can't access through public IPs for security consideration.</p>
<p>From company internal, we add the DNS mappings with private IPs to /etc/hosts inside docker containers managed by kubernetes to access these servers manually.</p>
<p>I know that docker supports command --add-host to change <code>/etc/hosts</code> when executing <code>docker run</code>. I'm not sure if this command supported in latest kubernetes, such as kuber <code>1.4</code> or <code>1.5</code> ?</p>
<p>On the other hand, we can wrap the startup script for the docker container,</p>
<ul>
<li>append the mappings to <code>/etc/hosts</code> firstly</li>
<li>start our application</li>
</ul>
<p>I only want to change the file once after first run in each container. Is there an easy way to do this because the mapping relations maybe different between develop and production environments or any commands related to this provided by kubernetes itself?</p>

<p>It is now possible to add a <code>hostAliases</code> section directly in the description of the deployment.</p>
<p>As a full example of how to use the <code>hostAliases</code> section I have included the surrounding code for an example deployment as well.</p>
<pre class="lang-yaml prettyprint-override"><code>apiVersion : apps/v1
kind: Deployment
metadata:
  name: &quot;backend-cluster&quot;
spec:
  replicas: 1
  selector:
    matchLabels:
      app: &quot;backend&quot;
  template:
    metadata:
      labels:
        app: &quot;backend&quot;
    spec:
      containers:
      - name: &quot;backend&quot;
        image: &quot;exampleregistry.azurecr.io/backend&quot;
        ports:
        - containerPort: 80
      hostAliases:
      - hostnames:
        - &quot;www.example.com&quot;
        ip: &quot;10.0.2.4&quot;
</code></pre>
<p>The important part is only a part of the file and here it is omitted for clarity:</p>
<pre class="lang-yaml prettyprint-override"><code>...
      hostAliases:
      - hostnames:
        - &quot;www.example.com&quot;
        ip: &quot;10.0.2.4&quot;
</code></pre>
