Kubernetes Deployments
Since Camel 2.20
Both producer and consumer are supported
The Kubernetes Deployments component is one of Kubernetes Components which provides a producer to execute Kubernetes Deployments operations and a consumer to consume events related to Deployments objects.
Configuring Options
Camel components are configured on two separate levels:
-
component level
-
endpoint level
Configuring Component Options
At the component level, you set general and shared configurations that are, then, inherited by the endpoints. It is the highest configuration level.
For example, a component may have security settings, credentials for authentication, urls for network connection and so forth.
Some components only have a few options, and others may have many. Because components typically have pre-configured defaults that are commonly used, then you may often only need to configure a few options on a component; or none at all.
You can configure components using:
-
the Component DSL.
-
in a configuration file (
application.properties,*.yamlfiles, etc). -
directly in the Java code.
Configuring Endpoint Options
You usually spend more time setting up endpoints because they have many options. These options help you customize what you want the endpoint to do. The options are also categorized into whether the endpoint is used as a consumer (from), as a producer (to), or both.
Configuring endpoints is most often done directly in the endpoint URI as path and query parameters. You can also use the Endpoint DSL and DataFormat DSL as a type safe way of configuring endpoints and data formats in Java.
A good practice when configuring options is to use Property Placeholders.
Property placeholders provide a few benefits:
-
They help prevent using hardcoded urls, port numbers, sensitive information, and other settings.
-
They allow externalizing the configuration from the code.
-
They help the code to become more flexible and reusable.
The following two sections list all the options, firstly for the component followed by the endpoint.
Component Options
The Kubernetes Deployments component supports the following options which are listed below.
| Name | Description | Default | Type |
|---|---|---|---|
Autowired An existing Kubernetes client for the endpoints of this component that do not set their own kubernetesClient option. The endpoints then do not use the options that configure the client (masterUrl, credentials, certificates, trustCerts, apiVersion, connectionTimeout). | KubernetesClient | ||
Allows for bridging the consumer to the Camel routing Error Handler, which mean any exceptions (if possible) occurred while the Camel consumer is trying to pickup incoming messages, or the likes, will now be processed as a message and handled by the routing Error Handler. Important: This is only possible if the 3rd party component allows Camel to be alerted if an exception was thrown. Some components handle this internally only, and therefore bridgeErrorHandler is not possible. In other situations we may improve the Camel component to hook into the 3rd party component and make this possible for future releases. By default the consumer will use the org.apache.camel.spi.ExceptionHandler to deal with exceptions, that will be logged at WARN or ERROR level and ignored. | false | boolean | |
Whether the producer should be started lazy (on the first message). By starting lazy you can use this to allow CamelContext and routes to startup in situations where a producer may otherwise fail during starting and cause the route to fail being started. By deferring this startup to be lazy then the startup failure can be handled during routing messages via Camel’s routing error handlers. Beware that when the first message is processed then creating and starting the producer may take a little time and prolong the total processing time of the processing. | false | boolean | |
Whether autowiring is enabled. This is used for automatic autowiring options (the option must be marked as autowired) by looking up in the registry to find if there is a single instance of matching type, which then gets configured on the component. This can be used for automatic configuring JDBC data sources, JMS connection factories, AWS Clients, etc. | true | boolean |
Endpoint Options
The Kubernetes Deployments endpoint is configured using URI syntax:
kubernetes-deployments:masterUrl
With the following path and query parameters:
Path Parameters
| Name | Description | Default | Type |
|---|---|---|---|
Required The URL of the Kubernetes API server, such as https://kubernetes.default.svc. Use local or client to create the Kubernetes client from the auto-detected configuration (kubeconfig file, in-cluster service account, system properties and environment variables) without applying the options that configure the client (credentials, certificates, trustCerts, apiVersion, connectionTimeout). With a URL, the client also starts from the auto-detected configuration, and these options override it. Not used when the kubernetesClient option is set. | String |
Query Parameters
| Name | Description | Default | Type |
|---|---|---|---|
The default API version of the Kubernetes client (the client default is v1). The client uses it only for a resource type that does not give its own version, and the resource types of these components all give theirs. | String | ||
Not used. It was the DNS domain for the ServiceCall EIP, which was removed in Camel 4.19. | String | ||
An existing Kubernetes client to use. The options that configure the client (masterUrl, credentials, certificates, trustCerts, apiVersion, connectionTimeout) are then not used, and Camel does not close the client when the endpoint stops. | KubernetesClient | ||
The namespace of the resources. For the producer, the CamelKubernetesNamespaceName header takes precedence. When neither is set, the list operations and the consumer cover all namespaces, and the operations on a single resource fail; openshift-deploymentconfigs then uses the namespace of the Kubernetes client, and kubernetes-custom-resources fails. Not used by kubernetes-namespaces, kubernetes-nodes and kubernetes-persistent-volumes, whose resources are cluster-scoped. When Camel creates the client from a URL, it is also the default namespace of the client. | String | ||
Not used. It was the port name for the ServiceCall EIP, which was removed in Camel 4.19. | String | ||
Not used. It was the port protocol for the ServiceCall EIP, which was removed in Camel 4.19. | tcp | String | |
The API group of the custom resource, such as sources.knative.dev. Used only by kubernetes-custom-resources: the consumer requires it, and the producer uses the CamelKubernetesCRDGroup header when it is not set. | String | ||
The name of the custom resource definition (CRD), such as githubsources.sources.knative.dev. Used only by kubernetes-custom-resources: the consumer requires it, and the producer uses the CamelKubernetesCRDName header when it is not set. | String | ||
The plural name of the custom resource, as used in its API path, such as githubsources. Used only by kubernetes-custom-resources: the consumer requires it, and the producer uses the CamelKubernetesCRDPlural header when it is not set. | String | ||
The scope of the custom resource: Namespaced or Cluster (the client takes any value other than Namespaced as cluster-scoped). Used only by kubernetes-custom-resources: the consumer requires it, and the producer uses the CamelKubernetesCRDScope header when it is not set. | String | ||
The version of the custom resource API, such as v1alpha1. Used only by kubernetes-custom-resources: the consumer requires it, and the producer uses the CamelKubernetesCRDVersion header when it is not set. | String | ||
The label key that the consumer filters the watched resources on. Used only together with labelValue, and it takes precedence over resourceName. Not used by kubernetes-custom-resources. | String | ||
The label value that the consumer filters the watched resources on. Used only together with labelKey. Not used by kubernetes-custom-resources. | String | ||
The number of threads of the consumer that create the watch, and watch again when the Kubernetes client closed it with an error. The client delivers the events one at a time on its own threads, so one thread is enough. | 1 | int | |
The name of the single resource that the consumer watches. Not used when labelKey and labelValue are set, nor when namespace is not set, except by kubernetes-namespaces and kubernetes-nodes, whose resources are cluster-scoped. Not used by kubernetes-custom-resources. | String | ||
Allows for bridging the consumer to the Camel routing Error Handler, which mean any exceptions (if possible) occurred while the Camel consumer is trying to pickup incoming messages, or the likes, will now be processed as a message and handled by the routing Error Handler. Important: This is only possible if the 3rd party component allows Camel to be alerted if an exception was thrown. Some components handle this internally only, and therefore bridgeErrorHandler is not possible. In other situations we may improve the Camel component to hook into the 3rd party component and make this possible for future releases. By default the consumer will use the org.apache.camel.spi.ExceptionHandler to deal with exceptions, that will be logged at WARN or ERROR level and ignored. | false | boolean | |
To let the consumer use a custom ExceptionHandler. Notice if the option bridgeErrorHandler is enabled then this option is not in use. By default the consumer will deal with exceptions, that will be logged at WARN or ERROR level and ignored. | ExceptionHandler | ||
Sets the exchange pattern when the consumer creates an exchange. Enum values:
| ExchangePattern | ||
The producer operation to perform, such as listPods or createConfigMap; the page of each component lists its operations. When it is not set, the CamelKubernetesOperation header gives the operation; the option takes precedence over the header. | String | ||
Whether the producer should be started lazy (on the first message). By starting lazy you can use this to allow CamelContext and routes to startup in situations where a producer may otherwise fail during starting and cause the route to fail being started. By deferring this startup to be lazy then the startup failure can be handled during routing messages via Camel’s routing error handlers. Beware that when the first message is processed then creating and starting the producer may take a little time and prolong the total processing time of the processing. | false | boolean | |
The timeout in milliseconds to establish a connection to the API server. When it is not set, the Kubernetes client default of 10000 applies; 0 or less leaves the timeout to the HTTP client implementation. | Integer | ||
The certificate of the certificate authority (CA) to trust for the API server, as Base64-encoded PEM data. Takes precedence over caCertFile. | String | ||
The path of a PEM file with the certificate of the certificate authority (CA) to trust for the API server. caCertData takes precedence over it. | String | ||
The client certificate for TLS client authentication, as Base64-encoded PEM data. Takes precedence over clientCertFile, and is used only together with clientKeyData or clientKeyFile. | String | ||
The path of a PEM file with the client certificate for TLS client authentication. Used only together with clientKeyData or clientKeyFile; clientCertData takes precedence over it. | String | ||
The algorithm of the client private key: RSA (the default of the Kubernetes client) or EC. | String | ||
The private key for TLS client authentication, as Base64-encoded unencrypted PEM data. Takes precedence over clientKeyFile. | String | ||
The path of a file with the private key for TLS client authentication, as unencrypted PEM. clientKeyData takes precedence over it. | String | ||
The password with which the Kubernetes client protects the client private key in the key store that it builds in memory (the client default is changeit). It does not decrypt the key, which must be unencrypted. | String | ||
The bearer token to authenticate to the API server, such as a service account token or an OAuth access token. When it is set, username and password are not used. | String | ||
The password for HTTP basic authentication to the API server. Used only together with username, and not when oauthToken is set. | String | ||
Whether to trust any certificate of the API server without checking it. This is insecure: set caCertData or caCertFile instead. Setting it to false does not override true from the auto-detected configuration. | Boolean | ||
The username for HTTP basic authentication to the API server. Used only together with password, and not when oauthToken is set. | String |
Message Headers
The Kubernetes Deployments component supports the following message header(s), which is/are listed below:
| Name | Description | Default | Type |
|---|---|---|---|
CamelKubernetesOperation (producer) Constant: | The operation of the producer, such as listPods or createConfigMap. Used only when the operation option of the endpoint is not set; one of the two is required. | String | |
CamelKubernetesNamespaceName (producer) Constant: | The namespace of the resource, which takes precedence over the namespace option of the endpoint. For kubernetes-namespaces, it is instead the name of the namespace to get, create, update or delete, where it is required. When no namespace is set, the list operations cover all namespaces (openshift-deploymentconfigs: the namespace of the Kubernetes client), getConfigMap, getDeployment and getDeploymentConfig use the namespace of the Kubernetes client, and the other operations fail; kubernetes-custom-resources requires a namespace for every operation. | String | |
CamelKubernetesDeploymentsLabels (producer) Constant: | The labels, as a map of label keys to values: listDeploymentsByLabels and listDeploymentConfigsByLabels (where they are required) list only the Deployments or DeploymentConfigs that have all of them, and the create and update operations set them as the labels of the Deployment or DeploymentConfig. | Map | |
CamelKubernetesDeploymentsAnnotations (producer) Constant: | The annotations, as a map of keys to values, that createDeployment and updateDeployment set on the Deployment. openshift-deploymentconfigs does not use them. | Map | |
CamelKubernetesDeploymentName (producer) Constant: | The name of the Deployment or DeploymentConfig for the get, create, update, delete and scale operations, where it is required. | String | |
CamelKubernetesDeploymentSpec (producer) Constant: | The DeploymentSpec of the Deployment to create or update; required for createDeployment and updateDeployment. | DeploymentSpec | |
CamelKubernetesDeploymentReplicas (producer) Constant: | The desired number of replicas (pods) for scaleDeployment and scaleDeploymentConfig, where it is required. | Integer | |
CamelKubernetesEventAction (consumer) Constant: | The action of the watch event that the consumer received: ADDED, MODIFIED or DELETED. For kubernetes-events, the createEvent and updateEvent operations of the producer read a header of the same name as the action of the Event. Enum values:
| Action | |
CamelKubernetesEventTimestamp (consumer) Constant: | The time when the consumer received the watch event, in milliseconds since the Unix epoch (not the time of the change in Kubernetes). | long |
Message Body
The message body at each side of the Kubernetes Deployments component: Consumer is the body of the messages the consumer creates, Consumer reply the bodies a consumer that answers its caller can reply with, Producer input the bodies the producer can send or write, and Producer output the body after the producer.
| Side | Body | Description |
|---|---|---|
Consumer |
| The Deployment that changed, with the action (ADDED, MODIFIED or DELETED) in the CamelKubernetesEventAction header. |
Producer input |
| Not used: the operations take their input from headers, such as the name of the Deployment in CamelKubernetesDeploymentName, its DeploymentSpec in CamelKubernetesDeploymentSpec and the replicas of scaleDeployment in CamelKubernetesDeploymentReplicas. |
Producer output |
| A List of the Deployments for the list operations, the Deployment of get, create and update (null when getDeployment finds none), and a Boolean of whether deleteDeployment deleted it. scaleDeployment gives the number of replicas in the spec of the scaled Deployment.
|
The bodies are the ones with the default options. A side that is not listed is not known, and tooling does not guess it. The carriers, the sides and the tools that use them are described in Message Body Types.
Examples
Kubernetes Deployments Producer Examples
-
listDeployments: this operation lists the deployments on a kubernetes cluster
-
Java
-
XML
-
YAML
from("direct:list")
.to("kubernetes-deployments:///?kubernetesClient=#kubernetesClient&operation=listDeployments")
.to("mock:result"); <route>
<from uri="direct:list"/>
<to uri="kubernetes-deployments:///?kubernetesClient=#kubernetesClient&operation=listDeployments"/>
<to uri="mock:result"/>
</route> - route:
from:
uri: direct:list
steps:
- to:
uri: kubernetes-deployments:///
parameters:
kubernetesClient: "#kubernetesClient"
operation: listDeployments
- to:
uri: mock:result This operation returns a List of Deployment from your cluster
-
listDeploymentsByLabels: this operation lists the deployments by labels on a kubernetes cluster
from("direct:listByLabels")
.process(exchange -> {
exchange.getIn().setHeader("CamelKubernetesDeploymentsLabels",
Map.of("key1", "value1", "key2", "value2"));
})
.to("kubernetes-deployments:///?kubernetesClient=#kubernetesClient&operation=listDeploymentsByLabels")
.to("mock:result"); This operation returns a List of Deployments from your cluster, using a label selector (with key1 and key2, with value value1 and value2)
Kubernetes Deployments Consumer Example
-
Java
-
XML
-
YAML
from("kubernetes-deployments://{{kubernetes-host}}?oauthToken={{kubernetes-token}}")
.to("log:result"); <route>
<from uri="kubernetes-deployments://{{kubernetes-host}}?oauthToken={{kubernetes-token}}"/>
<to uri="log:result"/>
</route> - route:
from:
uri: kubernetes-deployments://{{kubernetes-host}}
parameters:
oauthToken: "{{kubernetes-token}}"
steps:
- to:
uri: log:result This consumer returns a message per event received for all Deployments from all namespaces in the cluster.
You can narrow the scope of the consumer using the following query parameter combinations:
-
labelKey+labelValue- Watch Deployments with the specified label in any namespace. -
namespace- Watch all Deployments in the specified namespace. -
namespace+resourceName- Watch the Deployment with the specified name in the given namespace. -
namespace+labelKey+labelValue- Watch Deployments with the specified label in the given namespace.