[[running-integration]]
= Running an Integration

After completing the xref:installation/installation.adoc[installation] you should be able to run an Integration containing a Camel DSL application. The most basic configuration required is to wrap a Camel route into the Integration custom resource. Let's start with a java DSL Camel application:

```yaml
apiVersion: camel.apache.org/v1
kind: Integration
metadata:
  name: my-integration
spec:
  sources:
  - content: |
      import org.apache.camel.builder.RouteBuilder;

      public class Test extends RouteBuilder {
          @Override
          public void configure() throws Exception {
              from("timer:java?period=1000")
                  .setBody()
                      .simple("Hello Camel from ${routeId}")
                  .log("${body}");
          }
      }
    name: Test.java
```

Save the above as `my-integration.yaml` and apply with `kubectl apply -f my-integration.yaml`. Once the resource is stored in the cloud, the operator will take care to build, deploy and run the Camel application for you.

You can monitor the Integration with `kubectl get it -w`:

```bash
NAME             PHASE          READY   RUNTIME PROVIDER   RUNTIME VERSION   CATALOG VERSION   KIT                        REPLICAS
my-integration   Building Kit           quarkus            3.8.1             3.8.1             kit-crbekb6n5tgc73cb1tkg
my-integration   Deploying              quarkus            3.8.1             3.8.1             kit-crbekb6n5tgc73cb1tkg
my-integration   Running        False   quarkus            3.8.1             3.8.1             kit-crbekb6n5tgc73cb1tkg   0
my-integration   Running        False   quarkus            3.8.1             3.8.1             kit-crbekb6n5tgc73cb1tkg   1
my-integration   Running        False   quarkus            3.8.1             3.8.1             kit-crbekb6n5tgc73cb1tkg   1
my-integration   Running        True    quarkus            3.8.1             3.8.1             kit-crbekb6n5tgc73cb1tkg   1
```

NOTE: we're using the shortname `it` which can be used instead longer `integration`

The first time you run the application it may takes some minute as it needs to download dependencies and build the base images that will be reused later. You may notice certain parameters like the phase and the readiness of the application. You can also see the runtime information and the number or replicas running for this application. You will learn more about IntegrationKit and other aspects in the other sections of the documentations.

You can now check the Pods which are running the application and log to see what's going on:

```
kubectl get pods
NAME                              READY   STATUS    RESTARTS   AGE
my-integration-7d86444646-62497   1/1     Running   0          118s

kubectl logs my-integration-7d86444646-62497
2024-09-03 10:53:04,370 INFO  [org.apa.cam.k.Runtime] (main) Apache Camel K Runtime 3.8.1
2024-09-03 10:53:04,378 INFO  [org.apa.cam.qua.cor.CamelBootstrapRecorder] (main) Bootstrap runtime: org.apache.camel.quarkus.main.CamelMainRuntime
2024-09-03 10:53:04,389 INFO  [org.apa.cam.mai.MainSupport] (main) Apache Camel (Main) 4.4.1 is starting
2024-09-03 10:53:04,973 INFO  [org.apa.cam.k.sup.SourcesSupport] (main) Loading routes from: SourceDefinition{name='Test', language='java', type='source', location='file:/etc/camel/sources/Test.java', }
2024-09-03 10:53:15,275 INFO  [org.apa.cam.imp.eng.AbstractCamelContext] (main) Apache Camel 4.4.1 (camel-1) is starting
2024-09-03 10:53:15,471 INFO  [org.apa.cam.imp.eng.AbstractCamelContext] (main) Routes startup (started:1)
2024-09-03 10:53:15,471 INFO  [org.apa.cam.imp.eng.AbstractCamelContext] (main)     Started route1 (timer://java)
2024-09-03 10:53:15,472 INFO  [org.apa.cam.imp.eng.AbstractCamelContext] (main) Apache Camel 4.4.1 (camel-1) started in 194ms (build:0ms init:0ms start:194ms)
2024-09-03 10:53:15,479 INFO  [io.quarkus] (main) camel-k-integration 2.5.0-SNAPSHOT on JVM (powered by Quarkus 3.8.3) started in 30.798s.
2024-09-03 10:53:15,480 INFO  [io.quarkus] (main) Profile prod activated.
2024-09-03 10:53:15,480 INFO  [io.quarkus] (main) Installed features: [camel-bean, camel-core, camel-java-joor-dsl, camel-k-core, camel-k-runtime, camel-kubernetes, camel-timer, cdi, kubernetes-client, smallrye-context-propagation, vertx]
2024-09-03 10:53:16,478 INFO  [route1] (Camel (camel-1) thread #1 - timer://java) Hello Camel from route1
2024-09-03 10:53:17,470 INFO  [route1] (Camel (camel-1) thread #1 - timer://java) Hello Camel from route1
...
```

NOTE: if the above example failed, have a look at xref:troubleshooting/troubleshooting.adoc[how to troubleshoot a Camel K Integration].

== YAML DSL

In the example above we've seen how to run a Java DSL Camel application. You can use any other xref:languages/languages.adoc[Camel DSL compatible] in the same way. However, the Yaml DSL is a bit peculiar as it is a first class citizen for Camel K. Since the Integration is already a Yaml specification, then, Camel K provides a first class mechanism to embed the Yaml DSL in the Integration `.spec.flows`:

```yaml
apiVersion: camel.apache.org/v1
kind: Integration
metadata:
  name: my-it
spec:
  flows:
  - from:
      parameters:
        period: "1000"
      steps:
      - setBody:
          simple: Hello Camel from ${routeId}
      - log: ${body}
      uri: timer:yaml
```

You can see the specification is a lot neater, so, try choosing Yaml DSL whenever it's possible.

== Runtime provider

Camel K was originally equipped with a dedicated runtime known as Camel K Runtime. This is a lightweight layer on top of Camel Quarkus. However, you can directly run plain regular Camel Quarkus runtime applications as well. You will learn the concept of traits later on. For now, just be aware that you can run any Integration setting the plain Quarkus runtime using `camel` trait configuration. Here an example of how that would be:

```yaml
apiVersion: camel.apache.org/v1
kind: Integration
metadata:
  name: my-plain-quarkus-it
spec:
  flows:
  - from:
      parameters:
        period: "1000"
      steps:
      - setBody:
          simple: Hello Camel from ${routeId}
      - log: ${body}
      uri: timer:yaml
  traits:
    camel:
      runtimeProvider: plain-quarkus
```

NOTE: we plan to graduate plain Camel Quarkus runtime as default runtime in the future (likely in the next major release). We therefore recommend to use the plain Camel Quarkus runtime in any of your Integrations already.

== Using Kamel CLI

Camel K works very well with any Kubernetes compatible user interface (such as CLI as `kubectl`, `oc` or any other visual tooling). However we do provide a simple CLI that helps you performing most of the Integration works in an easier fashion: it's xref:running/running-cli.adoc[`kamel` CLI].
