Skip to main content
Redhat Developers  Logo
  • Products

    Featured

    • Red Hat Enterprise Linux
      Red Hat Enterprise Linux Icon
    • Red Hat OpenShift AI
      Red Hat OpenShift AI
    • Red Hat Enterprise Linux AI
      Linux icon inside of a brain
    • Image mode for Red Hat Enterprise Linux
      RHEL image mode
    • Red Hat OpenShift
      Openshift icon
    • Red Hat Ansible Automation Platform
      Ansible icon
    • Red Hat Developer Hub
      Developer Hub
    • View All Red Hat Products
    • Linux

      • Red Hat Enterprise Linux
      • Image mode for Red Hat Enterprise Linux
      • Red Hat Universal Base Images (UBI)
    • Java runtimes & frameworks

      • JBoss Enterprise Application Platform
      • Red Hat build of OpenJDK
    • Kubernetes

      • Red Hat OpenShift
      • Microsoft Azure Red Hat OpenShift
      • Red Hat OpenShift Virtualization
      • Red Hat OpenShift Lightspeed
    • Integration & App Connectivity

      • Red Hat Build of Apache Camel
      • Red Hat Service Interconnect
      • Red Hat Connectivity Link
    • AI/ML

      • Red Hat OpenShift AI
      • Red Hat Enterprise Linux AI
    • Automation

      • Red Hat Ansible Automation Platform
      • Red Hat Ansible Lightspeed
    • Developer tools

      • Red Hat Trusted Software Supply Chain
      • Podman Desktop
      • Red Hat OpenShift Dev Spaces
    • Developer Sandbox

      Developer Sandbox
      Try Red Hat products and technologies without setup or configuration fees for 30 days with this shared Openshift and Kubernetes cluster.
    • Try at no cost
  • Technologies

    Featured

    • AI/ML
      AI/ML Icon
    • Linux
      Linux Icon
    • Kubernetes
      Cloud icon
    • Automation
      Automation Icon showing arrows moving in a circle around a gear
    • View All Technologies
    • Programming Languages & Frameworks

      • Java
      • Python
      • JavaScript
    • System Design & Architecture

      • Red Hat architecture and design patterns
      • Microservices
      • Event-Driven Architecture
      • Databases
    • Developer Productivity

      • Developer productivity
      • Developer Tools
      • GitOps
    • Secure Development & Architectures

      • Security
      • Secure coding
    • Platform Engineering

      • DevOps
      • DevSecOps
      • Ansible automation for applications and services
    • Automated Data Processing

      • AI/ML
      • Data Science
      • Apache Kafka on Kubernetes
      • View All Technologies
    • Start exploring in the Developer Sandbox for free

      sandbox graphic
      Try Red Hat's products and technologies without setup or configuration.
    • Try at no cost
  • Learn

    Featured

    • Kubernetes & Cloud Native
      Openshift icon
    • Linux
      Rhel icon
    • Automation
      Ansible cloud icon
    • Java
      Java icon
    • AI/ML
      AI/ML Icon
    • View All Learning Resources

    E-Books

    • GitOps Cookbook
    • Podman in Action
    • Kubernetes Operators
    • The Path to GitOps
    • View All E-books

    Cheat Sheets

    • Linux Commands
    • Bash Commands
    • Git
    • systemd Commands
    • View All Cheat Sheets

    Documentation

    • API Catalog
    • Product Documentation
    • Legacy Documentation
    • Red Hat Learning

      Learning image
      Boost your technical skills to expert-level with the help of interactive lessons offered by various Red Hat Learning programs.
    • Explore Red Hat Learning
  • Developer Sandbox

    Developer Sandbox

    • Access Red Hat’s products and technologies without setup or configuration, and start developing quicker than ever before with our new, no-cost sandbox environments.
    • Explore Developer Sandbox

    Featured Developer Sandbox activities

    • Get started with your Developer Sandbox
    • OpenShift virtualization and application modernization using the Developer Sandbox
    • Explore all Developer Sandbox activities

    Ready to start developing apps?

    • Try at no cost
  • Blog
  • Events
  • Videos

Build and deploy a serverless app with Camel K and Red Hat OpenShift Serverless 1.5.0 Tech Preview

 

April 24, 2020
Shailendra Kumar Singh
Related topics:
JavaKubernetesOperatorsServerless
Related products:
Red Hat OpenShift

