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
4
Answers
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
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.
you need to call with node ip.
The format should be
NodeIP
of the Node where you are running your pods and theNodePort
. RefThe Template to call NodePort service from outside the cluster is like this.
Try this one:
The Docker Desktop CINC has the
vpnkit-controller
so if you set a service to use aLoadBalancer
it exposes it via your local machine:It is also assigned a random NodePort but the
vpnkit
will expose the default port of 5432 on localhost.