Deploy a web server taking configuration files from a configuration map.
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 webconfig from the web console.
Use the registry.ocp4.example.com:8443/rhscl/httpd-24-rhel7:latest container image.
Log in to the OpenShift cluster as the developer user with the developer password by using the OpenShift web console https://console-openshift-console.apps.ocp4.example.com URL.
Change to the perspective, and change to the storage-configs project.
Select the → option and click the button.
Add the webconfig deployment name and the image 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-svc
|
| App selector |
webconfig
|
| Port number |
8080
|
| Target port |
8080
|
| Route field | Route value |
|---|---|
| Route name |
webconfig-rt
|
| Service name |
webconfig-svc
|
| Target port |
8080
|
Select the → option and click the button to create the webconfig-svc service that exposes the webconfig deployment.
Verify the status of the service.
![]() |
Select the → option and click the button to create the webconfig-rt service that exposes the webconfig-svc service.
![]() |
Use a web browser to navigate to the http://webconfig-rt-storage-configs.apps.ocp4.example.com route.
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.
Select the → option and click the button to create the webfiles configuration map by using the redhatlogo.png file and the index.html file in the /home/DO180/labs/storage-configs directory, and verify the creation of the configuration map.
Add a key, define the index.html name as the value, and open the /home/DO180/labs/storage-configs/index.html file.
![]() |
Add a key, define the redhatlogo.png name as the value, and open the /home/DO180/labs/storage-configs/redhatlogo.png file.
![]() |
Log in to the OpenShift cluster from the command line, and mount the webfiles configuration map as a volume in the webconfig deployment from the command line.
Log in to the OpenShift cluster as the developer user with the developer password.
[student@workstation ~]$ oc login -u developer -p developer \
https://api.ocp4.example.com:6443
..output omitted...Mount the webfiles configuration 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/redhattraining/httpd-noimage:v2
deployment #2 running for 2 minutes - 1 pod
deployment #1 deployed 17 minutes ago
...output omitted...[student@workstation ~]$ oc get pods
NAME 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.com route.
Click the link to open the file.
![]() |
The configuration map successfully added the missing files to the web application.