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 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
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.Log in to the OpenShift cluster.
[student@workstation ~]$
oc login -u developer -p developer \ https://api.ocp4.example.com:6443...output omitted...Change to the
storage-reviewproject.[student@workstation ~]$
oc project storage-reviewNow using project "storage-review" on server "https://api.ocp4.example.com:6443". ...output omitted...
Create a secret named
world-credthat contains the following data:Field Value userredhatpasswordredhat123databaseworld_xCreate a secret that contains the database credentials.
[student@workstation]$
oc create secret generic world-cred \ --from-literal user=redhat \ --from-literal password=redhat123 \ --from-literal database=world_xsecret/world-cred createdConfirm the creation of the secret.
[student@workstation ~]$
oc get secrets world-credNAME TYPE DATA AGE world-cred Opaque 3 2m34s
Create a configuration map named
dbfilesby using the~/DO180/labs/storage-review/insertdata.sqlfile.Create a configuration map named
dbfilesby using theinsertdata.sqlfile in the~/DO180/labs/storage-reviewdirectory.[student@workstation ~]$
oc create configmap dbfiles \ --from-file ~/DO180/labs/storage-review/insertdata.sqlconfigmap/dbfiles createdVerify the creation of the configuration map.
[student@workstation]$
oc get configmapsNAME DATA AGE dbfiles 1 11s ...output omitted...
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.Create the database server deployment.
[student@workstation ~]$
oc create deployment dbserver \ --image registry.ocp4.example.com:8443/redhattraining/mysql-app:v1deployment.apps/dbserver createdSet the missing environment variables.
[student@workstation ~]$
oc set env deployment/dbserver --from secret/world-cred \ --prefix MYSQL_deployment.apps/dbserver updatedVerify that the
dbserverpod is in theRUNNINGstate. The pod name might differ in your output.[student@workstation ~]$
oc get podsNAME READY STATUS ... dbserver-6d5bf5d86c-ptrb21/1 Running ...
Add a volume to the
dbserverdeployment by using the following information:Field Value name dbserver-lvmtype persistentVolumeClaimclaim mode rwoclaim size 1Gimount path /var/lib/mysqlclaim class lvms-vg1claim name dbserver-lvm-pvcAdd a volume to the
dbserverdeployment.[student@workstation ~]$
oc set volume deployment/dbserver \ --add --name dbserver-lvm --type persistentVolumeClaim \ --claim-mode rwo --claim-size 1Gi --mount-path /var/lib/mysql \ --claim-class lvms-vg1 --claim-name dbserver-lvm-pvcdeployment.apps/dbserver volume updatedVerify the deployment status.
[student@workstation ~]$
oc get podsNAME READY STATUS ... dbserver-5bc6bd5d7b-7z7lv1/1 Running ...Verify the volume status.
[student@workstation ~]$
oc get pvcNAMESTATUSVOLUME CAPACITY ...output omitted... dbserver-lvm-pvcBoundpvc-2cb85025-... 1Gi ...output omitted...
Create a service for the
dbserverdeployment by using the following information:Field Value Name mysql-servicePort 3306Target port 3306Expose the
dbserverdeployment.[student@workstation ~]$
oc expose deployment dbserver --name mysql-service \ --port 3306 --target-port 3306service/mysql-service exposedVerify the service configuration. The endpoint IP address might differ in your output.
[student@workstation ~]$
oc get servicesNAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) ... mysql-service ClusterIP 172.30.240.100 <none> 3306/TCP ...[student@workstation ~]$
oc get endpointsNAME ENDPOINTS ... mysql-service 10.8.1.36: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-sharingPort 8080Target port 8080Create 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.Create a web application deployment.
[student@workstation ~]$
oc create deployment file-sharing \ --image registry.ocp4.example.com:8443/redhattraining/php-webapp-mysql:v1deployment.apps/file-sharing createdVerify the deployment status. Verify that the
file-sharingapplication pod is in theRUNNINGstate. The pod names might differ on your system.[student@workstation ~]$
oc get podsNAME READY STATUS ... dbserver-5bc6bd5d7b-7z7lv1/1 Running ... file-sharing-789c5948c8-gdrlz1/1 Running ...Scale the deployment to two replicas.
[student@workstation ~]$
oc scale deployment file-sharing --replicas 2deployment.apps/file-sharing scaledVerify the replica status and retrieve the pod name. The pod names might differ on your system.
[student@workstation ~]$
oc get podsNAME READY STATUS ... dbserver-5bc6bd5d7b-7z7lv1/1 Running ... file-sharing-789c5948c8-62j9s1/1 Running ... file-sharing-789c5948c8-gdrlz1/1 Running ...Expose the
file-sharingdeployment.[student@workstation ~]$
oc expose deployment file-sharing --name file-sharing \ --port 8080 --target-port 8080service/file-sharing exposedVerify the service configuration. The endpoint IP address might differ in your output.
[student@workstation ~]$
oc get servicesNAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) ... file-sharing ClusterIP 172.30.139.210 <none> 8080/TCP ... mysql-service ClusterIP 172.30.240.100 <none> 3306/TCP ...[student@workstation ~]$
oc get endpointsNAME ENDPOINTS file-sharing 10.8.1.37:8080,10.8.1.38:8080 ... mysql-service 10.8.1.36:3306 ...Expose the
file-sharingservice.[student@workstation ~]$
oc expose service/file-sharingroute.route.openshift.io/file-sharing exposed[student@workstation ~]$
oc get routesNAME HOST/PORT ... SERVICES ... file-sharing file-sharing-storage-review.apps.ocp4.example.com ... file-sharing ...Test the connectivity between the web application and the database server. In a web browser, navigate to
http://file-sharing-storage-review.apps.ocp4.example.com, and verify that aConnected successfullymessage is displayed.
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.Mount the
dbfilesconfiguration map to thefile-sharingdeployment.[student@workstation ~]$
oc set volume deployment/file-sharing \ --add --name config-map-pvc --type configmap \ --configmap-name dbfiles \ --mount-path /home/database-filesdeployment.apps/file-sharing volume updatedVerify the deployment status.
[student@workstation ~]$
oc get podsNAME READY STATUS ... dbserver-5bc6bd5d7b-7z7lv1/1 Running ... file-sharing-7f77855b7f-949lg1/1 Running ... file-sharing-7f77855b7f-9zvwq1/1 Running ...Verify the content of the
/home/database-files/insertdata.sqlfile.[student@workstation ~]$
oc exec -it pod/file-sharing--- MySQL dump 10.13 Distrib 8.0.19, for osx10.14 (x86_64) -- -- Host: 127.0.0.1 Database: world_x -- ------------------------------------------------------ -- Server version 8.0.19-debug ...output omitted...7f77855b7f-949lg-- \ head /home/database-files/insertdata.sql
Add a shared volume to the
file-sharingdeployment. Use the following information to create the volume:Field Value Name shared-volumeType persistentVolumeClaimClaim mode rwoClaim size 1GiMount path /home/sharedfilesClaim class nfs-storageClaim name shared-pvcNext, 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-volumevolume to thefile-sharingdeployment.[student@workstation ~]$
oc set volume deployment/file-sharing \ --add --name shared-volume --type persistentVolumeClaim \ --claim-mode rwo --claim-size 1Gi --mount-path /home/sharedfiles \ --claim-class nfs-storage --claim-name shared-pvcdeployment.apps/file-sharing volume updatedVerify the deployment status. Your pod names might differ on your system.
[student@workstation ~]$
oc get podsNAME READY STATUS ... dbserver-5bc6bd5d7b-7z7lv1/1 Running ... file-sharing-65884f75bb-92fxf1/1 Running ... file-sharing-65884f75bb-gsghk1/1 Running ...Verify the volume status.
[student@workstation ~]$
oc get pvcNAME STATUS VOLUME CAPACITY ACCESS MODES STORAGECLASS dbserver-lvm-pvc Bound pvc-2cb... 1Gi RWO lvms-vg1 ... shared-pvc Bound pvc-cf2... 1Gi RWO nfs-storage ...Copy the
/home/database-files/insertdata.sqlfile to the/home/sharedfilespath.[student@workstation ~]$
oc exec -it pod/file-sharing-65884f75bb-92fxf-- \ cp /home/database-files/insertdata.sql /home/sharedfiles/[student@workstation ~]$
oc exec -it pod/file-sharing-insertdata.sql65884f75bb-92fxf-- \ ls /home/sharedfiles/Remove the
config-map-pvcvolume from thefile-sharingdeployment.[student@workstation ~]$
oc set volume deployment/file-sharing \ --remove --name=config-map-pvcdeployment.apps/file-sharing volume updated
Add the
shared-volumePVC to thedbserverdeployment. Then, connect to adbserverdeployment pod and verify the content of the/home/sharedfiles/insertdata.sqlfile.Add the
shared-volumevolume to thedbserverdeployment.[student@workstation ~]$
oc set volume deployment/dbserver \ --add --name shared-volume \ --claim-name shared-pvc \ --mount-path /home/sharedfilesdeployment.apps/dbserver volume updatedVerify the deployment status. The pod names might differ on your system.
[student@workstation ~]$
oc get podsNAME READY STATUS ... dbserver-6676fbf5fc-n9hpk1/1 Running ... file-sharing-5fdb44cf57-2hhwj1/1 Running ... file-sharing-5fdb44cf57-z4n7g1/1 Running ...Verify the content of the
/home/sharedfiles/insertdata.sqlfile.[student@workstation ~]$
oc exec -it pod/dbserver--- MySQL dump 10.13 Distrib 8.0.19, for osx10.14 (x86_64) -- -- Host: 127.0.0.1 Database: world_x -- ------------------------------------------------------ -- Server version 8.0.19-debug ...output omitted...6676fbf5fc-n9hpk-- \ head /home/sharedfiles/insertdata.sql
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.Connect to the database server and execute the
/home/sharedfiles/insertdata.sqlfile. Then, exit the database server.[student@workstation ~]$
oc rsh dbserver-6676fbf5fc-n9hpksh-4.4$
mysql -u$MYSQL_USER -p$MYSQL_PASSWORD world_x </home/sharedfiles/insertdata.sqlmysql: [Warning] Using a password on the command line interface can be insecure. sh-4.4$exitexitTest the connectivity between the web application and the database server. In a web browser, navigate to
http://file-sharing-storage-review.apps.ocp4.example.com, and verify that the application retrieves data from theworld_xdatabase.