Search code examples
microk8s

how to enable port forward with micrpk8s


I'm playing around with microk8s and I simply want to run an apache server and navigate to its default page on the same machine. I'm on a mac arm m1:

microk8s kubectl run test-pod --image=ubuntu/apache2:2.4-20.04_beta --port=80

 ~ $ microk8s kubectl get pods                                                                                             2
NAME                                   READY   STATUS             RESTARTS       AGE
test-pod                               1/1     Running            0              8m43s

then I try to enable the forward:

◼ ~ $ microk8s kubectl port-forward test-pod :80
Forwarding from 127.0.0.1:37551 -> 80

but:

◼ ~ $ wget http://localhost:37551
--2022-12-24 18:54:37--  http://localhost:37551/
Resolving localhost (localhost)... 127.0.0.1, ::1
Connecting to localhost (localhost)|127.0.0.1|:8080... failed: Connection refused.
Connecting to localhost (localhost)|::1|:8080... failed: Connection refused.

the logs looks ok:

◼ ~ $ microk8s kubectl  logs test-pod                                                                           130
AH00558: apache2: Could not reliably determine the server's fully qualified domain name, using 10.1.254.96. Set the 'ServerName' directive globally to suppress this message

dashboard proxy does work fine and I can navigate to it:

◼ ~ $ microk8s dashboard-proxy
Checking if Dashboard is running.
Dashboard will be available at https://192.168.64.2:10443

Solution

  • Answering myself:

    1. I should use the Multipass' guest machine assigned IP. This is not docker :)
    2. For some reason I haven't figured out, as asked here, the forwarding from the guest does not work properly on mac. I should open a guest's shell and forward from there. that way, it will work. See the answer on the linked post.

    Hope this will spare some time on future mac users.