I've got a kubernetes pod myapp-2390458f-kfjgd
I can get access to with kubectl
and an instance of a PostgreSQL
that can be accessed from within the kubernetes cluster by the name mypos.tgres.com
, but it cannot be accessed outside of the cluster.
I'm trying to connect to the PostgreSQL
from my laptop, but to my knowledge kubectl port-forward
would not work in that case since I can only forward my local port to some pod's port. But it would not forward traffic further to mypos.tgres.com
.
Is there a way to forward all traffic to the actual db instance mypos.tgres.com
from the pod that can be accessed from my laptop?
What would be the possible solution?
The PostgreSQL
is not running as a pod, but on an internal network that is only accessible from the Kubernetes cluster's pods. The Kubernetes cluster is hosted in our own infrastracture, not in a cloud.
Create a Pod that acts as a proxy to the internal Postgres service; then you can
kubectl port-forward
to that Pod to get access to Postgres from your laptop.We can set up a simple proxy like this:
Now you can expose that proxy on your local machine:
And then access postgres via your local machine:
Delete the proxy pod when you're done: