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

1

5

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

Ratha answered 10/5, 2022 at 8:19 Comment(2)
Try to port forward: kubectl port-forward service/mongo-service 28015:27017, then you can use localhost:28015 to connect to it. Rancher desktop comes with traefik as ingress controller if I am not mistaken. You could also create an ingress for your mongo service.Goar
thank you for the response, will try with an ingresRatha
R
8

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

Ratha answered 10/5, 2022 at 13:26 Comment(1)
I love you; I got stuck with this thing for about 2 hoursFiertz

© 2022 - 2024 — McMap. All rights reserved.