Chapter 2. Getting started with Camel K
This chapter explains how to install Red Hat Integration - Camel K on OpenShift and how to set up your development environment. This chapter also explains how to develop and deploy simple Camel K integrations written in Java, XML, and YAML.
- Section 2.1, “Installing Camel K from the OpenShift OperatorHub”
- Section 2.2, “Installing OpenShift Serverless from the OperatorHub”
- Section 2.3, “Installing the Camel K and OpenShift command line tools”
- Section 2.4, “Setting up your Camel K development environment”
- Section 2.5, “Developing Camel K integrations in Java”
- Section 2.6, “Developing Camel K integrations in XML”
- Section 2.7, “Developing Camel K integrations in YAML”
- Section 2.8, “Running Camel K integrations”
- Section 2.9, “Running Camel K integrations in development mode”
2.1. Installing Camel K from the OpenShift OperatorHub Copy linkLink copied to clipboard!
You can install the Red Hat Integration - Camel K Operator on your OpenShift cluster from the OperatorHub. The OperatorHub is available from the OpenShift Container Platform web console and provides an interface for cluster administrators to discover and install Operators. For more details on the OperatorHub, see the OpenShift documentation.
Prerequisites
- You must have cluster administrator access to an OpenShift 4.3 cluster
You do not need to create a pull secret when installing Camel K from the OpenShift OperatorHub. The Camel K Operator automatically reuses the OpenShift cluster-level authentication to pull the Camel K image from registry.redhat.io
.
Procedure
- In the OpenShift Container Platform web console, log in using an account with cluster administrator privileges.
Create a new OpenShift project:
- In the left navigation menu, click Home > Project > Create Project.
-
Enter a project name, for example,
my-camel-k-project
, and click Create.
- In the left navigation menu, click Catalog > OperatorHub.
-
In the Filter by keyword text box, enter
Camel K
to find the Red Hat Integration - Camel K Operator. - Read the information about the Operator, and click Install. This displays the Create Operator Subscription page.
Select the following subscription settings:
- Installation Mode > A specific namespace on the cluster > my-camel-k-project
- Update Channel > techpreview
Approval Strategy > Automatic
NoteThe Installation mode > All namespaces on the cluster and Approval Strategy > Manual settings are also available if required by your environment.
- Click Subscribe. This displays the Operators > Installed Operators page.
- Wait a few moments until the Status for the Camel K Operator displays Succeeded and the subscription is Up to Date.
Additional resources
2.2. Installing OpenShift Serverless from the OperatorHub Copy linkLink copied to clipboard!
You can install the OpenShift Serverless Operator on your OpenShift cluster from the OperatorHub. The OperatorHub is available from the OpenShift Container Platform web console and provides an interface for cluster administrators to discover and install Operators. For more details on the OperatorHub, see the OpenShift documentation.
The OpenShift Serverless Operator supports both Knative Serving and Knative Eventing features. For more details, see Getting started with OpenShift Serverless.
Prerequisites
- You must have cluster administrator access to an OpenShift 4.3 cluster
- See Installing OpenShift Serverless in the OpenShift documentation
Procedure
- In the OpenShift Container Platform web console, log in using an account with cluster administrator privileges.
- In the left navigation menu, click Catalog > OperatorHub.
-
In the Filter by keyword text box, enter
Serverless
to find the OpenShift Serverless Operator. - Read the information about the Operator, and click Install. This displays the Create Operator Subscription page.
Select the default subscription settings:
- Installation Mode > All namespaces on the cluster
- Update Channel > Select the channel that matches your OpenShift version, for example, 4.3
Approval Strategy > Automatic
NoteThe Approval Strategy > Manual setting is also available if required by your environment.
- Click Subscribe. This displays the Operators > Installed Operators page.
- Wait a few moments until the Status for the Serverless displays Succeeded and the subscription is Up to Date.
For more details, see Installing OpenShift Serverless in the OpenShift documentation.
Next steps
You must install the following Knative components using the steps in the OpenShift documentation:
2.3. Installing the Camel K and OpenShift command line tools Copy linkLink copied to clipboard!
Camel K and OpenShift provide command line tools to deploy and manage your integrations in the cloud. This section explains how to install the following Command Line Interface (CLI) tools:
-
kamel
- Camel K CLI -
oc
- OpenShift Container Platform CLI -
kn
- OpenShift Serverless CLI
These command line tools are all available on Linux, Windows, and Mac.
Prerequisites
You must have access to an OpenShift cluster on which the Camel K Operator and OpenShift Serverless Operator are installed:
Procedure
- In the OpenShift Container Platform web console, log in using an account with developer or administrator privileges.
-
Click the
help icon in the toolbar, and select Command Line Tools.
-
Download and extract the
oc
- OpenShift CLI archive if this tool is not already installed. For more details, see the OpenShift CLI documentation. -
Download and extract the
kn
- OpenShift Serverless CLI archive if this tool is not already installed. For more details, see the OpenShift Serverless CLI documentation. -
Download and extract the
kamel
- Camel K CLI archive to install. -
Add the
kamel
binary file to your system path. For example, on Linux, you can putkamel
in/usr/bin
. Log into your OpenShift cluster using the
oc
client tool, for example:oc login --token=my-token --server=https://my-cluster.example.com:6443
$ oc login --token=my-token --server=https://my-cluster.example.com:6443
Copy to Clipboard Copied! Toggle word wrap Toggle overflow Enter the following command to verify the installation of the
kamel
client tool:kamel --help
$ kamel --help
Copy to Clipboard Copied! Toggle word wrap Toggle overflow
Additional resources
2.4. Setting up your Camel K development environment Copy linkLink copied to clipboard!
You must set up your environment with the recommended development tooling before you can automatically deploy the Camel K quick start tutorials. This section explains how to install the recommended Visual Studio (VS) Code IDE and the extensions that it provides for Camel K.
VS Code is recommended for ease of use and the best developer experience of Camel K. This includes automatic completion of Camel DSL code and Camel K traits, and automatic execution of tutorial commands. However, you can manually enter your code and tutorial commands using your chosen IDE instead of VS Code.
Prerequisites
You must have access to an OpenShift cluster on which the Camel K Operator and OpenShift Serverless Operator are installed:
- Section 2.3, “Installing the Camel K and OpenShift command line tools”
Procedure
Install VS Code on your development platform. For example, on Red Hat Enterprise Linux:
Install the required key and repository:
sudo rpm --import https://packages.microsoft.com/keys/microsoft.asc sudo sh -c 'echo -e "[code]\nname=Visual Studio Code\nbaseurl=https://packages.microsoft.com/yumrepos/vscode\nenabled=1\ngpgcheck=1\ngpgkey=https://packages.microsoft.com/keys/microsoft.asc" > /etc/yum.repos.d/vscode.repo'
$ sudo rpm --import https://packages.microsoft.com/keys/microsoft.asc $ sudo sh -c 'echo -e "[code]\nname=Visual Studio Code\nbaseurl=https://packages.microsoft.com/yumrepos/vscode\nenabled=1\ngpgcheck=1\ngpgkey=https://packages.microsoft.com/keys/microsoft.asc" > /etc/yum.repos.d/vscode.repo'
Copy to Clipboard Copied! Toggle word wrap Toggle overflow Update the cache and install the VS Code package:
yum check-update sudo yum install code
$ yum check-update $ sudo yum install code
Copy to Clipboard Copied! Toggle word wrap Toggle overflow For details on installing on other platforms, see the VS Code installation documentation.
-
Enter the
code
command to launch the VS Code editor. For more details, see the VS Code command line documentation. Install the VS Code Camel Extension Pack, which includes the extensions required for Camel K. For example, in VS Code:
- In the left navigation bar, click Extensions.
- In the search box, enter Apache Camel.
Select the Extension Pack for Apache Camel by Red Hat, and click Install.
For more details, see the instructions for the Extension Pack for Apache Camel by Red Hat.
Install the VS Code Didact extension, which you can use to automatically run quick start tutorial commands by clicking links in the tutorial. For example, in VS Code:
- In the left navigation bar, click Extensions.
- In the search box, enter Didact.
Select the extension, and click Install.
For more details, see the instructions for the Didact extension.
2.5. Developing Camel K integrations in Java Copy linkLink copied to clipboard!
This section shows how to develop a simple Camel K integration in Java DSL. Writing an integration in Java to be deployed using Camel K is the same as defining your routing rules in Camel. However, you do not need to build and package the integration as a JAR when using Camel K.
You can use any Camel component directly in your integration routes. Camel K automatically handles the dependency management and imports all the required libraries from the Camel catalog using code inspection.
Procedure
Enter the
kamel init
command to generate a simple Java integration file. For example:kamel init HelloCamelK.java
$ kamel init HelloCamelK.java
Copy to Clipboard Copied! Toggle word wrap Toggle overflow Open the generated integration file in your IDE and edit as appropriate. For example, the
HelloCamelK.java
integration automatically includes the Cameltimer
andlog
components to help you get started:Copy to Clipboard Copied! Toggle word wrap Toggle overflow
Next steps
2.6. Developing Camel K integrations in XML Copy linkLink copied to clipboard!
This section explains how to develop a simple Camel K integration in classic XML DSL. Writing an integration in XML to be deployed using Camel K is the same as defining your routing rules in Camel.
You can use any Camel component directly in your integration routes. Camel K automatically handles the dependency management and imports all the required libraries from the Camel catalog using code inspection.
Procedure
Enter the
kamel init
command to generate a simple XML integration file. For example:kamel init hello-camel-k.xml
$ kamel init hello-camel-k.xml
Copy to Clipboard Copied! Toggle word wrap Toggle overflow Open the generated integration file in your IDE and edit as appropriate. For example, the
hello-camel-k.xml
integration automatically includes the Cameltimer
andlog
components to help you get started:Copy to Clipboard Copied! Toggle word wrap Toggle overflow
Next steps
2.7. Developing Camel K integrations in YAML Copy linkLink copied to clipboard!
This section explains how to develop a simple Camel K integration in YAML DSL. Writing an integration in YAML to be deployed using Camel K is the same as defining your routing rules in Camel.
You can use any Camel component directly in your integration routes. Camel K automatically handles the dependency management and imports all the required libraries from the Camel catalog using code inspection.
Procedure
Enter the
kamel init
command to generate a simple XML integration file. For example:kamel init hello.camelk.yaml
$ kamel init hello.camelk.yaml
Copy to Clipboard Copied! Toggle word wrap Toggle overflow Open the generated integration file in your IDE and edit as appropriate. For example, the
hello.camelk.yaml
integration automatically includes the Cameltimer
andlog
components to help you get started:Copy to Clipboard Copied! Toggle word wrap Toggle overflow ImportantIntegrations written in YAML must have a file name with the pattern
*.camelk.yaml
or a first line of# camel-k: language=yaml
.
Additional resources
2.8. Running Camel K integrations Copy linkLink copied to clipboard!
You can run Camel K integrations in the cloud on your OpenShift cluster from the command line using the kamel run
command.
Prerequisites
- You must have access to an OpenShift cluster on which the Camel K Operator is installed. For more details, see Section 2.1, “Installing Camel K from the OpenShift OperatorHub”.
- Section 2.3, “Installing the Camel K and OpenShift command line tools”.
- Section 2.4, “Setting up your Camel K development environment”.
- You must already have a Camel integration written in Java, XML, or YAML DSL.
Procedure
Log into your OpenShift cluster using the
oc
client tool, for example:oc login --token=my-token --server=https://my-cluster.example.com:6443
$ oc login --token=my-token --server=https://my-cluster.example.com:6443
Copy to Clipboard Copied! Toggle word wrap Toggle overflow Ensure that the Camel K Operator is running, for example:
oc get pod
$ oc get pod NAME READY STATUS RESTARTS AGE camel-k-operator-86b8d94b4-pk7d6 1/1 Running 0 6m28s
Copy to Clipboard Copied! Toggle word wrap Toggle overflow Enter the
kamel run
command to run your integration in the cloud on OpenShift. For example:Java example
kamel run HelloCamelK.java
$ kamel run HelloCamelK.java integration "hello-camel-k" created
Copy to Clipboard Copied! Toggle word wrap Toggle overflow XML example
kamel run hello-camel-k.xml
$ kamel run hello-camel-k.xml integration "hello-camel-k" created
Copy to Clipboard Copied! Toggle word wrap Toggle overflow YAML example
kamel run hello.camelk.yaml
$ kamel run hello.camelk.yaml integration "hello" created
Copy to Clipboard Copied! Toggle word wrap Toggle overflow Enter the
kamel get
command to check the status of the integration:kamel get
$ kamel get NAME PHASE KIT hello Building Kit kit-bq666mjej725sk8sn12g
Copy to Clipboard Copied! Toggle word wrap Toggle overflow When the integration runs for the first time, Camel K builds the integration kit for the container image, which downloads all the required Camel modules and adds them to the image classpath.
Enter
kamel get
again to verify that the integration is running:kamel get
$ kamel get NAME PHASE KIT hello Running kit-bq666mjej725sk8sn12g
Copy to Clipboard Copied! Toggle word wrap Toggle overflow Enter the
kamel log
command to print the log tostdout
:Copy to Clipboard Copied! Toggle word wrap Toggle overflow -
Press
Ctrl-C
to terminate logging in the terminal.
Additional resources
-
For more details on the
kamel run
command, enterkamel run --help
- For faster deployment turnaround times, see Section 2.9, “Running Camel K integrations in development mode”
- For examples of using development tooling to run integrations, see VS Code Tooling for Apache Camel K by Red Hat
- See also Section 5.1, “Managing Camel K integrations”
2.9. Running Camel K integrations in development mode Copy linkLink copied to clipboard!
You can run Camel K integrations in development mode on your OpenShift cluster from the command line. Using development mode, you can iterate quickly on integrations in development and get fast feedback on your code.
When you specify the kamel run
command with the --dev
option, this deploys the integration in the cloud immediately and shows the integration logs in the terminal. You can then change the code and see the changes automatically applied instantly to the remote integration Pod on OpenShift. The terminal automatically displays all redeployments of the remote integration in the cloud.
The artifacts generated by Camel K in development mode are identical to those that you run in production. The purpose of development mode is faster development.
Prerequisites
- You must have access to an OpenShift cluster on which the Camel K Operator is installed. For more details, see Section 2.1, “Installing Camel K from the OpenShift OperatorHub”.
- Section 2.3, “Installing the Camel K and OpenShift command line tools”.
- Section 2.4, “Setting up your Camel K development environment”.
- You must already have a Camel integration written in Java, XML, or YAML DSL.
Procedure
Log into your OpenShift cluster using the
oc
client tool, for example:oc login --token=my-token --server=https://my-cluster.example.com:6443
$ oc login --token=my-token --server=https://my-cluster.example.com:6443
Copy to Clipboard Copied! Toggle word wrap Toggle overflow Ensure that the Camel K Operator is running, for example:
oc get pod
$ oc get pod NAME READY STATUS RESTARTS AGE camel-k-operator-86b8d94b4-pk7d6 1/1 Running 0 6m28s
Copy to Clipboard Copied! Toggle word wrap Toggle overflow Enter the
kamel run
command with--dev
to run your integration in development mode on OpenShift in the cloud. The following shows a simple Java example:Copy to Clipboard Copied! Toggle word wrap Toggle overflow Edit the content of your integration DSL file, save your changes, and see the changes displayed instantly in the terminal. For example:
Copy to Clipboard Copied! Toggle word wrap Toggle overflow -
Press
Ctrl-C
to terminate logging in the terminal.
Additional resources
-
For more details on the
kamel run
command, enterkamel run --help
- For examples of using development tooling to run integrations, see VS Code Tooling for Apache Camel K by Red Hat
- Section 5.1, “Managing Camel K integrations”
- Section 4.6, “Configuring Camel K integration dependencies”