- Reproduce the failure.
- Inspect application logs and Kubernetes objects (Pods, Deployments, Services).
- Identify the root cause (DNS, port mapping, selectors, credentials, or NodePort mismatch).
- Apply a minimal, targeted fix and verify success.
When troubleshooting, follow a repeatable approach: reproduce the failure, inspect logs and events, verify Service selectors/endpoints and Deployment/Pod environment variables, then apply targeted fixes. Setting the default namespace in your kubectl context can reduce typing.
Overview
This lab uses a two-tier stack:- Web app (Flask) listening on port 8080, exposed externally as a NodePort (30081) via a
web-service. - MySQL server listening on port 3306, exposed as a ClusterIP
mysql-serviceand backed by a singlemysqlPod.

Troubleshooting by namespace
Below are the namespaces examined in sequence. Each section includes the observed symptom, the inspection steps, the root cause, and the applied fix.Namespace: alpha — DNS name mismatch
Symptom (web UI): can’t connect to MySQL server on ‘mysql-service:3306’ (-2 Name does not resolve). Reproduce and inspect (set context toalpha):
mysql (not mysql-service), so the configured host mysql-service did not exist in DNS.
Fix: recreate the Service with the expected name. Because .metadata.name is effectively immutable for Services, delete and recreate the Service with the correct name:
mysql-service the web app could resolve and connect, and the page turned green.
Namespace: beta — targetPort mismatch (connection refused)
Symptom (web UI): 2003: Can’t connect to MySQL server on ‘mysql-service:3306’ (111 Connection refused). Investigation:targetPort was set to 8080, forwarding traffic to port 8080 on the MySQL Pod where nothing was listening. MySQL listens on 3306, so TCP connections were refused.
Fix: change the Service targetPort to 3306 so traffic forwards to the correct port on the Pod. Either use kubectl edit svc mysql-service to update the port mapping or apply an updated manifest:
targetPort matching the MySQL process port, connections succeeded.
Namespace: gamma — Service selector did not match Pod labels (no endpoints)
Symptom: Web UI times out (cannot reach DB). Inspection steps:name=mysql did not match the Pod label name=sql00001, so the Service had no endpoints and requests could not be routed to the Pod.
Fix: edit the Service selector to match the Pod label, or relabel the Pod. Example Service selector update:
Namespace: delta — incorrect DB user configured in the web Deployment (access denied)
Symptom (web UI): 1045 (28000): Access denied for user ‘sql-user’@‘10.42.x.x’ (using password: YES) Investigation:sql-user that did not exist or did not have the required privileges on the MySQL server.
Fix: update the Deployment environment variables to use the correct DB user (for example root) that matches the MySQL server credentials:
Namespace: epsilon — MySQL Pod root password mismatch (access denied)
Symptom: 1045 Access denied for user (web UI shows DB env and the MySQL error). Investigation:MYSQL_ROOT_PASSWORD than the web app expected (paswrd).
Fix approach:
- Prefer editing the controller (Deployment/StatefulSet) that manages the Pod so changes persist. Avoid editing individual Pods in production.
- Update the controller manifest to set the correct password (or, better, switch to a
Secret). - Replace the Pod so the new Pod uses the corrected environment variable.
Do not store production credentials in plain text environment variables in Pod specs. Use
Secrets and reference them from Deployments/StatefulSets. Avoid editing Pods directly; edit controllers so changes persist.Namespace: zeta — NodePort mismatch and combined credential problems
Symptom (initial): Bad Gateway / app not reachable. After fixing NodePort, the app then showed1045 Access denied.
Steps and fixes:
- NodePort mismatch:
- The
web-serviceNodePort was set to30088but the test environment expected30081. Either access the configured nodePort, or recreate the Service with the desired NodePort (note: NodePort can be immutable on some clusters).
- DB credentials mismatch:
- After restoring the correct NodePort, the web app returned
1045 Access denied. Update the web Deployment environment variables to use the correct DB user (e.g.,root), and ensure the MySQL Pod is started with the matchingMYSQL_ROOT_PASSWORD.
Common root causes and quick checks
Use the following checklist when troubleshooting multi-tier connectivity in Kubernetes:-
DNS / Service name:
- Verify the Service name matches the application’s configured host.
kubectl get svcandkubectl describe deploymentto inspect environment variables.
-
Port mapping:
- Ensure
portandtargetPortare correct for the backend process. kubectl describe svc <service>showsPortandTargetPort.
- Ensure
-
Service selectors & endpoints:
- Confirm Service selector labels match the Pod labels.
- Check
kubectl describe svc <service>forEndpoints(should be<ip>:<port>).
-
Credentials:
- Validate DB user and password in the application Deployment match the DB server.
- Use
kubectl describe deploymentandkubectl describe pod mysqlto inspect env vars.
-
NodePort / external access:
- Verify the NodePort you are using maps to the expected port (e.g., 30081).
kubectl get svc web-serviceshows NodePort mapping.
-
Controller vs Pod edits:
- Prefer editing higher-level controllers (Deployment/StatefulSet) rather than Pods directly so changes persist across restarts.
Quick reference table
Links and further reading
- Kubernetes Services & DNS: https://kubernetes.io/docs/concepts/services-networking/service/
- Managing Pods & Deployments: https://kubernetes.io/docs/concepts/workloads/controllers/deployment/
- Secrets best practices: https://kubernetes.io/docs/concepts/configuration/secret/
Final notes
- Always verify Service endpoints after changes:
kubectl describe svc <service>and ensureEndpointsare populated. - Use Secrets for credentials and update controllers (Deployments/StatefulSets) so changes are reproducible.
- A methodical checklist (DNS → ports → selectors → credentials → NodePort) helps quickly isolate and fix multi-tier connectivity issues in Kubernetes.