I always end up reinventing the wheel when setting up Readiness- & LivenessProbes for Postgres deployments on Kubernetes, which is why I decided to share it here for others to enjoy too.
As you'd like to use environment variables, make sure to prefix the readiness and liveness commands with bash -c
:
readinessProbe:
exec:
command: ["bash", "-c", "psql -w -U $POSTGRES_USER -d $POSTGRES_DB SELECT 1"]
initialDelaySeconds: 15
timeoutSeconds: 2