Bookmark this page

Lab: Deploying Simple Applications

Deploy applications by using the Red Hat OpenShift web console and CLI tools.

Use the Red Hat OpenShift web console to troubleshoot a failing application.

Outcomes

  • Deploy a database by using a container image in the Web Console.

  • Deploy an application with a container image by using the oc command.

  • Debug the application's failure by using the Web Console.

As the student user on the workstation machine, use the lab command to prepare your system for this exercise.

[student@workstation ~]$ lab start deploy-review

This command creates the deploy-review project in the Red Hat OpenShift Container Platform (RHOCP) cluster.

Instructions

This Lab uses two services, a PostgreSQL database and an application that connects to the database.

In the following table you can find the required parameters to create the intended Quarkus application.

Database Service Name postgresql
PostgreSQL Connection Username developer
PostgreSQL Connection Password test
PostgreSQL Database Name todo_list
Application Name todo-list
Application Image registry.ocp4.example.com:8443/redhattraining/openshift-dev-deploy-review-todo-list
  1. Log in to RHOCP and select the developer perspective.

    1. Open a web browser and navigate to https://console-openshift-console.apps.ocp4.example.com. Click htpasswd_provider and log in as the developer user with the developer password.

    2. From the side menu, click Developer to ensure that you use the developer perspective.

    3. Ensure that the selected project is deploy-review.

  2. Deploy the internal Postgresql database by using a Template in the Web Console.

    1. Click +Add to open the Add page.

    2. Under the Developer Catalog card, click Database.

    3. Type postgresql in the Filter by keyword input.

    4. Select the PostgreSQL (Ephemeral) template.

    5. In the side panel that opens, click Instantiate Template.

    6. Use the required parameters to complete the form.

    7. Click Create to start the database deployment.

    8. In the topology view, verify that the postgresql database is running after a few seconds. The postgresql icon must display a dark blue circle, which indicates that the database pod is running.

  3. Use the oc command to deploy the application's container image and create a route.

    1. Run the oc login command with the developer user and the developer password.

      [student@workstation ~]$ oc login -u developer -p developer \
          https://api.ocp4.example.com:6443
      Login successful.
      
      ...output omitted...
    2. Ensure that you are on the deploy-review project.

      [student@workstation ~]$ oc project deploy-review
      ...output omitted...
    3. Run the oc new-app command with the container image URL parameter.

      [student@workstation ~]$ oc new-app --name=todo-list \
      registry.ocp4.example.com:8443/redhattraining/openshift-dev-deploy-review-todo-list
      --> Found container image 25bd8d5 ...
      ...output omitted...
      --> Success
          Application is not exposed. You can expose services to the outside world by executing one or more of the commands below:
           'oc expose service/todo-list'
          Run 'oc status' to view your app.

      Note

      You can safely ignore pod security warnings for exercises in this course. OpenShift uses the Security Context Constraints controller to provide safe defaults for pod security.

    4. Create the route for the application by using the oc expose command:

      [student@workstation ~]$ oc expose service/todo-list
      route.route.openshift.io/todo-list exposed
  4. Test the application and verify that it does not work.

    1. Retrieve the list of items by running the following command:

      [student@workstation ~]$ curl -s \
      http://todo-list-deploy-review.apps.ocp4.example.com/todos
      ...output omitted...
            <h1>Application is not available</h1>
      ...output omitted...
  5. Use the Web Console to browse the application's logs to find out the root cause of the failure.

    1. In the RHOCP Web Console, on the left panel, click Topology.

    2. Click the todo-list pod, which should include a red circle around it, indicating that the pod is failing.

    3. Under Resources, Pods click View logs. The error in the logs must be: Error: could not connect to the database:error: password authentication failed for user "developer".

  6. Use the oc command to delete all the application's objects.

    1. Return to the terminal and delete all the application's objects with the following command:

      [student@workstation ~]$ oc delete all -l app=todo-list
      service "todo-list" deleted.
      deployment.apps "todo-list" deleted
      imagestream.image.openshift.io "todo-list" deleted
  7. Use the oc command to deploy the application by adding the DB_PASSWORD environmental variable with the correct password test, and create the applications's route.

    1. Run the oc new-app command with the container image URL parameter.

      [student@workstation ~]$ oc new-app -e DB_PASSWORD=test --name=todo-list \
      registry.ocp4.example.com:8443/redhattraining/openshift-dev-deploy-review-todo-list
      --> Found container image 7ac26b7 ...
      ...output omitted...
      --> Success
          Application is not exposed. You can expose services to the outside world by executing one or more of the commands below:
           'oc expose service/todo-list'
          Run 'oc status' to view your app.
    2. Create the route for the application by using the oc expose command:

      [student@workstation ~]$ oc expose service/todo-list
      route.route.openshift.io/todo-list exposed
  8. Verify that the issue is fixed and that the application responds correctly.

    1. Test that the application can create items.

      [student@workstation ~]$ curl -i -H "Content-Type: application/json" \
      http://todo-list-deploy-review.apps.ocp4.example.com/todos \
      --data '{ "task": "do laundry" }'
      HTTP/1.1 201 Created
      ...output omitted...
    2. Retrieve the list of items by running the following command:

      [student@workstation ~]$ curl -s \
      http://todo-list-deploy-review.apps.ocp4.example.com/todos; echo
      [{"id":1,"task":"do laundry"}]

Evaluation

As the student user on the workstation machine, use the lab command to grade your work. Correct any reported failures and rerun the command until successful.

[student@workstation ~]$ lab grade deploy-review

Finish

As the student user on the workstation machine, use the lab command to complete this exercise. This step is important to ensure that resources from previous exercises do not impact upcoming exercises.

[student@workstation ~]$ lab finish deploy-review

Revision: do288-4.12-0d49506