Share:

    Red Hat OpenShift Serverless 1.5.0 (currently in tech preview) runs on Red Hat OpenShift Container Platform 4.3. It enables stateful, stateless, and serverless workloads to all operate on a single multi-cloud container platform. Apache Camel K is a lightweight integration platform that runs natively on Kubernetes. Camel K has serverless superpowers.

    In this article, I will show you how to use OpenShift Serverless and Camel K to create a serverless Java application that you can scale up or down on demand.

    Prerequisites

    The following three technologies need to be installed before beginning this exercise:

    • Red Hat OpenShift Container Platform 4.3
    • Red Hat OpenShift Serverless 1.5.0 Tech Preview
    • Apache Camel K Operator 1.0.0 RC1

    Other technologies used

    Knative Serving and Kamel (the Camel K CLI tool) will be installed as part of this exercise. Knative Serving on OpenShift Container Platform 4.3 builds on Kubernetes and Kourier to support deploying and serving serverless applications. It creates a set of custom resource definitions (CRDs) that are used to define and control the behavior of serverless workloads on an OpenShift cluster.

    The kamel CLI tool interacts with the Camel K integration framework, letting us configure our clusters and run integrations. Together with Knative Serving, this tool helps us build and deploy serverless applications and test our integration. The Kamel CLI will run locally to deploy your Camel route directly onto a Kubernetes or OpenShift cluster.

    Install OpenShift Serverless Operator

    OpenShift Serverless 1.5.0 Tech Preview is compatible with OpenShift Container Platform (OCP) 4.3. Assuming that you have OpenShift Container Platform 4.3 in your development environment, navigate to OCP's OperatorHub in the web console. Select OpenShift Serverless Operator from the list of available operators, then click Install, as shown in Figure 1.

    A screenshot of the OperatorHub and OpenShiff

    Before we continue, let's verify that we've installed OpenShift Serverless Operator:

    $ oc get csv -n openshift-operators
    

    You should receive the following confirmation:

    NAME                       DISPLAY                       VERSION REPLACES                    PHASE
    serverless-operator.v1.5.0 OpenShift Serverless Operator 1.5.0    serverless-operator.v1.4.1 Succeeded
    

    Install Knative Serving

    Next, we'll install Knative Serving, which we'll use to deploy our serverless application. The serving.yaml file creates a KnativeServing object in the knative-serving namespace:

    apiVersion: v1
    kind: Namespace
    metadata:
      name: knative-serving
    ---
    apiVersion: operator.knative.dev/v1alpha1
    kind: KnativeServing
    metadata:
      name: knative-serving
      namespace: knative-serving
    

    Enter the following command to apply the object:

    $ oc apply -f serving.yaml
    namespace/knative-serving created
    knativeserving.operator.knative.dev/knative-serving created
    

    Check for pods

    After you have installed the KnativeServing object, check for pods in the new knative-serving-ingress and knative-serving namespaces:

    $ oc get pods -n knative-serving-ingress
    

    You should see the following pods created in the knative-serving-ingress namespace:

    NAME                                    READY STATUS  RESTARTS AGE
    3scale-kourier-control-568f886865-fptx4 1/1   Running 0        27m
    3scale-kourier-gateway-785c6bd959-b2t6c 1/1   Running 0        27m
    

    Now, check the knative-serving namespace:

    NAME                            READY STATUS   RESTARTS AGE
    activator-7cc6dbf497-4zwdf      1/1   Running  0        27m
    autoscaler-798cfcd656-gqkdc     1/1   Running  0        27m
    autoscaler-hpa-5cb5655744-cxff2 1/1   Running  0        27m
    controller-55c7dd95f6-9qftj     1/1   Running  0        27m
    webhook-769f994744-mjsrr        1/1   Running  0        27m
    

    You should also see a new Serverless tab in OpenShift Container Platform's Administrator console, as shown in Figure 2.

    A screenshot of the new Serverless tab in the console.

    Install the Camel K Operator

    Next, we'll install the Camel K Operator. Start by creating a new project for it:

    $ oc new-project camelknative
    

    Install the Camel K Operator from OpenShift Container Platform's OperatorHub, as shown in Figure 3.

    A screenshot of the Camel K operator in the OperatorHub.

    Select the camelknative namespace, as shown in Figure 4.

    A screenshot of options to configure a new operator namespace.

    Verify the installation status:

    $ oc get csv -n camelknative
    

    You should get a confirmation that the installation was successful:

    NAME                        DISPLAY          VERSION   REPLACES                    PHASE
    camel-k-operator.v1.0.0-rc2 Camel K Operator 1.0.0-rc2 camel-k-operator.v1.0.0-rc1 Succeeded
    

    Before we can continue, we need the kamel binary, which we'll use to configure our cluster and run integrations on it.

    Install kamel

    Check for the most recent kamel release here. Once you've downloaded kamel, add it to your system path. On Linux, this would be /usr/bin/kamel.

    Verify that you installed kamel:

    $ kamel version
    Camel K Client 1.0.0-M4
    

    Our development environment is complete. Next, we'll try out a simple deployment.

    Deploy a Camel route

    We'll start with a simple route that uses Undertow for its HTTP consumer:

    // Sample.java
    import org.apache.camel.builder.RouteBuilder;
    
    public class Sample extends RouteBuilder {
    
       @Override
       public void configure() throws Exception {
               from("undertow:http://0.0.0.0:8080/test")
              .setBody(constant("{{env:CAMEL_SETBODY}}"))
              .log("Hello Camel-K");
       }
    }
    

    Run the following to build and deploy the Sample.java route:

    $ kamel run Sample.java --name sample --dependency camel-undertow --env CAMEL_SETBODY="Response received from POD : {{env:HOSTNAME}}"
    integration "sample" created
    

    Test the integration

    Now we'll test our integration. To start, make sure it's running:

    $ oc get it

    You should see the following confirmation:

    NAME      PHASE     KIT                        REPLICAS
    sample    Running   kit-bppjp84iis5hj6nb3vk0   0
    

    Next, we call our pods:

    $ oc get pods
    

    None of the pods has served a request, so the integration is currently scaled to zero:

    NAME                                       READY     STATUS      RESTARTS   AGE
    camel-k-kit-bppjp84iis5hj6nb3vk0-1-build   0/1       Completed   0          18m
    camel-k-operator-775dfccddf-5r7zg          1/1       Running     0          56m
    
    $ oc get deployment sample-4srfn-deployment
    NAME                      READY     UP-TO-DATE   AVAILABLE   AGE
    sample-4srfn-deployment   0/0       0            0           8m3s
    

    When we send a request to the application, it automatically scales to one:

    $ curl http://sample.camelknative.apps.shsinghocp43.lab.com/test
    Response received from POD : sample-4srfn-deployment-5dfbf746c5-dw8wr
    

    Call $ oc get pods again, and you should see the following:

    NAME                                       READY     STATUS      RESTARTS   AGE
    camel-k-kit-bppjp84iis5hj6nb3vk0-1-build   0/1       Completed   0          28m
    camel-k-operator-775dfccddf-5r7zg          1/1       Running     0          66m
    sample-4srfn-deployment-5dfbf746c5-dw8wr   2/2       Running     0          14s
    

    The sample integration has scaled to one:

    $ oc get it
    NAME      PHASE     KIT                        REPLICAS
    sample    Running   kit-bppjp84iis5hj6nb3vk0   1
    
    $ oc get deployment sample-4srfn-deployment
    NAME                      READY     UP-TO-DATE   AVAILABLE   AGE
    sample-4srfn-deployment   1/1       1            1           14m
    

    Once a pod is ideal (when no traffic is served by the application), it automatically scales down to zero:

    NAME                                       READY     STATUS      RESTARTS   AGE
    camel-k-kit-bppjp84iis5hj6nb3vk0-1-build   0/1       Completed   0          31m
    camel-k-operator-775dfccddf-5r7zg          1/1       Running     0          69m
    
    $ oc get it
    NAME      PHASE     KIT                        REPLICAS
    sample    Running   kit-bppjp84iis5hj6nb3vk0   0
    

    Delete the application

    When you're done testing the integration, you can use kamel to delete the simple route we created with Camel K:

    $ kamel delete sample
    Integration sample deleted
    

    Conclusion

    I hope this article has given you a quick start on developing serverless applications with OpenShift Serverless and Camel K. Note again that Red Hat OpenShift Serverless 1.5.0 is currently in tech preview.

    Last updated: February 5, 2024

    Recent Posts

    • Unleashing multimodal magic with RamaLama

    • Integrate Red Hat AI Inference Server & LangChain in agentic workflows

    • Streamline multi-cloud operations with Ansible and ServiceNow

    • Automate dynamic application security testing with RapiDAST

    • Assessing AI for OpenShift operations: Advanced configurations

    Red Hat Developers logo LinkedIn YouTube Twitter Facebook

    Products

    • Red Hat Enterprise Linux
    • Red Hat OpenShift
    • Red Hat Ansible Automation Platform

    Build

    • Developer Sandbox
    • Developer Tools
    • Interactive Tutorials
    • API Catalog

    Quicklinks

    • Learning Resources
    • E-books
    • Cheat Sheets
    • Blog
    • Events
    • Newsletter

    Communicate

    • About us
    • Contact sales
    • Find a partner
    • Report a website issue
    • Site Status Dashboard
    • Report a security problem

    RED HAT DEVELOPER

    Build here. Go anywhere.

    We serve the builders. The problem solvers who create careers with code.

    Join us if you’re a developer, software engineer, web designer, front-end designer, UX designer, computer scientist, architect, tester, product manager, project manager or team lead.

    Sign me up

    Red Hat legal and privacy links

    • About Red Hat
    • Jobs
    • Events
    • Locations
    • Contact Red Hat
    • Red Hat Blog
    • Inclusion at Red Hat
    • Cool Stuff Store
    • Red Hat Summit

    Red Hat legal and privacy links

    • Privacy statement
    • Terms of use
    • All policies and guidelines
    • Digital accessibility

    Report a website issue