Read more

HowTo: Get postgres shell in kubernetes

Florian Heinle
August 25, 2022Software engineer at makandra GmbH

If your postgres database is only accessible from inside a kubernetes cluster, e.g. if it's configured in AWS RDS and not available to the public (as it should be!), here's how to open a psql shell inside Kubernetes and connect to the database. Make sure to replace the variables appropriately.

$ kubectl run postgresql-client \
  --image=postgres      \
  --namespace=$NAMESPACE \
  --stdin=true --tty=true \
  --rm=true                \
  --env="PGPASSWORD=$PASSWORD_FOR_POSTGRES \
  --command -- \
  psql --host=$HOSTNAME_FOR_POSTGRES --username=$USERNAME_FOR_POSTGRES $DATABASE_FOR_POSTGRES
Illustration UI/UX Design

UI/UX Design by makandra brand

We make sure that your target audience has the best possible experience with your digital product. You get:

  • Design tailored to your audience
  • Proven processes customized to your needs
  • An expert team of experienced designers
Read more Show archive.org snapshot

You need to specify the password as an env variable for the container since you can't answer the password prompt in the container.

If you don't immediately see a postgres shell, wait a few seconds and press enter.

The pod will automatically be deleted when the shell closes.

Posted by Florian Heinle to makandra Operations (2022-08-25 13:54)