<p>I am trying to create an application in Kubernetes (Minikube) and expose its service to other applications in same clusters, but i get connection refused if i try to access this service in Kubernetes node.</p>
<p>This application just listen on HTTP <code>127.0.0.1:9897</code> address and send response.</p>
<p>Below is my yaml file:</p>
<pre><code>apiVersion: apps/v1
kind: Deployment
metadata:
  name: exporter-test
  namespace: datenlord-monitoring
  labels:
    app: exporter-test
spec:
  replicas: 1
  selector:
    matchLabels:
      app: exporter-test
  template:
    metadata:
      labels:
        app: exporter-test
    spec:
      containers:
        - name: prometheus
          image: 34342/hello_world
          ports:
            - containerPort: 9897

---
apiVersion: v1
kind: Service
metadata:
  name: exporter-test-service
  namespace: datenlord-monitoring
  annotations:
      prometheus.io/scrape: 'true'
      prometheus.io/port:   '9897'
spec:
  selector: 
    app: exporter-test
  type: NodePort  
  ports:
    - port: 8080
      targetPort: 9897
      nodePort: 30001
</code></pre>
<p>After I apply this yaml file, the pod and the service deployed correctly, and I am sure this pod works correctly, since when I login the pod by
<code>kubectl exec -it exporter-test-* -- sh</code>, then just run <code>curl 127.0.0.1:9897</code>, I can get the correct response.</p>
<p>Also, if I run <code>kubectl port-forward exporter-test-* -n datenlord-monitoring 8080:9897</code>, I can get correct response from <code>localhost:8080</code>. So this application should work well.</p>
<p>However, when I trying to access this service from other application in same K8s cluster by <code>exporter-test-service.datenlord-monitoring.svc:30001</code> or just run <code>curl nodeIp:30001</code> in k8s node or run <code>curl clusterIp:8080</code> in k8s node, I got <code>Connection refused</code></p>
<p>Anyone had same issue before? Appreciate for any help! Thanks!</p>

user8756715
<p>you need to change <code>127.0.0.1:9897</code> to <code>0.0.0.0:9897</code> so that application listens to all incoming requests</p>
