Kubernetes Service get Connection Refused Kubernetes Service get Connection Refused kubernetes kubernetes

Kubernetes Service get Connection Refused


you are mixing two things here. NodePort is the port the application is available from outside your cluster. Inside your cluster you need to access your service via the service port, not the NodePort.

Try changing exporter-test-service.datenlord-monitoring.svc:30001 to exporter-test-service.datenlord-monitoring.svc:8080


Welcome to the community!

There are no issues with behaviour you observed.In short words kubernetes cluster (which is minikube in this case) has its own isolated network with internal DNS.

One way to access your service on the node: you specified nodePort for your service and this made the service accessible on the localhost:30001. You can check it by running on your host:

$ kubectl get svc -n datenlord-monitoringNAME                    TYPE       CLUSTER-IP       EXTERNAL-IP   PORT(S)          AGEexporter-test-service   NodePort   10.111.191.159   <none>        8080:30001/TCP   2m45s# Test:curl -I localhost:30001HTTP/1.1 200 OK

Another way to expose service to the host network is to use minikube tunnel (run in the another console). You'll need to change service type from NodePort to LoadBalancer:

$ kubectl get svc -n datenlord-monitoringNAME                    TYPE           CLUSTER-IP       EXTERNAL-IP      PORT(S)          AGEexporter-test-service   LoadBalancer   10.111.191.159   10.111.191.159   8080:30001/TCP   18m# Test:$ curl -I 10.111.191.159:8080HTTP/1.1 200 OK

Why some of options doesn't work.

Connection to the service by its DNS + NodePort. NodePort is used to link host IP and NodePort to service port inside kubernetes cluster. Internal DNS is not accessible outside kubernetes cluster (unless you don't add IPs to /etc/hosts on your host machine)

Inside the cluster you should use internal DNS with internal service port which is 8080 in your case. You can check how this works with a separate container in the same namespace (e.g. image curlimages/curl) and get following:

$ kubectl exec -it curl -n datenlord-monitoring -- curl -I exporter-test-service:8080HTTP/1.1 200 OK

Or from the pod in a different namespace:

$ kubectl exec -it curl-default-ns -- curl -I exporter-test-service.datenlord-monitoring.svc:8080HTTP/1.1 200 OK

I've attached useful links which help you to understand this difference.

Edit: DNS inside deployed pod

$ kubectl exec -it exporter-test-xxxxxxxx-yyyyy -n datenlord-monitoring -- bashroot@exporter-test-74cf9f94ff-fmcqp:/# cat /etc/resolv.conf nameserver 10.96.0.10search datenlord-monitoring.svc.cluster.local svc.cluster.local cluster.localoptions ndots:5

Useful links: