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-review
project.Create a secret named
world-cred
that contains the following data:| Field | Value | | --- | --- | | User |
redhat
| | Password |redhat123
| | Database |world_x
|Create a configuration map named
dbfiles
by using the~/DO180/labs/storage-review/insertdata.sql
file.Create a database server deployment named
dbserver
by using theregistry.ocp4.example.com:8443/redhattraining/mysql-app:v1
container image. Then, set the missing environment variables by using theworld-cred
secret.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
|Create a service for the
dbserver
deployment by using the following information:| Field | Value | | --- | --- | | Name |
mysql-service
| | Port |3306
| | Target port |3306
|Create a web application deployment named
file-sharing
by using theregistry.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 thefile-sharing
web application to external access. Access thefile-sharing
route in a web browser to test the connection between the web application and the database server.Mount the
dbfiles
configuration map to thefile-sharing
deployment as a volume namedconfig-map-pvc
. Set the mount path to the/home/database-files
directory. Then, verify the content of theinsertdata.sql
file.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 thecp
command to copy the/home/database-files/insertdata.sql
file to the/home/sharedfiles
directory. Then, remove theconfig-map-pvc
volume from thefile-sharing
deployment.Add the
shared-volume
PVC to thedbserver
deployment. Then, connect to adbserver
deployment pod and verify the content of the/home/sharedfiles/insertdata.sql
file.Connect to the database server and execute the
/home/sharedfiles/insertdata.sql
file to add data to theworld_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.
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