Chapter 210. Kubernetes Services Component


Available as of Camel version 2.17

The Kubernetes Services component is one of Kubernetes Components which provides a producer to execute kubernetes service operations and a consumer to consume kubernetes service events.

210.1. Component Options

The Kubernetes Services component has no options.

210.2. Endpoint Options

The Kubernetes Services endpoint is configured using URI syntax:

kubernetes-services:masterUrl

with the following path and query parameters:

210.2.1. Path Parameters (1 parameters):

NameDescriptionDefaultType

masterUrl

Required Kubernetes API server URL

 

String

210.2.2. Query Parameters (28 parameters):

NameDescriptionDefaultType

apiVersion (common)

The Kubernetes API Version to use

 

String

dnsDomain (common)

The dns domain, used for ServiceCall EIP

 

String

kubernetesClient (common)

Default KubernetesClient to use if provided

 

KubernetesClient

portName (common)

The port name, used for ServiceCall EIP

 

String

portProtocol (common)

The port protocol, used for ServiceCall EIP

tcp

String

bridgeErrorHandler (consumer)

Allows for bridging the consumer to the Camel routing Error Handler, which mean any exceptions occurred while the consumer is trying to pickup incoming messages, or the likes, will now be processed as a message and handled by the routing Error Handler. 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

labelKey (consumer)

The Consumer Label key when watching at some resources

 

String

labelValue (consumer)

The Consumer Label value when watching at some resources

 

String

namespace (consumer)

The namespace

 

String

poolSize (consumer)

The Consumer pool size

1

int

resourceName (consumer)

The Consumer Resource Name we would like to watch

 

String

exceptionHandler (consumer)

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

exchangePattern (consumer)

Sets the exchange pattern when the consumer creates an exchange.

 

ExchangePattern

operation (producer)

Producer operation to do on Kubernetes

 

String

connectionTimeout (advanced)

Connection timeout in milliseconds to use when making requests to the Kubernetes API server.

 

Integer

synchronous (advanced)

Sets whether synchronous processing should be strictly used, or Camel is allowed to use asynchronous processing (if supported).

false

boolean

caCertData (security)

The CA Cert Data

 

String

caCertFile (security)

The CA Cert File

 

String

clientCertData (security)

The Client Cert Data

 

String

clientCertFile (security)

The Client Cert File

 

String

clientKeyAlgo (security)

The Key Algorithm used by the client

 

String

clientKeyData (security)

The Client Key data

 

String

clientKeyFile (security)

The Client Key file

 

String

clientKeyPassphrase (security)

The Client Key Passphrase

 

String

oauthToken (security)

The Auth Token

 

String

password (security)

Password to connect to Kubernetes

 

String

trustCerts (security)

Define if the certs we used are trusted anyway or not

 

Boolean

username (security)

Username to connect to Kubernetes

 

String

210.3. Spring Boot Auto-Configuration

The component supports 2 options, which are listed below.

NameDescriptionDefaultType

camel.component.kubernetes-services.enabled

Whether to enable auto configuration of the kubernetes-services component. This is enabled by default.

 

Boolean

camel.component.kubernetes-services.resolve-property-placeholders

Whether the component should resolve property placeholders on itself when starting. Only properties which are of String type can use property placeholders.

true

Boolean

210.4. Eclipse Kura component

Available as of Camel 2.15

This documentation page covers the integration options of Camel with the Eclipse Kura M2M gateway. The common reason to deploy Camel routes into the Eclipse Kura is to provide enterprise integration patterns and Camel components to the messaging M2M gateway. For example you might want to install Kura on Raspberry PI, then read temperature from the sensor attached to that Raspberry PI using Kura services and finally forward the current temperature value to your data center service using Camel EIP and components.

210.4.1. KuraRouter activator

Bundles deployed to the Eclipse Kura are usually developed as bundle activators. So the easiest way to deploy Apache Camel routes into the Kura is to create an OSGi bundle containing the class extending org.apache.camel.kura.KuraRouter class:

public class MyKuraRouter extends KuraRouter {

  @Override
  public void configure() throws Exception {
    from("timer:trigger").
      to("netty-http:http://app.mydatacenter.com/api");
  }

}

Keep in mind that KuraRouter implements the org.osgi.framework.BundleActivator interface, so you need to register its start and stop lifecycle methods while creating Kura bundle component class.

Kura router starts its own OSGi-aware CamelContext. It means that for every class extending KuraRouter, there will be a dedicated CamelContext instance. Ideally we recommend to deploy one KuraRouter per OSGi bundle.

210.4.2. Deploying KuraRouter

Bundle containing your Kura router class should import the following packages in the OSGi manifest:

Import-Package: org.osgi.framework;version="1.3.0",
  org.slf4j;version="1.6.4",
  org.apache.camel,org.apache.camel.impl,org.apache.camel.core.osgi,org.apache.camel.builder,org.apache.camel.model,
  org.apache.camel.component.kura

Keep in mind that you don’t have to import every Camel component bundle you plan to use in your routes, as Camel components are resolved as the services on the runtime level.

Before you deploy your router bundle, be sure that you have deployed (and started) the following Camel core bundles (using Kura GoGo shell)…​

