OpenShift Hands-On Lab - Troubleshooting a Containerized Application

OpenShift Hands-On Lab - Troubleshooting a Containerized Application

OpenShift Learning Path for Cloud and DevOps Engineers

📝Introduction

In this lab scenario, a containerized application is not working properly and needs to be fixed. Using the various logs available, we will troubleshoot, fix it, and start the application using a simple method.

These are the objectives of this lab:

  • Create the New Project

📌Note: This section only applies to students using CodeReady Containers. Skip this section if you are using Red Hat OpenShift sandbox.

  • Replicate the Issue with the Application

  • Troubleshoot and Fix the Application

  • Verify the Application Is Running

📌Note: Due to resource limitations in my Cloud Playground environment, I used the below Red Hat free online resources available for this lab.

  1. To complete this lab, you must first register for a Red Hat Developer login on theRed Hat login page.

  2. Once registered, you may complete the lab steps usingRed Hat's CodeReady Containers or the Red Hat-provided OpenShift sandbox.

Solutions for CodeReady Containers and the Red Hat OpenShift sandbox can be used in this lab. However, I decided to use the free Red Hat-provided OpenShift sandbox available for 30 days.

📝Set Up CodeReady Containers (For those who choose to run it locally)

📌Note: CodeReady Containers has specific hardware and operating system requirements. To ensure your environment is compatible, seeRed Hat's minimum system requirements for CodeReady Containers.

  1. Navigate and log in to your Red Hat Developer account.

  2. Under the Local tab, select your OS and click Download CodeReady Containers.

  3. Click Copy Pull Secret for later use.

  4. Install CodeReady Containers.

    📌*Note:For OS-specific installation instructions, see [Red Hat's CodeReady Containers installation guide](access.redhat.com/documentation/en-us/red_h..).*

  5. Open a terminal session and set up CodeReady Containers:

     crc setup
    
  6. When prompted, enter yes to enable telemetry data collection or no to disable telemetry data collection.

  7. Start the VM:

     crc start
    

    📌Note: The cluster takes a minimum of 4 minutes to start before serving a request.

  8. When prompted, paste in the previously copied pull request and press Enter.

  9. Print the command needed to add the cached oc executable to your $PATH:

     crc oc-env
    
  10. Run the printed command.

  11. Log in as the developer user:

    oc login -u developer https://api.crc.testing:6443
    

📝Set Up an OpenShift Sandbox (For those who choose to run it online on the Cloud. This was my choice).

  1. To log in through the web UI directly, navigate to the Red Hat CodeReady Containers page and log in to your Red Hat Developer account with the credentials you created.

  2. Select Try OpenShift in our free sandbox.

  3. Click Launch your Developer Sandbox for Red Hat OpenShift.

  4. To confirm your account, enter a valid phone number and click Send Code.

  5. Enter the verification code you received and click Verify Code.

  6. Click Start using your sandbox.

  7. Under Log in with, click DevSandbox.

  8. Select the I have read and agree to the Red Hat OpenShift Online Services Agreement and click SUBMIT.

  9. At the top right, click the shell icon (>_).

  10. Leave the default project selected and click Start. Note: You will not be able to create new projects in the sandbox. For any steps in the lab stating you need to create a new project, skip that step and ensure you use one of the existing projects: <username>-dev, or <username>-stage.

    📌Note: Type q to exit a menu or log.

📝Log In to the Cluster (Option 1)

📌Note: This section only applies to students using CodeReady Containers. Otherwise, skip to the next objective.

  1. Log in to the cluster:

     oc login -u developer https://api.crc.testing:6443
    
  2. In a new browser, log in to the cluster using the console URL.

  3. Use thedeveloper credentials to log in.

📝Log In to the Cluster (Option 2)

📌Note: To complete a login using oc in the OpenShift sandbox, click on the shell (>_) icon. Alternatively, you can download the binary and log in from a remote system (e.g. VSCode). Please review the  Using Red Hat OpenShift Sandbox  video detailing the necessary steps for that process.

📝Replicate the Issue with the Application

  1. Paste in the command provided to replicate the error:
oc new-app --name=secret-db mysql mysql_root_pass=supersecret -l app=secret-db
  1. Clear your screen:
clear
  1. View the resources:
oc get all

📝Troubleshoot and Fix the Application

CodeReady Containers

  1. Check the logs of the pod:

     oc logs <POD_NAME> | less
    
  2. clear your screen.

  3. Correct the error by updating the deployment with the correct format:

     oc set env deployment secret-db MYSQL_ROOT_PASSWORD=supersecret
    
  4. clear your screen.

OpenShift Sandbox

  1. Check the logs of the pod:

     oc logs <POD_NAME>
    
  2. Go back and clear your screen by pressing q, then typing clear.

  3. Display the resources:

     oc get deployments
    
  4. Correct the error by updating the deployment with the correct format:

     oc set env deployment secret-db MYSQL_ROOT_PASSWORD=supersecret
     #When we created the app previoulsy the parameter for MYSQL_ROOT_PASSWORD was in the lowercase and the log was informing us what might be wrong.
     #Now we have fixed by running the correct parameter.
    
  5. clear your screen.

📝Verify the Application Is Running

CodeReady Containers

  1. View the resources and confirm the new pod is running:

     oc get all
    
  2. Check the logs for the new pod:

     oc logs <POD_NAME>
    
  3. At the bottom of the page, you should see mysqld is ready for connection.

  4. clear your screen.

  5. Verify that the mysqld instance is ready for connection:

     oc rsh <NEW_POD_NAME>
    
  6. Connect to the instance:

     mysql -uroot
    

OpenShift Sandbox

  1. View the resources and confirm the new pod is running:

     oc get pods
    
  2. Check the logs for the new pod:

     oc logs <NEW_POD_NAME> | less
    
  3. At the bottom of the page, you should see mysqld is ready for connection.

  4. Go back by pressing q.

  5. Verify that the mysqld instance is ready for connection:

     oc rsh <NEW_POD_NAME>
    
  6. Connect to the instance:

     mysql -uroot
    
  7. Check MySQL tables:

     show databases;
     exit
     exit
    

📌Note - At the end of each hands-on Lab, always clean up all previous resources created to avoid being charged if you used a Cloud Provider to provision them.

Congratulations — you have completed this hands-on lab covering the basics of using the various logs available to troubleshoot the issue, fix it, and start the application.

Thank you for reading. I hope you understood and learned something helpful from my blog.

Please follow me on CloudDevOpsToLearn and LinkedIn, franciscojblsouza