Outcomes
In this exercise, you deploy a web application to mount the missing files from a configuration map.
Create a web application deployment.
Expose the web application deployment to external access.
Create a configuration map from two files.
Mount the configuration map in the web application deployment.
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.
[student@workstation ~]$ lab start storage-configs
Instructions
Create a web application deployment named
webconfigfrom the web console. Use theregistry.ocp4.example.com:8443/rhscl/httpd-24-rhel7:latestcontainer image.Log in to the OpenShift cluster as the
developeruser with thedeveloperpassword by using the OpenShift web consolehttps://console-openshift-console.apps.ocp4.example.comURL.Change to the perspective, and change to the
storage-configsproject. Select the → option and click the button. Add thewebconfigdeployment name and theregistry.ocp4.example.com:8443/rhscl/httpd-24-rhel7:latestimage name, and leave the default for the other values.Select the button. Verify the successful deployment of three pods.
Expose the web application to external access from the web console. Use the following information to create a service and a route for the web application, and leave the hostname and path fields blank.
Service field Service value Service name webconfig-svcApp selector webconfigPort number 8080Target port 8080Route field Route value Route name webconfig-rtService name webconfig-svcTarget port 8080Select the → option and click the button to create the
webconfig-svcservice that exposes thewebconfigdeployment. Update the property values and click . Verify the status of the service.Alternatively, create the service from the CLI by using the
oc expose deploy/webconfig --name 'webconfig-svc' --selector 'app=webconfig' --target-port '8080' --port '8080'command.Select the → option and click the button to create the
webconfig-rtservice that exposes thewebconfig-svcservice. Update the property values and click . Verify the status of the route.Alternatively, create the route from the CLI by using the
oc expose svc/webconfig-svc --name 'webconfig-rt'command.Use a web browser to navigate to the
http://webconfig-rt-storage-configs.apps.ocp4.example.comroute. A testing page is displayed by default because of the missing files.
Use the missing files to create a configuration map from the web console. Use the following information to create the configuration map for the web application:
Configuration map field Value Name webfilesData key index.htmlData value Content from index.html Binary data key redhatlogo.pngBinary data value Non-printable content from the redhatlogo.pngfileSelect the → option and click to view the configuration map form. Using
webfilesfor the name, create the configuration map by using theredhatlogo.pngfile and theindex.htmlfile in the/home/student/DO180/labs/storage-configsdirectory. Add a key, define theindex.htmlname as the value, and open the/home/student/DO180/labs/storage-configs/index.htmlfile to associate the contents of the file with the data key.Add a key, define the
redhatlogo.pngname as the value, and open the/home/student/DO180/labs/storage-configs/redhatlogo.pngfile to associate the binary contents with the binary key.Click to create the configuration map.
Log in to the OpenShift cluster from the command line, and mount the
webfilesconfiguration map as a volume in thewebconfigdeployment from the command line.Log in to the OpenShift cluster as the
developeruser with thedeveloperpassword.[student@workstation ~]$
oc login -u developer -p developer \ https://api.ocp4.example.com:6443..output omitted...Select the
storage-configsproject.[student@workstation ~]$
oc project storage-configsNow using project "storage-configs" on server "https://api.ocp4.example.com:6443".Mount the
webfilesconfiguration map as a volume.[student@workstation ~]$
oc set volume deployment/webconfig \ --add --type configmap --configmap-name webfiles \ --name webfiles-vol --mount-path /var/www/html/deployment.apps/webconfig volume updatedVerify the deployment status. Verify that a new pod was created.
[student@workstation ~]$
oc status...output omitted... http://webconfig-rt-storage-configs.apps.ocp4.example.com to pod port 8080 (svc/webconfig-svc) deployment/webconfig deploys registry.ocp4.example.com:8443/rhscl/httpd-24-rhel7:latest deployment #2 running for 2 minutes - 3 pod deployment #1 deployed 17 minutes ago ...output omitted...[student@workstation ~]$
oc get podsNAME READY STATUS ... webconfig-654bcf6cf-wcnnk 1/1 Running ... ...output omitted...Return to the web browser, and navigate to the
webconfig-rt-storage-configs.apps.ocp4.example.comroute. Click the link to open the file.The configuration map successfully added the missing files to the web application.