cancel
Showing results for 
Search instead for 
Did you mean: 
mbencek
Cadet
Cadet
  • 2,063 Views

Automatically restarting pods when the secret or config map gets updated

Jump to solution

Hello,
Once the configmap or secret gets updated, pods using these don't see the change. After the update, pods need to get restarted/redeployed manually.

What is the best practice to automate this process on OpenShift 4.10?
Marko

Labels (1)
0 Kudos
1 Solution

Accepted Solutions
mighty_quinn
Mission Specialist
Mission Specialist
  • 2,055 Views

You can achieve this by adding a trigger section to the DeploymentConfig object, which defines the actions to take when a configmap or secret changes.

Here's an example of how to configure the DeploymentConfig to trigger a rolling deployment when a configmap changes:

apiVersion: apps.openshift.io/v1
kind: DeploymentConfig
metadata:
name: example
spec:
template:
spec:
containers:
- name: example
image: example:latest
env:
- name: CONFIGMAP_RELOAD_INTERVAL
value: "5s"
volumeMounts:
- name: config-volume
mountPath: /config
volumes:
- name: config-volume
configMap:

 


name: example-config
triggers:
- type: ConfigChange
type: ImageChange
imageChangeParams:
automatic: true
containerNames:
- example

The trigger section defines two types of triggers: ConfigChange and ImageChange. The ConfigChange trigger is responsible for detecting changes in the configmap referenced by the volume, and the ImageChange trigger is responsible for detecting changes in the Docker image.

The CONFIGMAP_RELOAD_INTERVAL environment variable is used to tell the application how often to check for changes in the configmap. In this example, it is set to 5 seconds.

When a change is detected in the configmap or the Docker image, OpenShift will automatically initiate a rolling deployment, which updates the pods one at a time, ensuring that the application remains available during the update.

 

Some guidance on DeploymentConfig objects is here:

https://docs.openshift.com/container-platform/4.12/applications/deployments/what-deployments-are.htm...

View solution in original post

0 Kudos
1 Reply
mighty_quinn
Mission Specialist
Mission Specialist
  • 2,056 Views

You can achieve this by adding a trigger section to the DeploymentConfig object, which defines the actions to take when a configmap or secret changes.

Here's an example of how to configure the DeploymentConfig to trigger a rolling deployment when a configmap changes:

apiVersion: apps.openshift.io/v1
kind: DeploymentConfig
metadata:
name: example
spec:
template:
spec:
containers:
- name: example
image: example:latest
env:
- name: CONFIGMAP_RELOAD_INTERVAL
value: "5s"
volumeMounts:
- name: config-volume
mountPath: /config
volumes:
- name: config-volume
configMap:

 


name: example-config
triggers:
- type: ConfigChange
type: ImageChange
imageChangeParams:
automatic: true
containerNames:
- example

The trigger section defines two types of triggers: ConfigChange and ImageChange. The ConfigChange trigger is responsible for detecting changes in the configmap referenced by the volume, and the ImageChange trigger is responsible for detecting changes in the Docker image.

The CONFIGMAP_RELOAD_INTERVAL environment variable is used to tell the application how often to check for changes in the configmap. In this example, it is set to 5 seconds.

When a change is detected in the configmap or the Docker image, OpenShift will automatically initiate a rolling deployment, which updates the pods one at a time, ensuring that the application remains available during the update.

 

Some guidance on DeploymentConfig objects is here:

https://docs.openshift.com/container-platform/4.12/applications/deployments/what-deployments-are.htm...

0 Kudos
Join the discussion
You must log in to join this conversation.