1. Context
Kubernetes ConfigMaps are usually used to store configuration data, such as environment settings, configuration files, or command-line arguments, for use by applications running in a cluster. ConfigMaps allow you to decouple configuration from the application code, making it easier to manage and update configurations without rebuilding or redeploying containers. They can be injected into containers as environment variables, command-line arguments, or mounted as files, or read at runtime.
2. Prerequisites
A camel integrationt o be deployed on OpenShift.
3. Goal
Provide a configuration example to read kubernetes config maps values in camel applications.
4. Configuration
In Camel we provide the secret function to retrieve configmap values from a configmap resource.
The syntax is pretty simple:
configmap:name/key[:defaultValue]
It’s important to restrict the ability to read configmap with the least amount of permissions for your cluster. So the application should run with a role with only list/read configmaps permission.
This could be done with the following command:
oc create clusterrole configmapreader --verb=get --verb=list --resource=configmap --namespace=<namespace>
The minimum permissions are list and get.
Alternatively, you can create a yaml file with the following content:
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRole
metadata:
name: configmapreader
rules:
- apiGroups:
- ""
resources:
- configmaps
verbs:
- get
- list
And then run
oc apply -f <file_name>
The application will have to run with that clusterrole.
This will ensure the running application won’t be able to do more than list and get configmap.
The same configuration could be seen on OCP by following the Camel on OCP Best Practices repository, in particular, the OCP Configmaps section. You can follow the example for both the runtimes supported by Red Hat Build of Apache Camel: