Lab: Manage Storage for Application Configuration and Data
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.
Log in to the OpenShift cluster and change to the
storage-reviewproject.Create a secret named
world-credthat contains the following data:| Field | Value | | --- | --- | | User |
redhat| | Password |redhat123| | Database |world_x|Create a configuration map named
dbfilesby using the~/DO180/labs/storage-review/insertdata.sqlfile.Create a database server deployment named
dbserverby using theregistry.ocp4.example.com:8443/redhattraining/mysql-app:v1container image. Then, set the missing environment variables by using theworld-credsecret.Add a volume to the
dbserverdeployment 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|Create a service for the
dbserverdeployment by using the following information:| Field | Value | | --- | --- | | Name |
mysql-service| | Port |3306| | Target port |3306|Create a web application deployment named
file-sharingby using theregistry.ocp4.example.com:8443/redhattraining/php-webapp-mysql:v1container 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-sharingto expose thefile-sharingweb application to external access. Access thefile-sharingroute in a web browser to test the connection between the web application and the database server.Mount the
dbfilesconfiguration map to thefile-sharingdeployment as a volume namedconfig-map-pvc. Set the mount path to the/home/database-filesdirectory. Then, verify the content of theinsertdata.sqlfile.Add a shared volume to the
file-sharingdeployment. 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-sharingdeployment pod and then use thecpcommand to copy the/home/database-files/insertdata.sqlfile to the/home/sharedfilesdirectory. Then, remove theconfig-map-pvcvolume from thefile-sharingdeployment.Add the
shared-volumePVC to thedbserverdeployment. Then, connect to adbserverdeployment pod and verify the content of the/home/sharedfiles/insertdata.sqlfile.Connect to the database server and execute the
/home/sharedfiles/insertdata.sqlfile to add data to theworld_xdatabase. You can execute the file by using the following command:mysql -u$MYSQL_USER -p$MYSQL_PASSWORD world_x </home/sharedfiles/insertdata.sqlThen, confirm connectivity between the web application and database server by accessing the
file-sharingroute in a web browser.
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
