- Inspect the application resources (Deployment / Pod / Service).
- Reproduce the failure (curl the NodePort where applicable).
- Identify the root cause and apply a fix.
- Verify the web application returns the green success page.
Tip: To avoid repeating
-n <namespace> for every kubectl command, set the default namespace for your current context with kubectl config set-context --current --namespace=<namespace>.Quick reference — Useful kubectl commands
Use these as you go through each namespace:Troubleshooting walkthrough by namespace
Below we keep the original sequence and the exact investigation/fix examples so you can reproduce the steps.1) Namespace: alpha — DNS / Service name mismatch
Symptom: Web UI loads but shows a red (failed) page. The web app logs show it cannot resolve the MySQL service name. Observed error:mysql-service but the Service is named mysql. In‑cluster DNS requires the Service name to match the hostname the application uses.
Fix applied:
- Delete or replace the Service so its name matches the DB host used by the app. Example:
2) Namespace: beta — Service targetPort wrong (3306 vs 8080)
Symptom: Web app reports connection refused when trying to reach MySQL.
Observed:
- Edit the Service so
targetPort: 3306(match the MySQL container port):
3) Namespace: gamma — Service selector did not match Pod labels (no endpoints)
Symptom: Web page times out and the Service has no endpoints. Investigation:- Edit the Service selector to match the pod labels, or update the pod labels to match the Service selector. Example (edit Service):
4) Namespace: delta — Incorrect DB user configured in web app
Symptom: Web app reports access denied for usersql-user.
Observed:
sql-user, which does not exist or lacks required privileges on the MySQL server. The intended credential is root.
Fix applied:
- Edit the Deployment to set
DB_User: rootand trigger a rollout so the web pod restarts with correct env vars:
- After the Deployment updates and a new pod becomes Ready, refresh the web page — it shows green success.
5) Namespace: epsilon — MySQL root password mismatch
Symptom: Even after DB user is set toroot, the web app still gets access denied. Inspecting the MySQL pod shows its MYSQL_ROOT_PASSWORD differs from the web app’s DB_Password.
Investigation:
- Ensure both the MySQL pod (or its managing controller) and the web deployment use the same credential. Update the MySQL configuration to
MYSQL_ROOT_PASSWORD=paswrdand recreate/redeploy the MySQL Pod so the new password takes effect.
- After MySQL restarts with the matching root password and the web app uses
DB_User=rootandDB_Password=paswrd, the web UI displays the green success page.
Do not store credentials in plain text for production. Use Kubernetes Secrets to manage database credentials and ensure deployments reference the same Secret to avoid drift.
6) Namespace: zeta — NodePort incorrect and credentials mismatch
Symptom: Initially you may see “Bad Gateway” or inability to reach the web app. After fixing NodePort, the web app reports DB access denied. Investigation & fixes:- NodePort mismatch
- Found web-service NodePort was
30088while the environment expects30081. - Fix: Edit the Service to set
nodePort: 30081.
- Found web-service NodePort was
- DB user and password mismatch
- Web Deployment used
DB_User: sql-user. Change it toroot. - MySQL pod had a different
MYSQL_ROOT_PASSWORD. Update MySQL to useMYSQL_ROOT_PASSWORD=paswrdand recreate/restart the pod so the password is applied.
- Web Deployment used
- After correcting the NodePort and synchronizing DB username/password, the web application displays the green success page.
Summary table — Namespace issues & fixes
Troubleshooting checklist (order to follow)
- DNS / Service name: does the Service name match the DB host used by the app?
- Service ports: does Service
portandtargetPortmap to the container port MySQL listens on (3306)? - Service selector: does the selector match the Pod labels so endpoints are populated?
- App credentials: do the app’s DB_USER/DB_PASSWORD match credentials on the MySQL server?
- Service exposure: if you access the web UI via NodePort, is the NodePort value correct?
- Logs: check web app and DB logs for authentication/connection errors; use
kubectl logsandkubectl describeto gather context.
Following the steps above helps you systematically isolate DNS/name issues, connectivity/port mismatches, selector/endpoint errors, NodePort exposure problems, and credential mismatches — the common causes in this lab.