1

I want to setup a local Kubernetes cluster for testing on macOS. I selected microk8s provided by Canonical. Kubernetes doesn't run native on macOS, but uses a Linux VM provided by 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!

stwissel
  • 640
  • 2
  • 7
  • 21
  • To clarify, you are logging to VM on your Mac and you are able to curl those address and when you want to curl them from your Mac you are getting some kind of error? Can you share error output you got? You are using svc type: [NodePort](https://kubernetes.io/docs/concepts/services-networking/service/#nodeport) so I guess `192.168.64.2` its IP address of the VM? Did you configure firewall to allow traffic? Did you deploy anything to get some kind of successful message (for example nginx)? – PjoterS Dec 31 '20 at 09:36
  • Yes. Inside the VM it works. On macOS it simply times out. Haven’t setup an Nginx yet. From macOS both microk8s and kubectl commands work, so they reach the controller inside the VM. Will test Nginx and report back – stwissel Dec 31 '20 at 09:53
  • Just installed nginx inside the VM. I can successful curl the Nginx from macOS using curl http://192.168.64.2. So the forwarding of ports between the k8s running inside the VM and the "outside" is missing. I'll update the question – stwissel Dec 31 '20 at 10:22
  • Just to clarify, you deployed Nginx as pod/deployment in kubernetes like [here](https://kubernetes.io/docs/concepts/workloads/controllers/deployment/#creating-a-deployment), not installed nginx application in the VM? What is your firewall configuration? Are you allowing all traffic or only for some ports/IPs? – PjoterS Jan 04 '21 at 10:06
  • No. Installed NGINX as app on the VM. Didn't try to deploy a pod. Didn't touch the firewall, just used the ootb setting that come with Ubuntu multipass. I try again soon – stwissel Jan 04 '21 at 17:32

1 Answers1

3

That 192.168.64.2 looks like a host only network and may be an internal host only network.. Can you ping 192.168.64.2 from the Mac terminal? multipass defaults to NAT for network and doesn't give the option to change that to bridged until multipass 1.6. Which at this moment is source only. I see 1.5 when I type multipass --version.

You can get around this anyway by using ssh to forward the multipass port out to the Mac host. From the multipass shell AKA multipass shell which defaults to primary, run ssh -R 8080 -R 31004 yourmacusername@yourmachostname.local. Add -f if you want the ssh port forward command to run in the background and add -g if you want to allow connections from other hosts on the same the network as your Mac. If ssh isn't available on your Mac then enable remote access or just ssh logins (ssh server) for your username under the sharing control panel in settings on your Mac.

freegnu
  • 146
  • 3