Expose Postgresql through SSH tunnel

Hello k8s community!

I have a PostgreSQL database running on my cluster. I have enable my NGINX Ingress Controller to accept TCP connections. By doing this I’m able to connect to my database from outside the cluster using my user and password. However, I know this is not the most secure way and I would like to know if it’s possible to do it through a SSH tunnel. Anybody knows from a step by step tutorial that might help me to achieve this.

kubectl port-forward is the equivalent of ssh tunnelling in kubernetes.

If this is for a long-lived service instead of development, you probably want to look into service meshes or use vpc peering or using a cni like cilium.