Skip to main content
In this lesson we walk through systematic troubleshooting of a simple two-tier web + MySQL application deployed across multiple Kubernetes namespaces. The objective in each namespace is to get the web UI to display a green page — indicating a successful DB connection. For each failing app we:
  • 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-service and backed by a single mysql Pod.
When the web UI shows a red/failed page it prints the application error including DB host, DB user, DB password and the MySQL client error (e.g. DNS failure, connection refused, or access denied). Use that information to narrow your investigation.
A split-screen screenshot: the left side shows a vertical architecture diagram of a web and MySQL stack with labels like web-service, webapp-mysql, mysql-service and ports (8080, 3306, 30081). The right side shows a dark terminal window with a shell prompt reading "controlplane ~".

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 to alpha):
The web UI returned HTML indicating the configured DB host and the DNS error:
Inspect the Deployment environment variables to see which DB host the app expects:
Root cause: the cluster had a Service named 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:
Applied commands:
Result: after recreating the Service as 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:
Root cause: the Service’s 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:
Commands:
Result: with 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:
Check Pod labels for the MySQL Pod:
Root cause: the Service selector 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:
Apply the change and verify:
Result: endpoints appeared and the app connected.

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:
Root cause: the web app was configured to use 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:
Result: new Pod used the corrected credentials and the app connected.

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:
Root cause: the MySQL Pod was started with a different 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.
Example commands:
Result: after restarting MySQL with the correct password the web app connected.
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 showed 1045 Access denied. Steps and fixes:
  1. NodePort mismatch:
  • The web-service NodePort was set to 30088 but the test environment expected 30081. Either access the configured nodePort, or recreate the Service with the desired NodePort (note: NodePort can be immutable on some clusters).
  1. 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 matching MYSQL_ROOT_PASSWORD.
Example workflow:
Result: after fixing NodePort, Deployment env vars, and MySQL password the application connected successfully.

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 svc and kubectl describe deployment to inspect environment variables.
  • Port mapping:
    • Ensure port and targetPort are correct for the backend process.
    • kubectl describe svc <service> shows Port and TargetPort.
  • Service selectors & endpoints:
    • Confirm Service selector labels match the Pod labels.
    • Check kubectl describe svc <service> for Endpoints (should be <ip>:<port>).
  • Credentials:
    • Validate DB user and password in the application Deployment match the DB server.
    • Use kubectl describe deployment and kubectl describe pod mysql to inspect env vars.
  • NodePort / external access:
    • Verify the NodePort you are using maps to the expected port (e.g., 30081).
    • kubectl get svc web-service shows 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



Final notes

  • Always verify Service endpoints after changes: kubectl describe svc <service> and ensure Endpoints are 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.

Watch Video