<p>I'm trying to port-forward my kubernetes service (through minikube) using the following command:</p>
<pre><code>kubectl port-forward svc/hapi-fhir-server 8080:8080 --address=0.0.0.0
</code></pre>
<p>But after trying to reach <code>localhost:8080</code> I get the following error: <code>&quot;....... an error occurred forwarding 8080 -&gt; 8080: error forwarding port 8080 to pod {PodID, uid ....:E connect(5, AF=2 127.0.0.1:8080, 16): Connection refused&quot;</code></p>
<p>I checked which port the pod is listening to through the following command
<code>kubectl get pod hapi-fhir-server-666b846cbf-lhmr4 --template=&quot;{{(index (index .spec.containers 0).ports 0).containerPort}}&quot;</code> resulting in answer <code>8080</code></p>
<p>For if this helps, my service &amp; deployment files (having removed unrelated lines)</p>
<pre><code>apiVersion: apps/v1
kind: Deployment
metadata:
  ....
spec:
  replicas: 2
  selector:
    ....
  template:
      ....
    spec:
      containers:
        - image: .........
          name: hapi-fhir-server
          ports:
            - containerPort: 8080
          resources: {}
      restartPolicy: Always
status: {}
</code></pre>
<pre><code>apiVersion: v1
kind: Service
metadata:
  ....
spec:
  type: NodePort
  ports:
    - protocol: TCP
      port: 8080
      targetPort: 8080
      nodePort: 32069
  selector:
    app: hapi-fhir-server
status:
  loadBalancer: {}
</code></pre>
<p>The image being used is a HAPI FHIR server with the following configuration that runs on Apache Tomcat (server.xml):</p>
<pre><code>&lt;Connector port=&quot;${server.port}&quot; protocol=&quot;HTTP/1.1&quot;
               connectionTimeout=&quot;20000&quot;
               redirectPort=&quot;8443&quot; 
               maxThreads=&quot;${server.tomcat.max-threads}&quot;
               minSpareThreads=&quot;${server.tomcat.min-spare-threads}&quot; /&gt; 
</code></pre>
<p><code>server.port</code> being 8080.</p>
<p>I can't seem to find an accurate answer to why this is happening, even after going through documentation or similar questions like: <a href="https://stackoverflow.com/questions/53799600/kubernetes-port-forwarding-connection-refused">Kubernetes Port Forwarding - Connection refused</a>.</p>
<p>Is there something I am missing, not doing correctly or that I am not thinking of?
<strong>Note:</strong> I am relatively new to Kubernetes.</p>

Delano van der Waal
<p>Apparently there was no issue with the Kubernetes or server configuration but rather the Dockerfile that didn't expose port 8080, now it does through the following:</p>
<pre><code># Dockerfile
......
EXPOSE 8080
......
</code></pre>
<p>Thanks to IvanAracki that pointed this out to me through the comments.</p>
