<p>I am running multinode k8s cluster on my workstation. I have created the VM's using multipass. K8s cluster is deployed using microk8s.</p>

<p>Microk8s provides private registry as a <a href="https://github.com/ubuntu/microk8s/blob/8bf6e65e9ed5f0749f43882c31787765ad91af1b/microk8s-resources/actions/registry.yaml" rel="nofollow noreferrer">addon</a>.</p>

<p>It is providing 32000 as node port for the registry.</p>

<p>I would like to connect to this cluster remotely and push docker images to this registry. </p>

<p>I have added <code>172.**.44.***:32000</code> as insecure registery in my docker settings in my remote pc.</p>

<p>Note: <code>172.**.44.***</code> is the IP of the cluster (something you get in kubectl cluster-info)</p>

<p>But I am unable to make it work</p>

<pre><code>docker build -t 172.**.44.***:32000/myapp:v1 .
docker push 172.**.44.***:32000/myapp:v1
Get http://172.**.44.***:32000/v2/: dial tcp 172.**.44.***:32000: connect: no route to host
</code></pre>

<hr>

<p>I didn't use <code>microk8s</code> to set up kubernetes cluster before, but I do have the feeling is, the ip of <code>172.xx.xx.xx</code> is the wrong IP that you can't connect it from your local pc. </p>

<p>so what's the output of below commands:</p>

<ol>
<li>What's the nodes IP, include master and work nodes?</li>
</ol>

<pre><code>kubernetes get nodes -o wide
</code></pre>

<ol start="2">
<li>What's the service setup?</li>
</ol>

<pre><code>kuberentes get services
</code></pre>

<p>can you make sure the service to that's private registry server's port is setup and can be connected. </p>

<ol start="3">
<li>check your own PC's IP</li>
</ol>

<pre><code># for windows
ipconfig

# for linux/macos
ifconfig
</code></pre>

<p>maybe there are many IPs in output, make sure you get the proper local IP for your PC. </p>

<p>For example, it is something like <code>10.xx.xx.xx</code>, then you should use similar IPs to connect to that private registry server, you just need find it out </p>

<ol start="4">
<li>check what network CNI you are using, weavenet, flannel, etc. </li>
</ol>

<p>the IP of <code>172.xx.xx.xx</code> are mostly used by these network CNI provider, it can be used in kubernetes cluster, but not your local host. </p>

piby180
<p>After you enable registry on the microk8s, run this script</p>

<pre class="lang-sh prettyprint-override"><code>kubectl get svc -n container-registry
</code></pre>

<p>you can see that microk8s has redirect registry service's port <code>32000</code> to <code>5000</code>, then I use <code>ingress</code> to expose via https. </p>

<p>First, you have to enable <code>ingress</code> on microk8s:</p>

<pre><code>microk8s.enable ingress
</code></pre>

<p>then, you have to create a <code>tls sceret</code> if you want to use https :</p>

<pre class="lang-sh prettyprint-override"><code>openssl genrsa -aes128 -out server.key 2048

openssl req -newkey rsa:2048 -nodes -keyout server.key -x509 -days 3650 -out server.crt

kubectl create secret tls registry-secret-tls --cert=server.crt --key=server.key -n container-registry
</code></pre>

<p>then use <code>kubectl apply -f</code> to create an <code>ingress</code> for revese proxy of <code>registry</code> service.</p>

<pre class="lang-yaml prettyprint-override"><code>apiVersion: extensions/v1beta1
kind: Ingress
metadata:
  name: registry
  namespace: container-registry
  annotations:
    nginx.ingress.kubernetes.io/ingress.class: nginx
    nginx.ingress.kubernetes.io/proxy-body-size: "500m"
    nginx.ingress.kubernetes.io/proxy-pass-headers: "Location"
spec:
  tls:
  - hosts:
    - ingress.local
    secretName: registry-secret-tls
  rules:
  - host: ingress.local
    http:
      paths:
      - path: /
        backend:
          serviceName: registry
          servicePort: 5000
</code></pre>

<p>then, add <code>127.0.0.1 ingress.local</code> to <code>/etc/hosts</code> file. 
At last, use <code>buildah</code> push docker images to <code>ingress.local</code>.</p>

<pre class="lang-sh prettyprint-override"><code>buildah push --tls-verify=false 44c92e82c220 docker://ingress.local/datacenter-school
</code></pre>

<p>This time, it looks everything is ok. But when I try list images in microk8s, I can't find the image that I just pushed.</p>

<pre class="lang-sh prettyprint-override"><code>microk8s.ctr images ls -q |grep datacenter-school
</code></pre>

<p>That's quiet weird!</p>
