Skip to main content
This document outlines a comprehensive troubleshooting session for a two-tier application deployed across several namespaces. The goal of each deployment is to display a green webpage upon successful connection. Throughout this session, we inspect environment variables, service configurations, deployment settings, and port mappings to systematically identify and resolve the issues. The following cases illustrate the debugging process in each namespace.

Case 1: Alpha Namespace

In the alpha namespace, although the UI loads, the application state shows as failed. The error message indicates:
This error suggests that the application is unable to resolve the MySQL service name. The architecture diagram below outlines the two-tier design. The web service listens on port 8080 and is exposed via NodePort 30081, requiring a connection to the MySQL service.
The image shows a network diagram with components labeled web-service, webapp-mysql, mysql-service, and mysql, connected by arrows indicating data flow and port numbers.

Troubleshooting Steps

  1. Check Pods in the Alpha Namespace Verify that the pods in the alpha namespace are running correctly.
  2. Set Default Namespace to Alpha To prevent repeatedly specifying the namespace, execute:
  3. Inspect Deployments and Services Confirm that the web application is deployed as a deployment and that the services for both the web application and MySQL exist.
    • To check deployments:
    • To check services:
  4. Resolve MySQL Name Resolution Issue The error occurs because the application expects the MySQL service name to be mysql-service, but the actual service is named mysql. To fix this, update the MySQL service to match the expected name:
    • Create a YAML file (for example, /tmp/kubectl-edit-3970124164.yaml) with the following content:
    • Then, run:
    • Verify the changes:
After these corrections, the application is able to successfully connect to the MySQL service.

Case 2: Beta Namespace

In the beta namespace, the tutor application initially fails with the following error message:

Troubleshooting Steps

  1. Switch Context to Beta
  2. Verify Pods and Services
    • Check the pods:
    • Check the services:
  3. Inspect Deployment for Environment Variables Ensure that the deployment’s configuration sets DB_Host to mysql-service:
  4. Fix Target Port Mismatch The issue was caused by a mismatch in port configuration; the MySQL service’s targetPort was set to 8080 rather than 3306. Update the service configuration:
    • Sample YAML configuration:
    • After editing, verify the update:
The adjustment of the target port enables the application to correctly connect to the MySQL service.

Case 3: Gamma Namespace

In the gamma namespace, both pods and services report running status, yet the application initially fails to load.

Troubleshooting Steps

  1. Switch Context to Gamma
  2. Verify Pods and Services
    • Inspect pods:
    • Inspect services:
  3. Examine the Web Service Configuration Confirm that the selectors and endpoints are set properly by describing the service:
    The output should indicate that the web service on port 8080 (exposed via NodePort 30081) correctly maps to the pod IP address (e.g., 10.42.0.1:8080).
  4. Review the Deployment Configuration Verify that the deployment’s environment variables (DB_Host, DB_User, DB_Password) and image configuration are correct:
  5. Check the MySQL Service Selector If endpoints are missing from the MySQL service, confirm that its selector matches the MySQL pod labels. If necessary, adjust the selector:
After these checks and adjustments, connectivity is restored, and the application becomes accessible.

Case 4: Delta Namespace

The delta namespace presents two issues. Initially, the application shows a connection error:
A subsequent error indicates “access denied for user sql-user,” implying incorrect credentials.

Troubleshooting Steps

  1. Switch Context to Delta
  2. Check Pods and Services
    • Inspect pods:
    • Inspect services:
  3. Review and Update Deployment Credentials Describing the deployment shows that DB_User is set as sql-user:
    To resolve the credential issue (the correct user should be root), edit the deployment:
    Change DB_User from sql-user to root and save the modification.
  4. Monitor the Pod Update Ensure that the updated pod is running. Once the deployment refreshes, the application should successfully connect to the MySQL service.

Case 5: Epsilon Namespace

In the epsilon namespace, the initial error encountered is an “Access denied” message:

Troubleshooting Steps

  1. Switch Context to Epsilon
  2. Verify Pods Confirm that both MySQL and the web application pods are running:
  3. Edit Deployment for Correct Credentials Access and modify the deployment to change DB_User from sql-user to root:
    After updating and saving, verify that the error now reflects the root user.
  4. Check MySQL Pod Configuration Describe the MySQL pod to confirm the MYSQL_ROOT_PASSWORD:
    If the MYSQL_ROOT_PASSWORD does not match paswrd as expected, update the MySQL configuration. Since changing pod configurations may require recreating the pod, use the command below:
After these modifications, the application within the epsilon namespace connects successfully.
In production, environment variables are best managed with ConfigMaps and Secrets rather than being hard-coded in deployments.
An image below illustrates the troubleshooting process in the epsilon namespace:
The image shows a troubleshooting task for a two-tier application in the "epsilon" namespace, with a terminal and architecture diagram.

Case 6: Zeta Namespace

The zeta namespace initially returned a “Bad Gateway” error.

Troubleshooting Steps

  1. Switch Context to Zeta
  2. Inspect the Web Service Configuration On examining the service, it was discovered that the NodePort was set incorrectly (e.g., 30088 instead of the required 30081). To update the NodePort, edit the web service with the following YAML:
    Save the file and verify the update:
  3. Update Deployment Credentials An “Access denied” error still appeared, indicating that DB_User was set to sql-user instead of root:
    Edit the deployment to update the credential:
    Change DB_User from sql-user to root and save. Deploy the updated configuration and verify that the pod is running with the correct credentials.
  4. Verify MySQL Pod Password Lastly, check that the MySQL pod’s MYSQL_ROOT_PASSWORD is correctly configured. If it is not, update the value using:
After these corrections, the application in the zeta namespace becomes fully accessible and establishes a successful database connection. An image confirming the successful deployment is shown below:
A green webpage displays a "SUCCESS" message with a thumbs-up icon, showing environment variables for a database connection.

Conclusion

This troubleshooting session illustrates the importance of verifying pod status, inspecting service configurations, and maintaining correct environment variables across Kubernetes namespaces. The table below summarizes the key challenges and their resolutions: Following these systematic troubleshooting methods helps ensure that service names, port configurations, selectors, and credentials are properly set, leading to a successful connection between the web and database components. Happy troubleshooting, and stay tuned for more labs and lessons in upcoming sessions! For more in-depth Kubernetes information, check out the Kubernetes Documentation.

Watch Video