0

For a while, I've used a NodePort service in my kubernetes in docker desktop on an M3 macbook. It's worked fine until today.

Now, it's stopped working, giving me an error when trying to connect:

(venv) jwatte@Jons-MacBook-Pro dir % psql postgresql://postgres:[email protected]:30032/postgres psql: error: connection to server at "127.0.0.1", port 30032 failed: Connection refused Is the server running on that host and accepting TCP/IP connections? 

(lkctl is an alias for kubectl --context=docker=desktop)

The service is listening:

(venv) jwatte@Jons-MacBook-Pro dir % lkctl get service graph-postgres-local -n sandbox -o wide NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE SELECTOR graph-postgres-local NodePort 10.104.142.18 <none> 30032:30032/TCP 7m41s app=graph-postgres 

The target pod exists:

(venv) jwatte@Jons-MacBook-Pro dir % lkctl get pod -n sandbox -l app=graph-postgres NAME READY STATUS RESTARTS AGE graph-postgres-8449bf8697-t8kht 1/1 Running 0 5m51s 

There are no processes listning on port 30032 locally:

(venv) jwatte@Jons-MacBook-Pro dir % netstat -nal | grep LISTEN | grep 32 (venv) jwatte@Jons-MacBook-Pro dir % 

Here's the service:

(venv) jwatte@Jons-MacBook-Pro dir % lkctl get service graph-postgres-local -o yaml -n sandbox apiVersion: v1 kind: Service metadata: annotations: kubectl.kubernetes.io/last-applied-configuration: | {"apiVersion":"v1","kind":"Service","metadata":{"annotations":{},"name":"graph-postgres-local","namespace":"sandbox"},"spec":{"ports":[{"name":"postgres","nodePort":30032,"port":5432,"protocol":"TCP","targetPort":5432}],"selector":{"app":"graph-postgres"},"type":"NodePort"}} creationTimestamp: "2024-07-02T22:35:04Z" name: graph-postgres-local namespace: sandbox resourceVersion: "2154965" uid: c5f3036e-a6b6-4f31-9fea-5c8657f9b929 spec: clusterIP: 10.104.142.18 clusterIPs: - 10.104.142.18 externalTrafficPolicy: Cluster internalTrafficPolicy: Cluster ipFamilies: - IPv4 ipFamilyPolicy: SingleStack ports: - name: postgres nodePort: 30032 port: 30032 protocol: TCP targetPort: 5432 selector: app: graph-postgres sessionAffinity: None type: NodePort status: loadBalancer: {} 

FWIW, I've also tried with port: 5432 in the service specification, with no change.

I understand that docker has to run a VM internally to host these containers, but this used to work, and today it stopped working. I updated to the latest version as of today as well, but no change.

1 Answer 1

0

Did you create an Ingress for it? Until you do, the port is expose but to the "internal docker" network. The Ingress creates a path from the outside world to the inside.

https://kubernetes.io/docs/concepts/services-networking/ingress/

Ideally you will want to have an ingress controller, which will be capable of handling multiple services from a single port. The most common ones are Traefik and NGINX-Ingress.

https://kubernetes.github.io/ingress-nginx/ https://doc.traefik.io/traefik/providers/kubernetes-ingress/

I would recommend starting with NGINX because it's simpler to grasp, but Traefik does some serious magic that makes things easier when you have lots of deployments and stuff.

2
  • Back when I learned Kubernetes, ingress didn't work locally, and only worked in hosted clouds (at least, that's what it seemed like to me.) (Also, kubernetes-in-docker-desktop wasn't really a thing, at the time I used bare kube on a bare linux VM.) I'll try a local docker ingress now and see how that goes! Oh, it looks like it still has the hostname problem. Having every developer in a company edit etc/hosts leads to a lot of support problems. But there are ways around that! Commented Nov 3, 2024 at 18:42
  • Make sure you give Docker the right permissions, Linux and other OSes don't like you using ports under 3000 without proper rights. Commented Nov 3, 2024 at 20:45

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.