It is a good practice to always define liveness and readiness probes on all you Kubernetes deployments. A simple “SELECT 1;” is good enough to establish that DB pod is ready to accept connections. The probes for that may look like this:
readinessProbe:
exec:
command: ["psql", "-w", "-U", "abcd", "-d", "my-db", "-c", "SELECT 1"]
initialDelaySeconds: 15
timeoutSeconds: 2
livenessProbe:
exec:
command: ["psql", "-w", "-U", "abcd", "-d", "my-db", "-c", "SELECT 1"]
initialDelaySeconds: 45
timeoutSeconds: 2
In the above example a user “abcd” connects to a database called “my-db”, without a password. The “-w” flag means “never ask for a password”.
If your user does have a password, you can supply it via the
PGPASSWORD
environment variable. Remember to omit the “-w” flag.