Deploy and update an application from resource manifests from YAML files that are stored in a Git server.
Outcomes
Deploy applications from resource manifests from YAML files that are stored in a GitLab repository.
Inspect new manifests for potential update issues.
Update application deployments from new YAML manifests.
Force the redeployment of pods when necessary.
As the student user on the workstation machine, use the lab command to prepare your system for this exercise.
[student@workstation ~]$ lab start declarative-manifests
Instructions
Log in to the OpenShift cluster and create the declarative-manifests 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...Create the declarative-manifests project.
[student@workstation ~]$ oc new-project declarative-manifests
Now using project "declarative-manifests" on server ...
...output omitted...Clone the declarative-manifest project from the Git repository.
Change your directory to the project labs directory.
[student@workstation ~]$ cd ~/DO280/labsClone the Git repository from https://git.ocp4.example.com/developer/declarative-manifests.git.
Use developer for both the username and for the password.
[student@workstation lab]$ git clone \
https://git.ocp4.example.com/developer/declarative-manifests.git
Cloning into 'declarative-manifests'...
remote: Enumerating objects: 24, done.
remote: Counting objects: 100% (24/24), done.
remote: Compressing objects: 100% (21/21), done.
remote: Total 24 (delta 8), reused 0 (delta 0), pack-reused 0
Receiving objects: 100% (24/24), done.
Resolving deltas: 100% (8/8), done.Go to the declarative-manifest directory.
[student@workstation lab]$ cd declarative-manifests
[student@workstation declarative-manifests]$Inspect the contents of the Git repository.
List the contents of the declarative-manifests directory.
[student@workstation declarative-manifests]$ ls -lA
total 12
-rw-rw-r--. 1 student student 3443 Jun 21 16:39 database.yaml
-rw-rw-r--. 1 student student 2278 Jun 21 16:39 exoplanets.yaml
drwxrwxr-x. 8 student student 163 Jun 21 16:39 .git
-rw-rw-r--. 1 student student 0 Jun 21 16:39 .gitkeep
-rw-rw-r--. 1 student student 11 Jun 21 16:39 README.mdList the commits, branches, and tags on the Git repository.
[student@workstation declarative-manifests]$git log --oneline4045336 (HEAD -> main, tag:third, origin/v1.1.1, origin/main, origin/HEAD) Exoplanets v1.1.1ad455b2 Database v1.1.1 821420c (tag:
second, origin/v1.1.0) Exoplanets v1.1.0d9abeb0 (tag:
first, origin/v1.0) Exoplanets v1.0a11396e Database v1.0 e868a90 README 18ddf3c Initial commit
Deploy the resource manifests of the first application version.
Switch to the v1.0 branch, which contains the YAML manifests for the first version of the application.
[student@workstation declarative-manifests]$ git checkout v1.0
branch 'v1.0' set up to track 'origin/v1.0'.
Switched to a new branch 'v1.0'Validate the YAML resource manifest for the application.
[student@workstation declarative-manifests]$ oc apply -f . \
--validate=true --dry-run=server
configmap/database created (server dry run)
secret/database created (server dry run)
deployment.apps/database created (server dry run)
service/database created (server dry run)
configmap/exoplanets created (server dry run)
secret/exoplanets created (server dry run)
deployment.apps/exoplanets created (server dry run)
service/exoplanets created (server dry run)
route.route.openshift.io/exoplanets created (server dry run)Deploy the exoplanets application.
[student@workstation declarative-manifests]$ oc apply -f .
configmap/database created
secret/database created
deployment.apps/database created
service/database created
configmap/exoplanets created
secret/exoplanets created
deployment.apps/exoplanets created
service/exoplanets created
route.route.openshift.io/exoplanets createdList the deployments and pods.
The exoplanets pod can go into a temporary crash loop backoff state if it attempts to access the database before it becomes available.
Wait for the pods to be ready.
Press Ctrl+C to exit the watch command.
[student@workstation declarative-manifests]$watch oc get deployments,podsEvery 2.0s: oc get deployments,pods ... NAMEREADYUP-TO-DATE AVAILABLE AGE deployment.apps/database1/11 1 32s deployment.apps/exoplanets1/11 1 32s NAMEREADYSTATUS RESTARTS AGE pod/database-6fddbbf94f-2pghj1/1Running 0 32s pod/exoplanets-64c87f5796-bw8tm1/1Running 0 32s
List the route for the exoplanets application.
[student@workstation declarative-manifests]$oc get routes -l app=exoplanetsNAME HOST/PORT ... exoplanetsexoplanets-declarative-manifests.apps.ocp4.example.com...
Open the route URL in the web browser.
The application version is v1.0.
http://exoplanets-declarative-manifests.apps.ocp4.example.com/
![]() |
Deploy the second version of the exoplanets application.
Switch to the v1.1.0 branch of the Git repository.
[student@workstation declarative-manifests]$ git checkout v1.1.0
branch 'v1.1.0' set up to track 'origin/v1.1.0'.
Switched to a new branch 'v1.1.0'Inspect the changes from the new manifests.
[student@workstation declarative-manifests]$oc diff -f ....output omitted... - secretRef: name: exoplanets - image: registry.ocp4.example.com:8443/redhattraining/exoplanets:v1.0 + image: registry.ocp4.example.com:8443/redhattraining/exoplanets:v1.1.0 imagePullPolicy: Always livenessProbe: failureThreshold: 3
The new version changes the image that is deployed to the cluster. Because the change is in the deployment, the new manifest produces new pods for the application.
Apply the changes from the new manifests.
[student@workstation declarative-manifests]$ oc apply -f .
configmap/database unchanged
secret/database configured
deployment.apps/database configured
service/database configured
configmap/exoplanets unchanged
secret/exoplanets configured
deployment.apps/exoplanets configured
service/exoplanets unchanged
route.route.openshift.io/exoplanets configuredList the deployments and pods.
Wait for the application pod to be ready.
Press Ctrl+C to exit the watch command.
[student@workstation declarative-manifests]$watch oc get deployments,podsEvery 2.0s: oc get deployments,pods ... NAME READY UP-TO-DATE AVAILABLE AGE deployment.apps/database 1/1 1 1 6m32s deployment.apps/exoplanets 1/1 1 1 6m33s NAMEREADYSTATUS RESTARTS AGE pod/database-6fddbbf94f-2pghj 1/1 Running 0 6m33s pod/exoplanets-74c85f5796-tw8tf1/1Running 0 32s
List the route for the exoplanets application.
[student@workstation declarative-manifests]$oc get routes -l app=exoplanetsNAME HOST/PORT ... exoplanetsexoplanets-declarative-manifests.apps.ocp4.example.com...
Open the route URL in the web browser.
The application version is v1.1.0.
http://exoplanets-declarative-manifests.apps.ocp4.example.com/
![]() |
Deploy the third version of the exoplanets application.
Switch to the v1.1.1 branch of the Git repository.
[student@workstation declarative-manifests]$ git checkout v1.1.1
branch 'v1.1.1' set up to track 'origin/v1.1.1'.
Switched to a new branch 'v1.1.1'View the differences between the currently deployed version of the application and the updated resource manifests.
[student@workstation declarative-manifests]$oc diff -f ....output omitted... kind: Secretmetadata: annotations: ...
output omitted... - DB_USER: '*** (before)'+ DB_USER: '*** (after)' kind: Secret metadata: annotations:
Inspect the current application pods.
[student@workstation declarative-manifests]$ oc get pods
NAME READY STATUS RESTARTS AGE
database-6fddbbf94f-brlj6 1/1 Running 0 44m
exoplanets-674cc57b5d-mv8kd 1/1 Running 0 18mDeploy the new version of the application.
[student@workstation declarative-manifests]$ oc apply -f .
configmap/database unchanged
secret/database configured
deployment.apps/database configured
service/database configured
configmap/exoplanets unchanged
secret/exoplanets configured
deployment.apps/exoplanets unchanged
service/exoplanets unchanged
route.route.openshift.io/exoplanets configuredInspect the current application pods again
[student@workstation declarative-manifests]$ oc get pods
NAME READY STATUS RESTARTS AGE
database-6fddbbf94f-brlj6 1/1 Running 0 10m
exoplanets-674cc57b5d-mv8kd 0/1 CrashLoopBackOff 4 (14s ago) 2mAlthough the secret is updated, the deployed application pods are not changed. These non-updated pods are a problem, because the pods load secrets and configuration maps at startup. Currently, the pods have stale values from the previous configuration, and therefore could crash.
Force the exoplanets application to restart, to flush out any stale configuration data.
Use the oc get deployments command to confirm the deployments.
[student@workstation declarative-manifests]$ oc get deployments
NAME READY UP-TO-DATE AVAILABLE AGE
database 1/1 1 1 32m
exoplanets 0/1 1 0 32mUse the oc rollout command to restart the database deployment.
[student@workstation declarative-manifests]$ oc rollout restart \
deployment/database
deployment.apps/database restartedUse the oc rollout command to restart the exoplanets deployment.
[student@workstation declarative-manifests]$ oc rollout restart \
deployment/exoplanets
deployment.apps/exoplanets restartedList the pods.
The exoplanets pod can go into a temporary crash loop backoff state if it attempts to access the database before it becomes available.
Wait for the application pod to be ready.
Press Ctrl+C to exit the watch command.
[student@workstation declarative-manifests]$ watch oc get pods
Every 2.0s: oc get deployments,pods ...
NAME READY STATUS RESTARTS AGEE
database-7c767c4bd7-m72nk 1/1 Running 0 32s
exoplanets-64c87f5796-bw8tm 1/1 Running 0 32sUse the oc get deployment command with the -o yaml option to view the last-applied-configuration annotation.
[student@workstation declarative-manifests]$ oc get deployment \
exoplanets -o yaml
apiVersion: apps/v1
kind: Deployment
metadata:
annotations:
deployment.kubernetes.io/revision: "3"
description: Defines how to deploy the application server
kubectl.kubernetes.io/last-applied-configuration: |
{"apiVersion":"apps/v1","kind":"Deployment","metadata":{"annotations":...
template.alpha.openshift.io/wait-for-ready: "true"
...output omitted...Open the route URL in the web browser.
The application version is v1.1.1.
http://exoplanets-declarative-manifests.apps.ocp4.example.com/
![]() |
Clean up the resources.
Delete the application resources.
[student@workstation declarative-manifests]$ oc delete -f .
configmap "database" deleted
secret "database" deleted
deployment.apps "database" deleted
service "database" deleted
configmap "exoplanets" deleted
secret "exoplanets" deleted
deployment.apps "exoplanets" deleted
service "exoplanets" deleted
route.route.openshift.io "exoplanets" deletedChange to the student HOME directory.
[student@workstation declarative-manifests]$ cd
[student@workstation ~]