Home > Back-end >  minikube service URL gives ECONNREFUSED on mac os Monterey
minikube service URL gives ECONNREFUSED on mac os Monterey

Time:11-24

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.

$ 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
$ kubectl get svc
NAME               TYPE        CLUSTER-IP      EXTERNAL-IP   PORT(S)          AGE
server-service     NodePort    10.100.21.232   <none>        8080:31457/TCP   15m
postgres           ClusterIP   10.97.19.125    <none>        5432/TCP         26m
$ 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 |
|-------------|------------------|--------------|-----------------------------|

But when I try to hit any of my endpoints using postman, I get a "Could not send request. Error: connect ECONNREFUSED 192.168.59.106:31457

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 application.properties 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.

Here is the yml for the rest-server:

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

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 "/" endpoint.

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:

$ 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

Thanks in advance!

CodePudding user response:

Possibly MacOS Firewall is blocking the connection. Could you try navigating to System Preferences > Security & Privacy and see if the port is being blocked in General tab? You can also disable Firewall in Firewall tab.

MacOS Firewall

CodePudding user response:

Thanks to Andrew Skorkin for pointing out my flaws. I changed the attribute from

spec:
  selector:
    matchLabels:
      app: server-deployment

to

spec:
  selector:
    matchLabels:
      name: server-deployment

in my Deployment and I also added the containerPort: 8080 explicitly. That fixed everything!

CodePudding user response:

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 app: server-deployment, but in the Service config selector is name: server-deployment.

If we want to use name: server-deployment selector for the Service, then we need to update the Deployment as shown below (matchLabels and labels fields):

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:
      ...
  • Related