Running an Integration
After completing the installation you should be connected to a Kubernetes/OpenShift cluster
and have the kamel
CLI correctly configured.
Ensure you’re connected to the cluster by executing a simple command using the Kubernetes CLI:
kubectl get pod
Just replace kubectl
with oc
if you’re using OpenShift. If everything is correctly configured you should get a response from the Kubernetes API
server (you should see at least the camel-k-operator
running).
You are now ready to create your first integration using Camel K. Just create a new Groovy file with the following content:
from('timer:tick?period=3000')
.setBody().constant('Hello world from Camel K')
.to('log:info')
You can run it on the cluster by executing:
kamel run hello.groovy
Integrations can be written in multiple languages. We are collecting examples in our Github repository.
Monitoring the application status
Camel K integrations follow a lifecycle composed of several steps before getting into the Running
state.
You can check the status of all integrations by executing the following command:
kamel get
Log the standard output
Camel K integrations follow a lifecycle composed of several steps before getting into the Running
state.
You can check the status of all integrations by executing the following command:
kamel logs hello
Running an Integration in Development mode
Camel K provide a very nice dev mode feature that will allow you to apply any change to your Integration code reactively. Check out the Camel K dev mode
Running an Integration without CLI
You can run your integration also if you have no CLI available. kamel
CLI manages a lot of fancy features but you can create an Integration Custom Resource with all the configuration expected to run your application.
As an example, let’s get the result of a dry run for a sample route:
kamel run Sample.java -o yaml
It will return the expected Integration custom resource (you can type it manually according to the specification linked above):
apiVersion: camel.apache.org/v1
kind: Integration
metadata:
creationTimestamp: null
name: my-integration
namespace: default
spec:
sources:
- content: "
import org.apache.camel.builder.RouteBuilder;
public class Sample extends RouteBuilder {
@Override
public void configure()
throws Exception {
from(\"timer:tick\")
.log(\"Hello Integration!\");
}
}"
name: Sample.java
status: {}
We can save this custom resource in a yaml file, ie, my-integration.yaml
. Once done, we can run the integration storing the Integration custom resource, via kubectl
, UI, API call or whichever mean we have to call our Kubernetes cluster. In our example, we’ll do this through kubectl
CLI:
kubectl apply -f my-integration.yaml
...
integration.camel.apache.org/my-integration created
The operator will now take care to run the Integration accordingly.