# Lab: Deploy Managed and Networked Applications on Kubernetes

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.

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

**Procedure 4.5. Instructions**

The API URL of your OpenShift cluster is [https://api.ocp4.example.com:6443](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](https://rol.redhat.com/rol/app/#)
    
2. Create a MySQL database deployment named `mysql-app` by using the [`registry.ocp4.example.com:8443/redhattraining/mysql-app:v1`](http://registry.ocp4.example.com:8443/redhattraining/mysql-app:v1) image, and identify the root cause of the failure.
    
    [Show Solution](https://rol.redhat.com/rol/app/#)
    
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:
    
    ```plaintext
    /bin/bash -c "mysql -uredhat -predhat123 </tmp/world_x.sql"
    ```
    
    [Show Solution](https://rol.redhat.com/rol/app/#)
    
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](https://rol.redhat.com/rol/app/#)
    
5. Create a web application deployment named `php-app` by using the [`registry.ocp4.example.com:8443/redhattraining/php-webapp:v1`](http://registry.ocp4.example.com:8443/redhattraining/php-webapp:v1) image.
    
    [Show Solution](https://rol.redhat.com/rol/app/#)
    
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](https://rol.redhat.com/rol/app/#)
    
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`](http://phpapp-web-app.apps.ocp4.example.com) route, and verify that the application retrieves data from the MySQL database.
    
    1. <table><tbody><tr><td colspan="1" rowspan="1"><p></p></td></tr></tbody></table>
        
    
    [Show Solution](https://rol.redhat.com/rol/app/#)
    

**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.

```plaintext
[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.

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