2.2 Configure the application
In this stage, we show you how to configure your application. For this lab the application of the previous lab is used.
Task 2.2.1: Update application port inside deployment
We will change the port of the application. With this change we need to adapt the deployment first. There are three ports to change. The container port itself, and the ports for the liveness/readiness probes.
apiVersion: apps.openshift.io/v1
kind: DeploymentConfig
metadata:
annotations:
image.openshift.io/triggers: '[{"from":{"kind":"ImageStreamTag","name":"data-producer:rest"},"fieldPath":"spec.template.spec.containers[?(@.name==\"data-producer\")].image"}]'
labels:
app: data-producer
application: amm-techlab
name: data-producer
spec:
replicas: 1
selector:
deploymentConfig: data-producer
strategy:
type: Recreate
template:
metadata:
labels:
application: amm-techlab
deploymentConfig: data-producer
spec:
containers:
- image: data-producer
imagePullPolicy: Always
livenessProbe:
failureThreshold: 5
httpGet:
path: /health/live
port: 8080
scheme: HTTP
initialDelaySeconds: 3
periodSeconds: 20
timeoutSeconds: 15
readinessProbe:
failureThreshold: 5
httpGet:
path: /health/ready
port: 8080
scheme: HTTP
initialDelaySeconds: 3
periodSeconds: 20
timeoutSeconds: 15
name: data-producer
ports:
- containerPort: 8080
name: http
protocol: TCP
resources:
limits:
cpu: '1'
memory: 500Mi
requests:
cpu: 50m
memory: 100Mi
triggers:
- imageChangeParams:
automatic: true
containerNames:
- data-producer
from:
kind: ImageStreamTag
name: data-producer:rest
type: ImageChange
- type: ConfigChange
Update the application port from 8080 to 8081 using oc patch
:
oc patch dc/data-producer --type "json" -p '[{"op":"replace","path":"/spec/template/spec/containers/0/ports/0/containerPort","value":8081}]'
deploymentconfig.apps.openshift.io/data-producer patched
Update also the ports of the liveness and readiness probes from 8080 to 8081 using oc patch
:
command hint
oc patch dc/data-producer --type "json" -p '[{"op":"replace","path":"/spec/template/spec/containers/0/livenessProbe/httpGet/port","value":8081}]'
oc patch dc/data-producer --type "json" -p '[{"op":"replace","path":"/spec/template/spec/containers/0/readinessProbe/httpGet/port","value":8081}]'
Note
The changed DeploymentConfig should now represent the solutionVerify the changed port of the pod by describing the DeploymentConfig using oc describe
.
command hint
oc describe deploymentconfig data-producer
The pod does not start because that the readiness probe fails. Now we have to change the application to use the port 8081 for serving its endpoint.
Task 2.2.2: Configure application
There are several options how to configure a Quarkus application. We’ll show how to do it with environment variables. You can overwrite every property in the application.properties
file with the corresponding environment variable. (eg. quarkus.http.port=8081
in the application.properties is the same like QUARKUS_HTTP_PORT=8081
as an environment variable) Quarkus: overriding-properties-at-runtime
The environment of the DeploymentConfig has to be extended with a new environment variable named QUARKUS_HTTP_PORT
.
First, let’s check the environment:
oc set env dc/data-producer --list
# deploymentconfigs/data-producer, container data-producer
There are no environment variables configured.
Add the environment variable QUARKUS_HTTP_PORT
with the value 8081 with oc set env
.
command hint
oc set env dc/data-producer QUARKUS_HTTP_PORT=8081
deploymentconfig.apps.openshift.io/data-producer updated
The variable should be configured now. Check it by listing the environment of the DeploymentConfig again.
command hint
oc set env dc/data-producer --list
Expected output of the environment listing:
# deploymentconfigs/data-producer, container data-producer
QUARKUS_HTTP_PORT=8081
Task 2.2.3: Verify application
Changing the environment of a deployment triggers a rollout of the application pod. After the container has started successfully, the application should be reachable again.
Check if the changes were applied correctly. Open your browser and navigate to your application:
https://data-producer-<username>.techlab.openshift.ch/data
Important notes
We showed how to change the OpenShift resources using the commands oc patch
and oc set env
.
This is good for developing or debugging the setup of an application project.
For changing stages and productive environments, we propose updating the YAML representations inside the Git repository and apply the files again.
Solution
The needed resource files are available inside the folder manifests/02.0/2.2/ of the techlab github repository.
If you weren’t successful, you can update your project with the solution by cloning the Techlab Repository git clone https://github.com/puzzle/amm-techlab.git
and executing this command:
oc apply -f manifests/02.0/2.2/