install file:///home/user/.m2/repository/org/apache/camel/camel-core/2.15.0/camel-core-2.15.0.jar
start <camel-core-bundle-id>
install file:///home/user/.m2/repository/org/apache/camel/camel-core-osgi/2.15.0/camel-core-osgi-2.15.0.jar
start <camel-core-osgi-bundle-id>
install file:///home/user/.m2/repository/org/apache/camel/camel-kura/2.15.0/camel-kura-2.15.0.jar
start <camel-kura-bundle-id>

…​and all the components you plan to use in your routes:

install file:///home/user/.m2/repository/org/apache/camel/camel-stream/2.15.0/camel-stream-2.15.0.jar
start <camel-stream-bundle-id>

Then finally deploy your router bundle:

install file:///home/user/.m2/repository/com/example/myrouter/1.0/myrouter-1.0.jar
start <your-bundle-id>

210.4.3. KuraRouter utilities

 Kura router base class provides many useful utilities. This section
explores each of them.

210.4.3.1. SLF4J logger

Kura uses SLF4J facade for logging purposes. Protected member log returns SLF4J logger instance associated with the given Kura router.

public class MyKuraRouter extends KuraRouter {

    @Override
    public void configure() throws Exception {
        log.info("Configuring Camel routes!");
        ...
    }

}

210.4.3.2. BundleContext

Protected member bundleContext returns bundle context associated with the given Kura router.

public class MyKuraRouter extends KuraRouter {

    @Override
    public void configure() throws Exception {
        ServiceReference<MyService> serviceRef = bundleContext.getServiceReference(LogService.class.getName());
        MyService myService = bundleContext.getService(serviceRef);
        ...
    }

}

210.4.3.3. CamelContext

Protected member camelContext is the CamelContext associated with the given Kura router.

public class MyKuraRouter extends KuraRouter {

    @Override
    public void configure() throws Exception {
        camelContext.getStatus();
        ...
    }

}

210.4.3.4. ProducerTemplate

Protected member producerTemplate is the ProducerTemplate instance associated with the given Camel context.

public class MyKuraRouter extends KuraRouter {

    @Override
    public void configure() throws Exception {
        producerTemplate.sendBody("jms:temperature", 22.0);
        ...
    }

}

210.4.3.5. ConsumerTemplate

Protected member consumerTemplate is the ConsumerTemplate instance associated with the given Camel context.

public class MyKuraRouter extends KuraRouter {

    @Override
    public void configure() throws Exception {
        double currentTemperature = producerTemplate.receiveBody("jms:temperature", Double.class);
        ...
    }

}

210.4.3.6. OSGi service resolver

OSGi service resolver (service(Class<T> serviceType)) can be used to easily retrieve service by type from the OSGi bundle context.

public class MyKuraRouter extends KuraRouter {

    @Override
    public void configure() throws Exception {
        MyService myService = service(MyService.class);
        ...
    }

}

If service is not found, a null value is returned. If you want your application to fail if the service is not available, use requiredService(Class) method instead. The requiredService throws IllegalStateException if a service cannot be found.

public class MyKuraRouter extends KuraRouter {

    @Override
    public void configure() throws Exception {
        MyService myService = requiredService(MyService.class);
        ...
    }

}

210.4.4. KuraRouter activator callbacks

Kura router comes with the lifecycle callbacks that can be used to customize the way the Camel router works. For example to configure the CamelContext instance associated with the router just before the former is started, override beforeStart method of the KuraRouter class:

public class MyKuraRouter extends KuraRouter {

  ...

  protected void beforeStart(CamelContext camelContext) {
    OsgiDefaultCamelContext osgiContext = (OsgiCamelContext) camelContext;
    osgiContext.setName("NameOfTheRouter");
  }

}

210.4.5. Loading XML routes from ConfigurationAdmin

Sometimes it is desired to read the XML definition of the routes from the server configuration. This a common scenario for IoT gateways where over-the-air redeployment cost may be significant. To address this requirement each KuraRouter looks for the kura.camel.BUNDLE-SYMBOLIC-NAME.route property from the kura.camel PID using the OSGi ConfigurationAdmin. This approach allows you to define Camel XML routes file per deployed KuraRouter. In order to update a route, just edit an appropriate configuration property and restart a bundle associated with it. The content of the kura.camel.BUNDLE-SYMBOLIC-NAME.route property is expected to be Camel XML route file, for example:

<routes xmlns="http://camel.apache.org/schema/spring">
    <route id="loaded">
        <from uri="direct:bar"/>
        <to uri="mock:bar"/>
    </route>
</routes>

210.4.6. Deploying Kura router as a declarative OSGi service

If you would like to deploy your Kura router as a declarative OSGi service, you can use activate and deactivate methods provided by KuraRouter.

<scr:component name="org.eclipse.kura.example.camel.MyKuraRouter" activate="activate" deactivate="deactivate" enabled="true" immediate="true">
  <implementation class="org.eclipse.kura.example.camel.MyKuraRouter"/>
</scr:component>

210.4.7. See Also

  • Configuring Camel
  • Component
  • Endpoint
  • Getting Started
Red Hat logoGithubRedditYoutubeTwitter

Learn

Try, buy, & sell

Communities

About Red Hat Documentation

We help Red Hat users innovate and achieve their goals with our products and services with content they can trust.

Making open source more inclusive

Red Hat is committed to replacing problematic language in our code, documentation, and web properties. For more details, see the Red Hat Blog.

About Red Hat

We deliver hardened solutions that make it easier for enterprises to work across platforms and environments, from the core datacenter to the network edge.

© 2024 Red Hat, Inc.