How to export microk8s ports to macOS host?

I want to setup a local Kubernetes cluster for testing on macOS. I selected microk8s running on macOS using Canonical’s multipass.

Installation was smooth and deployment of the kubernetes-bootcamp seemed to have worked. This is the output I got so far:

microk8s kubectl get services

NAME                  TYPE        CLUSTER-IP       EXTERNAL-IP   PORT(S)          AGE
kubernetes            ClusterIP   10.152.183.1     <none>        443/TCP          5h9m
kubernetes-bootcamp   NodePort    10.152.183.226   <none>        8080:31004/TCP   4h10m

multipass list

Name                    State             IPv4             Image
microk8s-vm             Running           192.168.64.2     Ubuntu 18.04 LTS

Pinging the instance with ping 192.168.64.2 works as expected.

Update: I further tested connectivity by installing nginx inside the VM. Using curl http://192.168.64.2 the nginx startpage inside the VM showed up on macOS.

Now when I shell into the VM using multipass exec microk8s-vm -- bash, I can curl into my deployed service as expected with both:

  • curl http://127.0.0.1:31004
  • curl http://10.152.183.226:8080

Getting the expected result of:

Hello Kubernetes bootcamp! | Running on: kubernetes-bootcamp-57978f5f5d-d977w | v=1

However I’m missing the step to access these url from macOS (both curl and a browser). I tried unsuccessfully:

  • curl http://10.152.183.226:8080
  • curl http://10.152.183.226:31004
  • curl http://192.168.64.2:8080
  • curl http://192.168.64.2:31004

I’m obviously missing a step to make the running services accessible from the macOS host. What did I miss? Help is very much appreciated!

Hi @notessensei

Sorry for the late reply.

The 10.152.183.226 is a network internal to the the VM so the curl command should not work for those. curl http://192.168.64.2:8080 should not work either because port 8080 is of the pod 10.152.183.226. The curl http://192.168.64.2:31004 should be returning the Hello Kubernetes bootcamp! message. Could you check there is not firewall (either on the host or on the VM) blocking this connection?