Camel K

Service Trait

The Service trait exposes the Integration with a Service resource so that it can be accessed by other applications (or Integrations) in the same namespace.

this trait is automatically disabled if the Knative Service trait is enabled.

It’s enabled by default if the integration depends on a Camel component that can expose a HTTP endpoint.

This trait is available in the following profiles: Kubernetes, Knative, OpenShift.

Configuration

Trait properties can be specified when running any integration with the CLI:

$ kamel run --trait service.[key]=[value] --trait service.[key2]=[value2] integration.yaml

The following configuration options are available:

Property Type Description

service.enabled

bool

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

service.auto

bool

To automatically detect from the code if a Service needs to be created.

service.nodePort

bool

Enable Service to be exposed as NodePort (default false).

Deprecated: Use service type instead.

service.type

github.com/apache/camel-k/v2/pkg/apis/camel/v1/trait.ServiceType

The type of service to be used, either 'ClusterIP', 'NodePort' or 'LoadBalancer'.

service.annotations

map[string]string

The annotations added to the Service object.

service.labels

map[string]string

The labels added to the Service object.

service.networkPolicyEnabled

bool

Enables the NetworkPolicy managed by the Service trait. Defaults to false. When enabled, at least one of the namespace or pod selectors must be configured.

service.networkPolicyNamespaceSelector

map[string]string

Labels used to restrict the source namespaces allowed by the NetworkPolicy.

service.networkPolicyPodSelector

map[string]string

Labels used to restrict the source pods allowed by the NetworkPolicy.

service.ports

[]string

List of container ports available in the container to expose (syntax: <port-name>;<port-number>;<container-port-number>[;<port-protocol]). When omitted, port-protocol (admitted values TCP, UDP or SCTP) is TCP. Don’t use this for the primary http managed port (which is managed by container trait). Don’t use in Knative based environments.

the variable names are "snake case" if you’re using in kamel CLI, for example trait.myParam has to be translated as -t trait.my-param

Examples

  • Expose a Service (we call it hello) on a port (85`) which is used internally by your application (8085):

    $ kamel run PlatformHttpServer.java -p quarkus.http.port=8085 -t container.ports=hello;8085 -t service.ports=hello;85;8085
  • Expose an UDP Service (we call it udp) on a port (95) which is used internally by your application (9095):

    $ kamel run MyUDPServer.java -t container.ports=udp;95;UDP -t service.ports=udp;95;9095;UDP
  • Restrict a Service with an ingress NetworkPolicy. The example allows requests only from pods labeled app: my-client in namespaces labeled kubernetes.io/metadata.name: backend:

    spec:
      traits:
        service:
          enabled: true
          network-policy-enabled: true
          network-policy-namespace-selector:
            kubernetes.io/metadata.name: backend
          network-policy-pod-selector:
            app: my-client