The app gets "password authentication failed" or "Access denied" from the database. What do you check?
IntermediateTroubleshootingDatabase connections in apps
Answer
Short answer
The network path works — the server answered — but login was rejected. Check the username and password actually reaching the app (env var/secret value, typos, trailing newline, URL-encoding), whether the user exists for that host, whether the password was rotated, and database-specific rules like PostgreSQL's pg_hba.conf or MySQL's 'user'@'host'.
Checklist
- What the app really has:
Secrets created withkubectl exec deploy/orders -- printenv | grep DB_ kubectl get secret orders-db -o jsonpath='{.data.password}' | base64 -d | od -c | tail -2 # trailing \n?echo "pass" | base64include a newline — useecho -n. - Test the same credentials manually with
psql/mysqlfrom the pod. - User/host rules:
- MySQL:
SELECT user, host FROM mysql.user;—'app'@'localhost'can't log in from10.0.1.5. - Postgres:
no pg_hba.conf entry→ add a rule; role needsLOGIN.
- MySQL:
- Rotation — was the password rotated in the vault but the pods still use the old one? Restart pods or use a reloader.
- Special characters not URL-encoded in the connection string.
- Wrong database / authSource (MongoDB needs
authSource=adminfor admin-created users).
What to say in the interview
"Authentication errors mean the network is fine. I verify the exact secret value inside the pod — trailing newlines and URL-encoding are classic — test it with the CLI client, then check host-based rules like MySQL user@host or pg_hba.conf, and whether a rotation left pods with a stale password."
More on Database connections in apps
How does an application connect to a database, and how should connection details be passed?BeginnerAfter deployment, the app can't connect to the database. How do you troubleshoot it?IntermediateWhat is a connection string? Explain its parts.BeginnerWhat are the default ports for common databases?BeginnerWhy should database credentials never be stored in code or Git?BeginnerHow do Kubernetes Secrets work, and are they secure?Intermediate