Aditia Rahman
Aditia Rahman

Reputation: 110

Connect to internal kubernetes service from local network

it is possible to connect to internal kubernetes service from local network? for example I have vm outside kubernetes cluster but on the same network as kubernetes cluster (I can ping the private node ip from my vm), and from that vm I want to connect to internal kubernetes service like http://sample-service.default.svc.cluster.local from local network

I've tried follow this tutorial https://blog.heptio.com/configuring-your-linux-host-to-resolve-a-local-kubernetes-clusters-service-urls-a8c7bdb212a7 but still not working

Upvotes: 2

Views: 2085

Answers (1)

Fabrice Jammes
Fabrice Jammes

Reputation: 3205

Yes it is possible, you need to change the type of your service to NodePort: https://kubernetes.io/docs/concepts/services-networking/service/#nodeport. Then your service will be reachable from any of your Kubernetes worker nodes, using its IP address and the NodePort (>30000) displayed by command below.

For example:

$ kubectl get svc parse-server 
NAME           TYPE       CLUSTER-IP      EXTERNAL-IP   PORT(S)          AGE
parse-server   NodePort   10.96.139.142   <none>        1337:31013/TCP   17h

$ kubectl get nodes -o wide
NAME                 STATUS   ROLES    AGE   VERSION   INTERNAL-IP   EXTERNAL-IP   OS-IMAGE                                     KERNEL-VERSION    CONTAINER-RUNTIME
...
kind-worker2         Ready    <none>   42h   v1.19.1   172.18.0.2    <none>        Ubuntu Groovy Gorilla (development branch)   4.15.0-1101-oem   containerd://1.4.0

Then service parse-server is reachable from the local network using:

$ curl http://172.18.0.2:31013
<!DOCTYPE html>
<html lang="en">
...

NodePort is the easiest way to expose service outside of a Kubernetes cluster, but if you need more advanced features, like routing by url path or hostname, you need to investigate on ingress: https://kubernetes.io/docs/concepts/services-networking/ingress/.

Upvotes: 2

Related Questions