From your stack overflow post: you only “told” Kubernetes at what port something is listening inside the container, you didn’t specify to which port you’d like to map that.
I personally, would put a service in front of it as documented here:
https://kubernetes.io/docs/concepts/services-networking/service/
kind: Service
apiVersion: v1
metadata:
name: my-postgres-service
spec:
selector:
app: my-postgres-app
ports:
- protocol: TCP
port: 80 #That's the port you'll use to connect
targetPort: 55432 # that's the port at which your app (your postgres) is listening