Connecting to a postgres server, only accessible in kubernetes pod?

Answered

I can access a psql command prompt for a postgres server using kubernetes and kubectl.

I do so by running a command like so:

    kubectl -n mynamespace exec -it some_pod --container someContainer -- /bin/bash -c "$CMD"

where CMD is like the following:

  export PGPASSWORD='MY_PASSWORD_HERE'; ./pgsql/bin//psql  postgresql://someServer:5432/mydb -U myuser

This is all scripted, so with no effort, I can access a terminal based client for postgres. 
Of course I'd prefer to do this with Datagrip if possible, but am unsure how to access the server with this setup, which I can't really get changed. I've tried putting this into the Datagrip datasource dialogs, but haven't seen if it's possible yet. I feel it may require a port forward in some fashion, but no luck as of yet.

Any suggestions? Thanks!

Note that I feel this is probalby more of a kubernetes question than a Datagrip one, but thought I might be wrong, lol. 

0
2 comments

You're right, it's kubernetes configuration question. You have to expose PG port outside the pod, then you can connect. or you can set up some SSH tunnel to PG host...

0

cool - thanks for the feedback - I'll try playing with that 

0

Please sign in to leave a comment.