Using rancher Desktop: How to access a Kubernetes Service(node port) running in a container from the local laptop

4.6k views Asked by At

I am running Rancher Desktop on my ubuntu laptop. I have a container running mongodb in a kubernetes container:

$ kubectl get all
NAME                                                 READY   STATUS              RESTARTS       AGE
pod/mongo-deployment-7fb46bd85-vz9th                 1/1     Running             0              37m

NAME                                 TYPE        CLUSTER-IP      EXTERNAL-IP   PORT(S)           AGE
service/kubernetes                   ClusterIP   10.43.0.1       <none>        443/TCP           3d17h
service/mongo-service                NodePort    10.43.132.185   <none>        27017:32040/TCP   37m

NAME                                            READY   UP-TO-DATE   AVAILABLE   AGE
deployment.apps/mongo-deployment                1/1     1            1           37m

NAME                                                       DESIRED   CURRENT   READY   AGE
replicaset.apps/mongo-deployment-7fb46bd85                 1         1         1       37m

So the node port of the mongo service is: 32040.

I have found the local ip of the kubernetes node:

$ kubectl get node -o wide
NAME                   STATUS   ROLES                  AGE     VERSION        INTERNAL-IP    EXTERNAL-IP   OS-IMAGE             KERNEL-VERSION   CONTAINER-RUNTIME
lima-rancher-desktop   Ready    control-plane,master   3d17h   v1.23.6+k3s1   192.168.5.15   <none>        Alpine Linux v3.15   5.15.32-0-virt   containerd://1.5.11

so the internal ip is: 192.168.5.15

but when i try to connect to 192.168.5.15 on port 32040 i get connection timed out.

could i have a hint on how to do this with Rancher Desktop ?

thank you, Andrei

1

There are 1 answers

0
Andrei Diaconescu On

i found a solution: it seems that the ip returned by kubectl get node -o wide is not usable to acess services from the kubernetes node, in Rancher Desktop (it is working in other kubernetes cluster named "kind" (https://kind.sigs.k8s.io/)).

What is working for Rancher Desktop is to access the NodePort service directly on localhost, so in the example above: localhost:32040