Camel CLI

Camel Kubernetes Plugin

qianmoQqianmoQ· 更新于 2026-09-22· 阅读 68 分钟· 0 次阅读

登录后可跨设备保存划线和私人笔记登录

Camel Kubernetes plugin

Export, build, push, and deploy Camel integrations to Kubernetes — develop locally with Camel CLI, then promote to any cluster.

Prerequisites: kubectl installed, connected to a Kubernetes cluster (remote, Kind, or Minikube).

Enable the plugin:

camel plugin add kubernetes
Run camel kubernetes --help to see all subcommands.

Kubernetes export

Export a Maven project with a Kubernetes manifest (kubernetes.yml) containing Deployment, Service, ConfigMap, and other resources:

camel kubernetes export route.yaml --dir some/path/to/project

The default runtime is Quarkus (--runtime=quarkus). Build and deploy:

./mvnw package -Dquarkus.container-image.build=true
./mvnw package -Dquarkus.kubernetes.deploy=true
The camel kubernetes run command combines export, build, push, and deploy into a single step.

The export command provides several options to customize the project:

OptionDescription
--service-accountThe service account used to run the application.
--dependencyAdds dependency that should be included, use "camel:" prefix for a Camel component, "mvn:org.my1.0" for a Maven dependency.
--build-propertyMaven/Gradle build properties (syntax: --build-property=prop1=foo)
--propertyAdd a runtime property or properties from a file (syntax: [my-key=my-value\file:/path/to/my-conf.properties,/path/to/my-conf.properties]).
--configAdd a runtime configuration from a ConfigMap or a Secret (syntax: [configmap,secret]:name[/key], where name represents the configmap/secret name and key optionally represents the configmap/secret key to be filtered).
--resourceAdd a runtime resource from a Configmap or a Secret (syntax: [configmap,secret]:name[/key][@path], where name represents the configmap/secret name, key optionally represents the configmap/secret key to be filtered and path represents the destination path).
--open-apiAdd an OpenAPI spec (syntax: [configmap,file]:name).
--envSet an environment variable in the integration container, for instance "--env MY_VAR=my-value".
--volumeMount a volume into the integration container, for instance "--volume pvcname:/container/path".
--connectA Service that the integration should bind to, specified as [[apigroup/]version:]kind:[namespace/]name.
--sourceAdd the source file to your integration, this is added to the list of files listed as arguments of the command.
--annotationAdd an annotation to the integration. Use name values pairs like "--annotation my.company=hello".
--labelAdd a label to the integration. Use name values pairs like "--label my.company=hello".
--traitAdd a trait configuration to the integration. Use name values pairs like "--trait trait.name.config=hello".
--imageAn image built externally (for instance via CI/CD). Enabling it will skip the integration build phase.
--image-registryThe image registry to hold the app container image.
--image-groupThe image registry group used to push images to.
--image-builderThe image builder used to build the container image (e.g. docker, jib, s2i).
--image-platformList of target platforms. Each platform is defined using os and architecture (e.g. linux/amd64).
--base-imageThe base image that is used to build the container image from (default is eclipse-temurin:<java-version>).
--registry-mirrorOptional Docker registry mirror where to pull images from when building the container image.
--cluster-typeThe target cluster type. Special configurations may be applied to different cluster types such as Kind or Minikube.
--profileThe developer profile to use a specific configuration in configuration files using the naming style application-<profile>.properties.
Run camel kubernetes export --help for all options (includes inherited Camel CLI export options).

Health probes

The export includes camel-observability-services by default, which prefixes health probes with /observe:

  • Quarkus: /observe/health/live, /observe/health/ready, /observe/health/started
  • Spring Boot: /observe/health/liveness, /observe/health/readiness

Kubernetes manifest options

Customize the Kubernetes manifest using traits (from Camel K). Trait configuration precedence:

  1. --trait command options
  2. Annotations with prefix trait.camel.apache.org/*
  3. Properties in application-<profile>.properties with prefix camel.jbang.trait.*
  4. Properties in application.properties with prefix camel.jbang.trait.*

Container trait

Customize the container specification (image, ports, resources):

PropertyTypeDescription
container.portintTo configure a different port exposed by the container (default 8080).
container.port-namestringTo configure a different port name for the port exposed by the container. It defaults to http only when the expose parameter is true.
container.service-portintTo configure under which service port the container port is to be exposed (default 80).
container.service-port-namestringTo configure under which service port name the container port is to be exposed (default http).
container.namestringThe application container name.
container.imagestringThe application container image to use for the Deployment.
container.image-pull-policyPullPolicyThe pull policy: Always\Never\IfNotPresent
container.image-pull-secretsstring[]The pull secrets for private registries
container.request-cpustringThe minimum amount of CPU required.
container.request-memorystringThe minimum amount of memory required.
container.limit-cpustringThe maximum amount of CPU required.
container.limit-memorystringThe maximum amount of memory required.

Example:

camel kubernetes export Sample.java --trait container.name=my-container --trait container.port=8088 --trait container.request-cpu=0.005 --trait container.request-memory=100Mi

CronJob trait

Generate a CronJob instead of a Deployment (requires enabled=true and schedule):

camel kubernetes export Sample.java --trait=cronjob.enabled=true --trait=cronjob.schedule="* * * * 2"
PropertyTypeDescription
cronjob.enabledbooleanTo generate the CronJob manifest instead of Deployment. (default=false)
cronjob.schedulestringTo set the schedule to run the workload following the crontab format.
cronjob.timezonestringTo set the timezone to run the workload.
cronjob.startingDeadlineSecondsintegerTo set the StartingDeadlineSeconds field of the CronJob.
cronjob.activeDeadlineSecondsintegerTo set the ActiveDeadlineSeconds field of the CronJob.
cronjob.backoffLimitintegerTo set the BackoffLimit field of the CronJob.
cronjob.durationMaxIdleSecondsintegerTo set the camel.main.duration-max-idle-seconds property for how long time in seconds Camel can be idle before automatic terminating the JVM. (default 1)

Labels and annotations

By default, resources have the label app.kubernetes.io/name set to the project name. Add custom labels and annotations:

camel kubernetes export Sample.java --annotation project.team=camel-experts --label env=staging

Environment variables

Set environment variables with --trait environment.vars=KEY=VALUE or the shortcut --env KEY=VALUE:

camel kubernetes export Sample.java --env MY_ENV=foo --env FOO_ENV=bar

Service trait

A Service resource is auto-generated when routes expose HTTP endpoints (e.g., platform-http). Customize it:

PropertyTypeDescription
service.typestringThe type of service to be used, either 'ClusterIP', 'NodePort' or 'LoadBalancer'.
container.service-portintTo configure under which service port the container port is to be exposed (default 80).
container.service-port-namestringTo configure under which service port name the container port is to be exposed (default http).

Knative service trait

Use Knative serving for serverless workloads with auto-scaling and scale-to-zero.

Disabled by default — enable with --trait knative-service.enabled=true.

Property Type Description

knative-service.enabled

bool

Can be used to enable or disable a trait. All traits share this common property.

knative-service.annotations

map[string]string

The annotations added to route. This can be used to set knative service-specific annotations CLI usage example: -t "knative-service.annotations.'haproxy.router.openshift.io/balance'=true"

knative-service.class

string

Configures the Knative autoscaling class property (e.g., to set hpa.autoscaling.knative.dev or kpa.autoscaling.knative.dev autoscaling).

Refer to the Knative documentation for more information.

knative-service.autoscaling-metric

string

Configures the Knative autoscaling metric property (e.g., to set concurrency based or cpu based autoscaling).

Refer to the Knative documentation for more information.

knative-service.autoscaling-target

int

Sets the allowed concurrency level or CPU percentage (depending on the autoscaling metric) for each Pod.

Refer to the Knative documentation for more information.

knative-service.min-scale

int

The minimum number of Pods that should be running at any time for the integration. It’s zero by default, meaning that the integration is scaled down to zero when not used for a configured amount of time.

Refer to the Knative documentation for more information.

knative-service.max-scale

int

An upper bound for the number of Pods that can be running in parallel for the integration. Knative has its own cap value that depends on the installation.

Refer to the Knative documentation for more information.

knative-service.rollout-duration

string

Enables to gradually shift traffic to the latest Revision and sets the rollout duration. It’s disabled by default and must be expressed as a Golang time.Duration string representation, rounded to a second precision.

knative-service.visibility

string

Setting cluster-local, Knative service becomes a private service. Specifically, this option applies the networking.knative.dev/visibility label to Knative service.

Refer to the Knative documentation for more information.

knative-service.timeout-seconds

int

The maximum duration in seconds that the request instance is allowed to respond to a request. This field propagates to the integration Pod’s terminationGracePeriodSeconds.

Refer to the Knative documentation for more information.

Knative component trait

Configure the Camel Knative component to interact with Knative eventing and Knative serving. The export auto-configures both the component and the Kubernetes manifest.

Disabled by default — enable with --trait knative.enabled=true.

Property Type Description

knative.enabled

bool

Can be used to enable or disable a trait. (default: true)

knative.configuration

string

Can be used to inject a Knative complete configuration in JSON format

knative.channel-sinks

[]string

List of channels used as destination of camel routes. Can contain simple channel names or full Camel URIs.

Refer to the Knative documentation for more information.

knative.channel-sources

[]string

List of channels used as the source of camel routes. Can contain simple channel names or full Camel URIs.

knative.endpoint-sinks

[]string

List of endpoints used as destination of camel routes. Can contain simple endpoint names or full Camel URIs.

knative.endpoint-sources

[]string

List of endpoints used as sources of camel routes. Can contain simple endpoint names or full Camel URIs.

knative.event-sinks

[]string

List of endpoints used as destination of integration routes. Can contain simple endpoint names or full Camel URIs.

knative.event-sources

[]string

List of event types that the integration will be subscribed to. Can contain simple event types or full Camel URIs (to use a specific broker different from "default").

knative.sink-binding

bool

Allows binding the integration to a sink via a Knative SinkBinding resource. This can be used when the integration targets a single sink. It’s enabled by default when the integration targets a single sink (except when the integration is owned by a Knative source).

knative.filters

[]string

Sets filter attributes on the event stream (such as event type, source, subject and so on). A list of key-value pairs that represent filter attributes and its values. The syntax is KEY=VALUE, e.g., source="my.source". Filter attributes get set on the Knative trigger that is being created as part of this integration.

knative.filter-event-type

bool

Enables the default filtering for the Knative trigger using the event type If this is true, the created Knative trigger uses the event type as a filter on the event stream when no other filter criteria is given. (default: true)

Knative trigger

When a route consumes from knative:event, the plugin automatically generates a Knative Trigger in the manifest:

- route:
    from:
      uri: knative:event/camel.evt.type
      parameters:
        name: my-broker
      steps:
        - to:
            uri: log:info

Export with camel kubernetes export knative-route.yaml — the trigger, service, and knative.json configuration are all generated automatically.

Knative channel subscription

Similarly, routes consuming from knative:channel/my-channel automatically generate a Knative Subscription in the manifest. The knative.json configuration is auto-generated.

Knative sink binding

Routes that produce to knative:event, knative:channel, or knative:endpoint automatically get a SinkBinding resource in the manifest. Knative injects the target URL via the K_SINK environment variable at deployment time, so the route doesn’t need to know the actual URL. === Mount trait

Configure volume mounts from ConfigMaps, Secrets, and PVCs. Shortcuts: --volume, --config, --resource.

PropertyTypeDescription
mount.configs[]stringA list of configuration pointing to configmap/secret. The configurations are expected to be UTF-8 resources as they are processed by runtime Camel Context and tried to be parsed as property files. They are also made available on the classpath to ease their usage directly from the Route. Syntax: [configmap\secret]:name[/key], where name represents the resource name and key optionally represents the resource key to be filtered
mount.resources[]stringA list of resources (text or binary content) pointing to a configmap/secret. The resources are expected to be any resource type (text or binary content). The destination path can be either a default location or any path specified by the user. Syntax: [configmap\secret]:name[/key][@path], where name represents the resource name, key optionally represents the resource key to be filtered and path represents the destination path
mount.volumes[]stringA list of Persistent Volume Claims to be mounted. Syntax: [pvcname:/container/path]

Example:

camel kubernetes export Sample.java --config secret:my-credentials --resource configmap:my-data --volume my-pvc:/container/path

Mount paths follow Camel conventions: configs go to /etc/camel/conf.d/, resources to /etc/camel/resources.d/, and the application is auto-configured to read these paths.

Ingress trait

Add an Ingress resource to expose the application externally (requires a Service resource):

PropertyTypeDescription
ingress.enabledboolCan be used to enable or disable a trait. All traits share this common property (default false).
ingress.annotationsmap[string]stringThe annotations added to the ingress. This can be used to set controller-specific annotations, e.g., when using the NGINX Ingress controller.
ingress.hoststringTo configure the host exposed by the ingress.
ingress.pathstringTo configure the path exposed by the ingress (default /).
ingress.pathTypestringTo configure the path type exposed by the ingress. One of Exact, Prefix, ImplementationSpecific (default to Prefix).
ingress.autoboolTo automatically add an Ingress Resource whenever the route uses an HTTP endpoint consumer (default true).
ingress.tls-hosts[]stringTo configure specific hosts exposed through SNI TLS extension by the ingess.
ingress.tls-secret-namestringTo indicate the secret containing the TLS private key and certificate to use for TLS.

Example:

camel kubernetes export Sample.java --trait ingress.enabled=true --trait ingress.host=example.com --trait ingress.path=/sample

Route trait (OpenShift)

Add an OpenShift Route resource to expose the application externally:

PropertyTypeDescription
route.enabledboolCan be used to enable or disable a trait. All traits share this common property (default false).
route.annotationsmap[string]stringThe annotations added to the route. This can be used to set openshift route specific annotations options.
route.hoststringTo configure the host exposed by the route.
route.tls-terminationstringThe TLS termination type, like edge, passthrough or reencrypt. Refer to the OpenShift route documentation for additional information.
route.tls-certificatestringThe TLS certificate contents or file (file:absolute.path). Refer to the OpenShift route documentation for additional information.
route.tls-keystringThe TLS certificate key contents or file (file:absolute.path). Refer to the OpenShift route documentation for additional information.
route.tls-ca-certificatestringThe TLS CA certificate contents or file (file:absolute.path). Refer to the OpenShift route documentation for additional information.
route.tls-destination-ca-certificatestringThe destination CA contents or file (file:absolute.path). The destination CA certificate provides the contents of the CA certificate of the final destination. When using reencrypt termination, this file should be provided to have routers use it for health checks on the secure connection. If this field is not specified, the router may provide its own destination CA and perform hostname validation using the short service name (service.namespace.svc), which allows infrastructure generated certificates to automatically verify. Refer to the OpenShift route documentation for additional information.
route.tls-insecure-edge-termination-policystringTo configure how to deal with insecure traffic, e.g. Allow, Disable or Redirect traffic. Refer to the OpenShift route documentation for additional information.

Example:

camel kubernetes export Sample.java --cluster-type=openshift --trait route.enabled=true --trait route.host=example.com --trait route.tls-termination=edge

Jolokia trait

Enable JMX access via Jolokia (requires Jolokia configured in the application):

PropertyTypeDescription
jolokia.enabledboolCan be used to enable or disable a trait. All traits share this common property. (default false).
jolokia.container-portintTo configure a different jolokia port exposed by the container (default 8778).
jolokia.container-port-namestringTo configure a different port name for the port exposed by the container (default jolokia).
jolokia.exposeboolCan be used to enable/disable exposure of jolokia via kubernetes Service. (default false).
jolokia.service-portintTo configure a different jolokia port exposed by the service (default 8778). It is applied only when the expose parameter is true.
jolokia.service-port-namestringTo configure a different port name for the port exposed by the service (default jolokia). It is applied only when the expose parameter is true.

Example:

camel kubernetes export Sample.java --trait jolokia.enabled=true --trait jolokia.expose=true

OpenAPI trait

Mount OpenAPI specs from ConfigMaps:

camel kubernetes export Sample.java --open-api configmap:my-spec

Deploy to OpenShift

Use --cluster-type=openshift to generate OpenShift-specific resources (Route, ImageStream, BuildConfig):

camel kubernetes export Sample.java --cluster-type=openshift

The default image builder switches to S2I for OpenShift. Override with --image-builder=jib to push to an external registry instead.

With S2I, set --image-group to your OpenShift project/namespace name, since S2I uses it as part of the image coordinates: image-registry.openshift-image-registry.svc:5000/<project>/<name>:<tag>

Kubernetes run

The run command exports, builds, pushes, and deploys in one step:

camel kubernetes run route.yaml --image-registry=kind

The command auto-detects local clusters (kind, minikube, OpenShift) and configures the registry accordingly. Disable with --disable-auto.

Customize the image:

camel kubernetes run route.yaml --image-registry=kind --image-group camel-experts
camel kubernetes run route.yaml --image quay.io/camel-experts/demo-app:1.0

The run command supports the same trait options as export for customizing the Kubernetes manifest.

Auto reload with --dev

Watch for source file changes and automatically rebuild/redeploy:

camel kubernetes run route.yaml --image-registry=kind --dev

Terminate the process to stop dev mode — the deployment is automatically removed on shutdown.

On macOS, the file watch mechanism is slower due to limited native file operations for Java processes.

Setting properties and resources at runtime

Set properties inline, from files, or from Kubernetes resources:

camel kubernetes run route.yaml --property my-key=my-val
camel kubernetes run route.yaml --property file:/some/directory/file.properties

Properties from ConfigMaps and Secrets

Use --config to mount ConfigMap/Secret data as properties files, automatically configured for Camel property placeholders:

camel kubernetes run route.java --config configmap:game-config
camel kubernetes run route.java --config configmap:game-config/game.properties
camel kubernetes run route.java --config secret:my-credentials

Mount paths: --config configmap: maps to /etc/camel/conf.d/_configmaps/<name>/<key>, --config secret: maps to /etc/camel/conf.d/_secrets/<name>/<key>. Each ConfigMap key becomes a file.

Mounting generic files

Use --resource to mount files without property placeholder configuration. Syntax: [configmap|secret]:name[/key][@path]:

camel kubernetes run route.java --resource configmap:my-data
camel kubernetes run route.java --resource configmap:my-data/config.xml@/etc/my-config.xml

Mount paths: /etc/camel/resources.d/_configmaps/<name>/<key> (or _secrets). Use @path to override the destination.

Show logs

Stream log output from a running deployment:

camel kubernetes logs --name=route

Delete deployments

Remove a deployment and all its resources:

camel kubernetes delete --name=route

Minikube deployment tips

Quick start for local development with Minikube (Camel 4.10+):

minikube start --addons registry --driver=docker
eval $(minikube -p minikube docker-env)
camel kubernetes run demo.camel.yaml

Deployment tips and troubleshooting

  • If there is any error with camel kubernetes run, set --verbose to display additional logging.
  • You may want to examine the generated maven project in .camel-jbang-run/<name>.
  • If there are issues building the container image or deploying the kubernetes manifests, consider disabling the kubernetes cluster detection with --disable-auto.
  • Note that Docker multi-platform build is used. It requires to have followed these Docker requirements.

评论

登录后参与评论

正在加载评论…