Deploy a multi-pod application into Red Hat OpenShift Container Platform (RHOCP).
Outcomes
You should be able to use the oc command-line utility to:
Create RHOCP deployments.
Configure networking.
Expose applications for external access.
As the student user on the workstation machine, use the lab command to prepare your system for this exercise.
[student@workstation ~]$ lab start openshift-multipod
Instructions
Log in to the cluster as the developer user, and ensure that you use the ocp-multipod project.
Log in to the cluster as the developer user.
[student@workstation ~]$ oc login -u developer -p developer \
https://api.ocp4.example.com:6443
Login successful.
...output omitted...Ensure that you use the ocp-multipod project.
[student@workstation ~]$ oc project ocp-multipod
Already on project "ocp-multipod" on server "https://api.ocp4.example.com:6443".Create a Deployment resource for the Gitea application.
Use the oc create deployment command to create the Gitea deployment.
Configure the deployment port 3030 and use the registry.ocp4.example.com:8443/redhattraining/podman-gitea:latest container image.
[student@workstation ~]$ oc create deployment gitea --port 3030 \
--image=registry.ocp4.example.com:8443/redhattraining/podman-gitea:latest
Warning: would violate PodSecurity "restricted:v1.24" ...
...output omitted...
deployment.apps/gitea createdYou can ignore pod security warnings for exercises in this course. Red Hat OpenShift uses the Security Context Constraints controller to provide safe defaults for pod security.
Verify the pod status.
[student@workstation ~]$oc get poNAME READY STATUS RESTARTS AGE gitea-6d446c7b48-b89hz1/1 Running0 75s
If the pod is in the ContainerCreating status, repeat the preceding command after a few seconds.
The preceding command uses the po short name to refer to the pod resource. In the preceding command, the names po, pod, and pods are equivalent.
Create a Deployment resource for a PostgreSQL database called gitea-postgres. The Gitea application uses the database to store data.
You can use the completed file in the ~/DO188/solutions/openshift-multipod directory.
Use the oc create deployment command to create the gitea-postgres database.
Configure the deployment port 5432 and use the registry.ocp4.example.com:8443/rhel9/postgresql-13:1 container image.
Use the --dry-run=client and -o yaml options to generate a YAML file, and redirect the output to the postgres.yaml file.
[student@workstation ~]$oc create deployment gitea-postgres --port 5432 -o yaml \ --image=registry.ocp4.example.com:8443/rhel9/postgresql-13:1 \ --dry-run=client > postgres.yamlno output expected
The preceding command uses output redirection (>) to create the postgres.yaml file.
Open the postgres.yaml file in an editor, such as gedit, and add the following environment variables:
...file omitted...
containers:
- image: registry.ocp4.example.com:8443/rhel9/postgresql-13:1
name: postgresql-13
ports:
- containerPort: 5432
env:
- name: POSTGRESQL_USER
value: gitea
- name: POSTGRESQL_PASSWORD
value: gitea
- name: POSTGRESQL_DATABASE
value: gitea
...file omitted...To get more information about the env property, execute the oc explain deployment.spec.template.spec.containers.env command.
The YAML format is white-space sensitive. You must use correct indentation.
In the preceding example, the env: object indentation is 8 spaces.
Use the oc create command to create the deployment.
[student@workstation ~]$ oc create -f postgres.yaml
Warning: would violate PodSecurity "restricted:v1.24"...
...output omitted...
deployment.apps/gitea-postgres createdIf you receive an error, compare your postgres.yaml file to the complete ~/DO188/solutions/openshift-multipod/postgres.yaml file.
Verify the pod status.
[student@workstation ~]$oc get poNAME READY STATUS RESTARTS AGE gitea-6d446c7b48-rf578 1/1 Running 0 6m18sgitea-postgres-86d47f494d-7rl5g 1/1 Running0 18s
Configure networking for the database.
Expose the PostgreSQL database on the gitea-postgres hostname.
[student@workstation ~]$ oc expose deployment gitea-postgres
service/gitea-postgres exposedVerify that the PostgreSQL service uses the gitea-postgres name and the 5432 port.
[student@workstation ~]$oc get svcNAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGEgitea-postgresClusterIP 172.30.124.174 <none>5432/TCP50s
Configure networking for the Gitea application.
Expose the application within the RHOCP cluster.
[student@workstation ~]$ oc expose deployment gitea
service/gitea exposedExpose the gitea service for external access.
[student@workstation ~]$ oc expose service gitea
route.route.openshift.io/gitea exposedTest your application functionality.
Verify the external URL for your application.
[student@workstation ~]$oc get routeNAME HOST/PORT SERVICES PORT WILDCARD giteagitea-ocp-multipod.apps.ocp4.example.comgitea 3030 None
In a web browser, open the gitea-ocp-multipod.apps.ocp4.example.com URL and use the following configuration:
: PostgreSQL
: gitea-postgres:5432
: gitea
: gitea
: gitea
: gitea-ocp-multipod.apps.ocp4.example.com
: http://gitea-ocp-multipod.apps.ocp4.example.com
Then, click .
This step is successful if you see the login page.
Optionally, click to create a user and log in.
![]() |