Configuration via ConfigMap or Secret

Camel K allows to define property values using Kubernetes ConfigMap or Secrets.

For the sake of simplicity, 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 options.

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 my.message property 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 Secrets is similar to the configuration via 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 in 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 in configuration properties using the {{secret:secret-name/key-name}} syntax.

For example, the following configuration stored in a ConfigMap references the example 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 necessary the Secret and ConfigMap:

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