Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to expose service outside k8s cluster?

Tags:

kubernetes

I have run a Hello World application using the below command.

kubectl run hello-world --replicas=2 --labels="run=load-balancer-example" --image=gcr.io/google-samples/node-hello:1.0 --port=8080

Created a service as below

kubectl expose deployment hello-world --type=NodePort --name=example-service

The pods are running

NAME                          READY   STATUS    RESTARTS   AGE
hello-world-68ff65cf7-dn22t   1/1     Running   0          2m20s
hello-world-68ff65cf7-llvjt   1/1     Running   0          2m20s

Service:

NAME              TYPE        CLUSTER-IP      EXTERNAL-IP   PORT(S)          AGE
example-service   NodePort    10.XX.XX.XX     <none>        8080:32023/TCP   66s

Here, I am able to test it through curl inside the cluster.

curl http://10.XX.XX.XX:8080
Hello Kubernetes!

How can I access this service outside my cluster? (example, through laptop browser)

like image 695
Sunil Gajula Avatar asked Sep 13 '25 06:09

Sunil Gajula


1 Answers

you shoud try

http://IP_OF_KUBERNETES:32023

IP_OF_KUBERNETES can be your master IP your worker IP when you expose a port in kubernetes .It expose that port in all of your server in cluster.Imagine you have two worker node with IP1 and IP2 and one pode is running in IP1 and in worker2 there is no pods but you can access your pod by

http://IP1:32023

http://IP2:32023

like image 104
yasin lachini Avatar answered Sep 17 '25 21:09

yasin lachini