<p>I can start an &quot;interactive pod&quot; using:</p>
<pre class="lang-sh prettyprint-override"><code>$ kubectl run my-shell --rm -i --tty --image ubuntu -- bash
</code></pre>
<p>How can I add a <a href="https://kubernetes.io/docs/tasks/network/customize-hosts-file-for-pods/" rel="nofollow noreferrer">customized hosts file</a> for this pod?</p>
<p>That is, one or more entries in <code>hostAliases</code> which is defined in the pod manifest.</p>
<p>One option is to create a pod that runs some idle process:</p>
<pre class="lang-yaml prettyprint-override"><code>apiVersion: v1
kind: Pod
metadata:
  name: my-shell
spec:
  restartPolicy: Never
  hostAliases:
  - ip: &quot;8.8.8.8&quot;
    hostnames:
    - &quot;dns.google&quot;
  containers:
  - name: my-shell
    image: ubuntu
    command: ['sh', '-c', 'echo The app is running! &amp;&amp; sleep 3600']
</code></pre>
<p>Applying that using <code>kubectl apply</code> and then <code>kubectl exec</code> into the running pod.</p>
<p>Is it possible to more directly start an interactive pod with a specific pod spec?</p>

malthe
<p>Add <code>--overrides='{ &quot;spec&quot;: { &quot;hostAliases&quot;: [ { &quot;ip&quot;: &quot;8.8.8.8&quot;, &quot;hostnames&quot;: [ &quot;dns.google&quot; ] } ] } }'</code> to the <code>kubectl run</code> command:</p>
<pre><code>kubectl run my-shell --rm -i --tty --image ubuntu --overrides='{ &quot;spec&quot;: { &quot;hostAliases&quot;: [ { &quot;ip&quot;: &quot;8.8.8.8&quot;, &quot;hostnames&quot;: [ &quot;dns.google&quot; ] } ] } }' -- bash
</code></pre>
<p>Reference: <a href="https://kubernetes.io/docs/reference/generated/kubectl/kubectl-commands#run" rel="nofollow noreferrer">https://kubernetes.io/docs/reference/generated/kubectl/kubectl-commands#run</a></p>
