<p>I have the <code>minikube</code> environment as the following: -</p>
<ul>
<li>Host OS: <code>CentOS Linux release 7.7.1908 (Core)</code></li>
<li>Docker:  <code>Docker Engine - Community 20.10.7</code></li>
<li>minikube: <code>minikube version: v1.20.0</code></li>
</ul>
<p>I would like to add some additional host mapping (5+ IP and name) to the <code>/etc/hosts</code> inside the <code>minikube</code> container. Then I use the <code>minikube ssh</code> to enter to the shell and try to <code>echo &quot;172.17.x.x my.some.host&quot; &gt;&gt; /etc/hosts</code>. There is an error as <code>-bash: /etc/hosts: Permission denied</code> since the user who login to this shell is a <code>docker</code>, not a <code>root</code>.</p>
<p>I also found that at the host machine there is a docker container named <code>minikube</code> running, by using the <code>docker container ls</code>. Even I can go to this container with <code>root</code> by using <code>docker exec -it -u root minikube /bin/bash</code>. I understand that it is a kind of tweak and may be a bad practice. Especially it is too much tasks.</p>
<p>Regarding to the <code>docker</code> and <code>docker-compose</code> which provides the <code>--add-host</code> and <code>extra_hosts</code> respectively to add hostname mappings, Does the <code>minikube</code> provide it? Is there any good practice to achieve this within the <code>minikube</code> and/or system administrator point-of-view good practice?</p>
<h4>Edit 1</h4>
<p>After <code>echo 172.17.x.x my.some.host &gt; ~/.minikube/files/etc/hosts</code> and start the <code>minikube</code>, there are some error as the following: -</p>
<pre class="lang-sh prettyprint-override"><code>[kubelet-check] It seems like the kubelet isn't running or healthy.
[kubelet-check] The HTTP call equal to 'curl -sSL http://localhost:10248/healthz' failed with error: Get &quot;http://localhost:10248/healthz&quot;: dial tcp: lookup localhost on 8.8.8.8:53: no such host.

        Unfortunately, an error has occurred:
                timed out waiting for the condition

        This error is likely caused by:
                - The kubelet is not running
                - The kubelet is unhealthy due to a misconfiguration of the node in some way (required cgroups disabled)

        If you are on a systemd-powered system, you can try to troubleshoot the error with the following commands:
                - 'systemctl status kubelet'
                - 'journalctl -xeu kubelet'

        Additionally, a control plane component may have crashed or exited when started by the container runtime.
        To troubleshoot, list all containers using your preferred container runtimes CLI.

        Here is one example how you may list all Kubernetes containers running in docker:
                - 'docker ps -a | grep kube | grep -v pause'
                Once you have found the failing container, you can inspect its logs with:
                - 'docker logs CONTAINERID'
</code></pre>
<p>Then I use the <code>vi</code> to create a whole <code>hosts</code> file at <code>~/.minikube/files/etc/hosts</code> as the following: -</p>
<pre><code>127.0.0.1       localhost
::1     localhost ip6-localhost ip6-loopback
fe00::0 ip6-localnet
ff00::0 ip6-mcastprefix
ff02::1 ip6-allnodes
ff02::2 ip6-allrouters

172.17.x.x my.some.host1
172.17.x.y my.some.host2
...
</code></pre>
<p>At this time the <code>minikube</code> is started properly.</p>

<p>Minikube has a <a href="https://minikube.sigs.k8s.io/docs/handbook/filesync/" rel="nofollow noreferrer">built-in sync mechanism</a> that could deploy a desired /etc/hosts with the following example:</p>
<pre><code>mkidr -p ~/.minikube/files/etc
echo 127.0.0.1 localhost &gt; ~/.minikube/files/etc/hosts
minikube start
</code></pre>
<p>Then go and check if it's working:</p>
<pre><code>minikube ssh
</code></pre>
<p>And once you are inside the container:</p>
<pre><code>cat /etc/hosts
</code></pre>
