简体   繁体   中英

NodePort Service not accessible from webapp inside minikube cluster, but from outside

I have installed a kubernetes elasticsearch (v. 7.0.1) environment with a deployment and service using type NodePort running on minikube. When I hit kubectl get services , I get the relevant line:

elasticsearch                NodePort    10.101.5.85      <none>        9200:31066/TCP               27m

If I do

$curl http://$(minikube ip):31066

I get the usual elasticsearch page. If, however, I do

root@webapp-5489d8d6fd-2ml2w:/# curl http://localhost:9200

as root of a webapp on the same cluster, I get error:

curl: (7) Failed to connect to localhost port 9200: Connection refused

Can anyone hint at the reason for my problem?

First of all, your elasticsearch service is NodePort type with ports 9200:31066/TCP . It means that elasticsearch is using port 9200 , and NodePort is using 31066 port.

1) curl http://$(minikube ip):31066

MinikubeIP is your node ip. You can verify this using $ kubectl describe node So if you are use port 31066 it connects correctly.

2) curl http://localhost:9200

You did not provide any information about other Deployments or pods so I assume you have Elasticsearch deployment with pod.

If you will execute $ curl http://localhost:9200 in elasticsearch container it will work, because elasticsearch is running inside (local) this container.

If you want to curl from other (non elasticsearch pod) you have to use service which you have created with elasticsearch port. $ curl elasticsearch:9200 or $ curl 10.101.5.85:9200

From other containers you can also curl using NodeIP with NodePort
$ curl $(minikube ip):31066 same like in point 1.

Usefull links: https://gardener.cloud/050-tutorials/content/howto/service-access/

Hope it helps!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM