tree: 4b110627bf946040acafa59c1ab34b7007fd56bd [path history] [tgz]
  1. Container.java
  2. README.md
  3. RestDSL.java
generic-examples/traits/container/README.md

Camel K Container Trait

In this section you will find examples about fine tuning your Integration using Container trait capability.

The Container trait is a platform trait, it is enabled by default.

Before you begin

Read the general instructions in the root README.md file for setting up your environment and the Kubernetes cluster before looking at this example.

Make sure you've read the installation instructions for your specific cluster before starting the example.

Basic usage

To configure some custom values, run the integration

kamel run \
  --name container \
  Container.java \
  --trait container.image-pull-policy=Always \
  --trait container.request-cpu=0.005 \
  --trait container.limit-cpu=0.2 \
  --trait container.request-memory=100Mi \
  --trait container.limit-memory=500Mi

When you check the values declared by the pod spec

kubectl get pods --selector="camel.apache.org/integration"="container" -o yaml

You should get a result with the values you defined

...
                "imagePullPolicy": "Always",

...
                "resources": {
                    "limits": {
                        "cpu": "200m",
                        "memory": "500Mi"
                    },
                    "requests": {
                        "cpu": "5m",
                        "memory": "100Mi"
                    }
                },
...

Advanced usages

The container and service port configuration needs needs the presence of a service, else it will be ignored.

For these example, we use an example route exposing some rest endpoint. This will enable the service and expose the container port by default.

Warning

Be careful when changing the default ports value and/or name as it can have some side effects.

Service Port

To define a custom service port, run the integration

kamel run --name restcontainer \
  RestDSL.java \
  --trait service.enabled=true \
  --trait container.service-port=8082 \
  --trait container.service-port-name=myserviceport

When you check the values declared by the service spec

kubectl get service restcontainer  -o jsonpath='{.spec.ports}'

You should get a result with the values you defined

[{"name":"myserviceport","port":8082,"protocol":"TCP","targetPort":"http"}]

For more details on the Service trait, see the example README.md file

Container Port

The definition of a custom container port need some modification of quarkus default property to be effective.

kamel run \
  --property quarkus.http.port=8081 \
  --name restcontainer \
  RestDSL.java \
  --trait container.port=8081 \
  --trait container.port-name=mycontainerport
kubectl get pods --selector="camel.apache.org/integration"="restcontainer" \
    -o jsonpath= -o jsonpath='{.items[*].spec.containers[*].ports}'

You should get a result with the values you defined

[{"containerPort":8081,"name":"mycontainerport","protocol":"TCP"}]