<p>I am trying to deploy an image from my private registry that's hosted on my local network and pointed using my local machines /etc/hosts file.</p>
<p>I am getting the resolution error as below:</p>
<pre><code>Failed to pull image &quot;gitlab.example.com:5050/group/project:latest&quot;: rpc error: code = Unknown desc = failed to resolve image
</code></pre>
<p>My /etc/hosts file contains:</p>
<pre><code>192.168.1.100 gitlab.example.com
</code></pre>
<p>Using docker the pull/push works perfectly fine as the resolution happens using /etc/hosts</p>
<p>I've tried editing corefile of coredns to make the resolution happen, but it isn't working.</p>
<p>Can someone point me in right direction over here.</p>

Anoop Naik
<p>You can try to use <a href="https://kubernetes.io/docs/concepts/services-networking/add-entries-to-pod-etc-hosts-with-host-aliases/" rel="nofollow noreferrer">hostAliases</a> 💡 and add a host entry to your pod. Kubernetes will not honor the <code>/etc/hosts</code> file from the hosts/nodes. Either the one in the pod or resolves through CoreDNS. For example:</p>
<pre class="lang-yaml prettyprint-override"><code>apiVersion: v1
kind: Pod
metadata:
  name: hostaliases-pod
spec:
  restartPolicy: Never
  hostAliases:
  - ip: &quot;192.168.1.100&quot; 👈
    hostnames:
    - &quot;gitlab.example.com&quot; 👈
  containers:
  - name: gitlab-hosts
    image: myimage
    command:
    - mygitlabjob
    args:
    - &quot;arg1&quot;
</code></pre>
<p>Update:</p>
<p>I think see the problem here. microk8s on Ubuntu runs in a <code>snap</code>. That means it's <a href="https://snapcraft.io/docs/snap-confinement" rel="nofollow noreferrer">confined/sandboxed</a> in a container of its own. This also means that it probably doesn't care about your machine's <code>/etc/hosts</code> file. Unfortunately, snap's file systems are mounted as read-only for security reasons and to prevent tampering.</p>
<pre class="lang-sh prettyprint-override"><code>○ → pwd
/snap/microk8s/current
○ → sudo touch hosts
touch: cannot touch 'hosts': Read-only file system
</code></pre>
<p>If you'd like to use a private registry this way, some recommendations:</p>
<ul>
<li>Ask your system admin to add that entry into your local DNS server, or add it if you are the system admin.</li>
<li>Use an alternative small K8s distro that uses Docker.
<ul>
<li><a href="https://kind.sigs.k8s.io/docs/user/quick-start/" rel="nofollow noreferrer">KinD</a></li>
<li><a href="https://kubernetes.io/docs/tasks/tools/install-minikube/" rel="nofollow noreferrer">minikube</a></li>
</ul>
</li>
<li>Build your own microk8s snap with a modified <code>/etc/hosts</code> file (hard)</li>
</ul>
