Configuration via ConfigMap or Secret

Camel K allows defining property values using Kubernetes ConfigMap or Secrets.

For the sake of example, consider the following integration:

props.groovy
from('timer:props?period=1000')
    .log('{{my.message}}')

In addition to command line property configuration, Camel K provides the following configuration mechanisms.

Configuration via ConfigMap

You can create a ConfigMap containing your configuration properties, and link it to a Camel K integration.

For example, you can define the following ConfigMap:

my-config.yaml
apiVersion: v1
kind: ConfigMap
metadata:
  name: my-config
data:
  application.properties: |
    my.message=Hello World
    logging.level.org.apache.camel=DEBUG

In the ConfigMap above, we’ve set both the value of the property my.message, and also the logging level for the org.apache.camel package.

You need to create the ConfigMap first (in the same Kubernetes namespace):

$ kubectl apply -f my-config.yaml

You can now run the integration with the following command to reference the ConfigMap:

$ kamel run --configmap=my-config props.groovy

Configuration via Secret

Configuration via a Secret is similar to the configuration via a ConfigMap. The difference is that you may need to base64 encode the content of the application.properties file inside the Secret.

For example, the following Secret is equivalent to the previous ConfigMap:

my-secret.yaml
apiVersion: v1
kind: Secret
metadata:
  name: my-secret
data:
  application.properties: |
    bXkubWVzc2FnZT1IZWxsbyBXb3JsZAogICAgbG9nZ2luZy5sZXZlbC5vcmcuYXBhY2hlLmNhbWVs
    PURFQlVHCg==

You need to create the Secret first (in the same Kubernetes namespace):

$ kubectl apply -f my-secret.yaml

You can now run the integration with the following command to reference the Secret:

$ kamel run --secret=my-secret props.groovy

Reference a Secret from properties

Suppose you have an existing Secret, that contains sensitive information that your integration requires. You might want to reference the values from this Secret in your configuration properties.

For example, a Secret named secret-message:

secret-message.yaml
apiVersion: v1
kind: Secret
metadata:
  name: secret-message
data:
  MESSAGE: SGVsbG8gV29ybGQK
type: Opaque

You can reference this Secret from the configuration properties, using the {{secret:secret-name/key-name}} syntax.

For example, the following configuration stored in a ConfigMap references the Secret defined previously:

my-config.yaml
apiVersion: v1
kind: ConfigMap
metadata:
  name: my-config
data:
  application.properties: |
    my.message={{secret:secret-message/MESSAGE}}

You can now run the integration with the following commands to include both the Secret and ConfigMap:

$ kubectl apply -f my-config.yaml -f secret-message.yaml
$ kamel run --secret=secret-message --configmap=my-config props.groovy