Lab: Deploy Managed and Networked Applications on Kubernetes

·

3 min read

Deploy a database server and a web application that connects to that database and expose the web application to external access.

Outcomes

  • Deploy a MySQL database from a container image.

  • Deploy a web application from a container image.

  • Configure environment variables for a deployment.

  • Expose the web application for external access.

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

This command ensures that the cluster is accessible and that all exercise resources are available. It also creates the database-applications project.

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

Procedure 4.5. Instructions

The API URL of your OpenShift cluster is https://api.ocp4.example.com:6443, and the oc command is already installed on your workstation machine.

Log in to the OpenShift cluster as the developer user with the developer password.

Use the database-applications project for your work.

  1. Log in to the OpenShift cluster and change to the database-applications project.

    Show Solution

  2. Create a MySQL database deployment named mysql-app by using the registry.ocp4.example.com:8443/redhattraining/mysql-app:v1 image, and identify the root cause of the failure.

    Show Solution

  3. Configure the environment variables for the mysql-app deployment by using the following information:

    | Field | Value | | --- | --- | | MYSQL_USER | redhat | | MYSQL_PASSWORD | redhat123 | | MYSQL_DATABASE | world_x |

    Then, execute the following command in the mysql-app deployment pod to load the world_x database:

     /bin/bash -c "mysql -uredhat -predhat123 </tmp/world_x.sql"
    

    Show Solution

  4. Create a service for the mysql-app deployment by using the following information:

    | Field | Value | | --- | --- | | Name | mysql-service | | Port | 3306 | | Target port | 3306 |

    Show Solution

  5. Create a web application deployment named php-app by using the registry.ocp4.example.com:8443/redhattraining/php-webapp:v1 image.

    Show Solution

  6. Create a service for the php-app deployment by using the following information:

    | Field | Value | | --- | --- | | Name | php-svc | | Port | 8080 | | Target port | 8080 |

    Then, create a route named phpapp to expose the web application to external access.

    Show Solution

  7. Test the connectivity between the web application and the MySQL database. In a web browser, navigate to the phpapp-web-app.apps.ocp4.example.com route, and verify that the application retrieves data from the MySQL database.

Show Solution

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