blob: c75b55a9090e5c3a335e24c8dad137673291b1b9 [file] [log] [blame]
= 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:
[source,groovy]
.props.groovy
----
from('timer:props?period=1000')
.log('{{my.message}}')
----
In addition to xref:configuration/configuration.adoc[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:
[source,yaml]
.my-config.yaml
----
apiVersion: v1
kind: ConfigMap
metadata:
name: my-config
data:
application.properties: |
my.message=Hello World
----
In the ConfigMap above, we've set the value of the property `my.message`. Other settings could also be added there if necessary.
You need to create the ConfigMap first (in the same Kubernetes namespace):
[source,console]
----
$ kubectl apply -f my-config.yaml
----
You can now run the integration with the following command to reference the ConfigMap:
[source, console]
----
$ 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:
[source,yaml]
.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):
[source, console]
----
$ kubectl apply -f my-secret.yaml
----
You can now run the integration with the following command to reference the Secret:
[source,console]
----
$ 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`:
[source,yaml]
.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:
[source,yaml]
.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:
[source,console]
----
$ kubectl apply -f my-config.yaml -f secret-message.yaml
$ kamel run --secret=secret-message --configmap=my-config props.groovy
----