Home > Net >  Kubernetes NodePort not accesible from outside
Kubernetes NodePort not accesible from outside

Time:02-07

I'm trying to use the latest bitnami postgres chart to deploy postgres to a local kubernetes cluster (mac os, docker desktop 4.4.2, kubernetes 1.22.5): https://github.com/bitnami/bitnami-docker-postgresql

I have set the node port:

primary:
  service:
    # Kubernetes Service type
    type: NodePort
    nodePorts:
      # Node port for PostgreSQL
      postgresql: '30000'

the service is visible:

NAME                             TYPE        CLUSTER-IP       EXTERNAL-IP   PORT(S)          AGE
service/postgres-nodeport      NodePort    10.111.195.149   <none>        5432:30000/TCP   9m56s

but I cant access it from outside, eg:

psql -h localhost -p 30000 -U myusername -d mydatabase

but I think it is configured correctly, because when I execute port-forward postgres is available:

kubectl port-forward pod/postgres-nodeport-0 30000:5432 

CodePudding user response:

I found a solution: You need to set the port to higher than 30000, e.g. 30001 but its strange, because earlier it worked with port 30000, and the documentation says that the port range is 30000-32767

CodePudding user response:

you need to call with node ip. The format should be NodeIP of the Node where you are running your pods and the NodePort. Ref

The Template to call NodePort service from outside the cluster is like this.

<NodeIP>:<NodePort>

Try this one:

psql -h 192.168.65.4 -p 30000 -U myusername -d mydatabase

CodePudding user response:

Nodeport only exposes the service on the nodes at the specified port. It does not expose it to the public. You need to configure ingress or load balancer to expose the service to the outside world.

  •  Tags:  
  • Related