Lab: Manage Storage for Application Configuration and Data

·

4 min read

Deploy a web application and its database that share database credentials from a secret. The database should use the default storage for the cluster. Also deploy a file-sharing application that runs with multiple replicas and shares its storage volume with a file uploader application. The file sharing and file uploader applications take configuration files from a config map and should use NFS file storage for shareability. The database should use local storage for increased and performance.

Outcomes

  • Deploy a database server.

  • Deploy a web application.

  • Create a secret that contains the database server credentials.

  • Create a configuration map that contains an SQL file.

  • Add and remove a volume on the database server and the web application.

  • Expose the database server and the web application.

  • Scale up the web application.

  • Mount the configuration map as a volume.

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 storage-review project, and it creates files that this lab uses, in the /home/student/DO180/labs/storage-review directory.

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

Procedure 5.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 storage-review project for your work.

  1. Log in to the OpenShift cluster and change to the storage-review project.

    Show Solution

  2. Create a secret named world-cred that contains the following data:

    | Field | Value | | --- | --- | | User | redhat | | Password | redhat123 | | Database | world_x |

    Show Solution

  3. Create a configuration map named dbfiles by using the ~/DO180/labs/storage-review/insertdata.sql file.

    Show Solution

  4. Create a database server deployment named dbserver by using the registry.ocp4.example.com:8443/redhattraining/mysql-app:v1 container image. Then, set the missing environment variables by using the world-cred secret.

    Show Solution

  5. Add a volume to the dbserver deployment by using the following information:

    | Field | Value | | --- | --- | | Name | dbserver-lvm | | Type | persistentVolumeClaim | | Claim mode | rwo | | Claim size | 1Gi | | Mount path | /var/lib/mysql | | Claim class | lvms-vg1 | | Claim name | dbserver-lvm-pvc |

    Show Solution

  6. Create a service for the dbserver deployment by using the following information:

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

    Show Solution

  7. Create a web application deployment named file-sharing by using the registry.ocp4.example.com:8443/redhattraining/php-webapp-mysql:v1 container image. Scale the deployment to two replicas. Then, expose the deployment by using the following information:

    | Field | Value | | --- | --- | | Name | file-sharing | | Port | 8080 | | Target port | 8080 |

    Create a route named file-sharing to expose the file-sharing web application to external access. Access the file-sharing route in a web browser to test the connection between the web application and the database server.

    Show Solution

  8. Mount the dbfiles configuration map to the file-sharing deployment as a volume named config-map-pvc. Set the mount path to the /home/database-files directory. Then, verify the content of the insertdata.sql file.

    Show Solution

  9. Add a shared volume to the file-sharing deployment. Use the following information to create the volume:

    | Field | Value | | --- | --- | | Name | shared-volume | | Type | persistentVolumeClaim | | Claim mode | rwo | | Claim size | 1Gi | | Mount path | /home/sharedfiles | | Claim class | nfs-storage | | Claim name | shared-pvc |

    Next, connect to a file-sharing deployment pod and then use the cp command to copy the /home/database-files/insertdata.sql file to the /home/sharedfiles directory. Then, remove the config-map-pvc volume from the file-sharing deployment.

    Show Solution

  10. Add the shared-volume PVC to the dbserver deployment. Then, connect to a dbserver deployment pod and verify the content of the /home/sharedfiles/insertdata.sql file.

    Show Solution

  11. Connect to the database server and execute the /home/sharedfiles/insertdata.sql file to add data to the world_x database. You can execute the file by using the following command:

    mysql -u$MYSQL_USER -p$MYSQL_PASSWORD world_x </home/sharedfiles/insertdata.sql
    

    Then, confirm connectivity between the web application and database server by accessing the file-sharing route in a web browser.

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 storage-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 storage-review