K8s Deployment Sample 2: Content Based Routing

Let's define a content-based routing scenario using WSO2 Micro Integrator and deploy it on your Kubernetes environment.


Step 1 - Create the integration solution

Let's use the Content Routing integration template in WSO2 Integration Studio:

  1. Open WSO2 Integration Studio.
  2. In the Getting Started view, select the Content Based Routing template.

  3. Give a project name and click Finish.

    k8s project structure

  4. Create a Kubernetes Project inside the integration project.

    1. Right-click the content-routing-sample project, go to New -> Kubernetes Exporter:

      Create Kubernetes Project

    2. In the Kubernetes Exporter Information for K8s EI Operator dialog box that opens, enter the following details:

      Parameter Description
      Kubernetes Exporter Name Give a unique name for the project.
      Integration Name This name will be used to identify the integration solution in the kubernetes custom resource. Let's use content-routing as the integration name for this example.
      Number of Replicas Specify the number of pods that should be created in the kubernetes cluster.
      Base Image Repository Specify the base Micro Integrator Docker image for your solution. For this example, let's use the Micro Integrator docker image from the WSO2 public docker registry: wso2/wso2mi.

      Note that the image value format should be 'docker_user_name/repository_name'.
      Base Image Tag Give a tag name for the base Docker image.
      Target Image Repository The Docker repository to which the Docker image will be pushed: 'docker_user_name/repository_name'.
      Target Image Tag Give a tag name for the Docker image.

    3. Click Finish.

Your integration project with the content routing sample is now ready to be deployed in Kubernetes.

k8s project structure

Step 2 - Build and Push the Docker image


Be sure to start your Docker instance before building the image. If Docker is not started, the build process will fail.

There are two ways to build a Docker image of the integration solution and push it to your Docker registry:

  • Using Maven:

    Before you begin

    You need Maven 3.5.2 or a later version when you build the Docker image manually (without using WSO2 Integration Studio).

    1. Open a terminal and navigate to the integration project.
    2. Execute the following command.

      Be sure to specify the user name and password of the correct Docker registry.

      mvn clean install -Dmaven.test.skip=true -Ddockerfile.username={username} -Ddockerfile.password={password} 

    This will build the Docker image and then push it to the specified Docker registry.

  • Using WSO2 Integration Studio:

    1. Open the pom.xml file in the Kubernetes exporter.
    2. Ensure that the composite exporter is selected under Dependencies and click Build & Push.

    3. In the dialog box that opens, enter the credentials of your Docker registry to which the image should be pushed.

      docker registry credentials

    4. Click Push Image.

Run the docker image ls command to verify that the Docker image is created.

Step 3 - Deploy the solution in K8s


Before you begin, the API Kubernetes Operator should be installed in your Kubernetes environment.

Follow the steps given below:

  1. Open the integration_cr.yaml file from the Kubernetes project in WSO2 Integration Studio.
  2. See that the integration details of the content-routing solution are updated. Be sure to add the image name in the following format: docker_user/repository:tag

    apiVersion: "wso2.com/v1alpha2"
    kind: "Integration"
      name: "content-routing"
      image: "<Docker image for the Content-Based Routing Scenario>"
        minReplicas: 1
  3. Open a terminal and start the Kubernetes cluster.

  4. Navigate to the location of your integration_cr.yaml file, and execute the following command to deploy the integration solution in the Kubernetes cluster:

    kubectl apply -f integration_cr.yaml

When the integration is successfully deployed, it should create the content-routing integration, content-routing-deployment, content-routing-service, and ei-operator-ingress as follows:


The api-operator-ingress is not created if you have disabled the ingress controller.

kubectl get integration

content-routing                           40s

kubectl get deployment

NAME                         READY   UP-TO-DATE   AVAILABLE   AGE
content-routing-deployment   1/1     1            1           2m

kubectl get services
NAME                         TYPE        CLUSTER-IP       EXTERNAL-IP   PORT(S)       AGE
content-routing-service      ClusterIP   <none>        8290/TCP      2m
kubernetes                   ClusterIP        <none>        443/TCP       2d
k8s-api-operator             ClusterIP     <none>        443/TCP       1d

kubectl get ingress
NAME                   HOSTS                      ADDRESS     PORTS     AGE
api-operator-ingress   wso2ei.ingress.wso2.com   80, 443   2m

Step 4 - Test the deployment

Let's invoke the service without going through the ingress controller.

  1. Create a request.xml file as follows:


  2. Apply port forwarding as shown below. This will allow you to invoke the service without going through the Ingress controller:

    kubectl port-forward service/content-routing-service 8290:8290

  3. Execute the following command to invoke the service:

    curl -X POST -d @request.xml http://localhost:8290/ArithmaticOperationService -H "Content-Type: text/xml"

You will receive the following SOAP response:

<?xml version="1.0" encoding="UTF-8" ?>
<SOAP-ENV:Envelope xmlns:SOAP-ENV='http://schemas.xmlsoap.org/soap/envelope/' xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' xmlns:s='http://www.w3.org/2001/XMLSchema'>
  <SOAP-ENV:Body><AddIntegerResponse xmlns="http://tempuri.org"><AddIntegerResult>35</AddIntegerResult></AddIntegerResponse></SOAP-ENV:Body>