<p>I have a spring-boot postgres setup that I am trying to containerize and deploy in minikube. My pods and services show that they are up.</p>
<pre><code>$ kubectl get pods
NAME                                          READY   STATUS    RESTARTS   AGE
server-deployment-5bc57dcd4f-zrwzs            1/1     Running   0          14m
postgres-7f887f4d7d-5b8v5                     1/1     Running   0          25m
</code></pre>
<pre><code>$ kubectl get svc
NAME               TYPE        CLUSTER-IP      EXTERNAL-IP   PORT(S)          AGE
server-service     NodePort    10.100.21.232   &lt;none&gt;        8080:31457/TCP   15m
postgres           ClusterIP   10.97.19.125    &lt;none&gt;        5432/TCP         26m
</code></pre>
<pre><code>$ minikube service list
|-------------|------------------|--------------|-----------------------------|
|  NAMESPACE  |       NAME       | TARGET PORT  |             URL             |
|-------------|------------------|--------------|-----------------------------|
| default     | kubernetes       | No node port |
| kube-system | kube-dns         | No node port |
| custom      | server-service   | http/8080    | http://192.168.59.106:31457 |
| custom      | postgres         | No node port |
|-------------|------------------|--------------|-----------------------------|
</code></pre>
<p>But when I try to hit any of my endpoints using postman, I get:</p>
<pre><code>Could not send request. Error: connect ECONNREFUSED 192.168.59.106:31457
</code></pre>
<p>I don't know where I am going wrong. I tried deploying the individual containers directly in docker (I had to modify some of the <code>application.properties</code> to get the rest server talking to the db container) and that works without a problem so clearly my server side code should not be a problem.</p>
<p>Here is the yml for the rest-server:</p>
<pre><code>apiVersion: apps/v1
kind: Deployment
metadata:
  name: server-deployment
  namespace: custom
spec:
  selector:
    matchLabels:
      app: server-deployment
  template:
    metadata:
      name: server-deployment
      labels:
        app: server-deployment
    spec:
      containers:
      - name: server-deployment
        image: aruns1494/rest-server-k8s:latest
        env:
        - name: POSTGRES_USER
          valueFrom:
            configMapKeyRef:
              name: postgres-config
              key: postgres_user
        - name: POSTGRES_PASSWORD
          valueFrom:
            configMapKeyRef:
              name: postgres-config
              key: postgres_password
        - name: POSTGRES_SERVICE
          valueFrom:
            configMapKeyRef:
              name: postgres-config
              key: postgres_service
---
apiVersion: v1
kind: Service
metadata:
  name: server-service
  namespace: custom
spec:
  selector:
    name: server-deployment
  ports:
  - name: http
    port: 8080
  type: NodePort
</code></pre>
<p>I have not changed the spring boot's default port so I expect it to work on 8080. I tried connecting to that URL through chrome and Firefox and I get the same error message. I expect it to fall back to a default error message page when I try to hit the <code>/</code> endpoint.</p>
<p>I did look up several online articles but none of them seem to help. I am also attaching my kube-system pods if that helps:</p>
<pre><code>$ kubectl get pods -n kube-system
NAME                               READY   STATUS    RESTARTS      AGE
coredns-78fcd69978-x6mv6           1/1     Running   0             39m
etcd-minikube                      1/1     Running   0             40m
kube-apiserver-minikube            1/1     Running   0             40m
kube-controller-manager-minikube   1/1     Running   0             40m
kube-proxy-dnr8p                   1/1     Running   0             39m
kube-scheduler-minikube            1/1     Running   0             40m
storage-provisioner                1/1     Running   1 (39m ago)   40m
</code></pre>

<p>My proposition is to check that provided Deployment and Service have the same labels and selectors, because now in the Deployment config pod label is <code>app: server-deployment</code>, but in the Service config selector is <code>name: server-deployment</code>.</p>
<p>If we want to use <code>name: server-deployment</code> selector for the Service, then we need to update the Deployment as shown below (<code>matchLabels</code> and <code>labels</code> fields):</p>
<pre><code>apiVersion: apps/v1
kind: Deployment
metadata:
  name: server-deployment
  namespace: custom
spec:
  selector:
    matchLabels:
      name: server-deployment
  template:
    metadata:
      name: server-deployment
      labels:
        name: server-deployment
    spec:
      containers:
      ...
</code></pre>
