Skip to content

K8s Deployment Sample 1: Hello World Scenario

Let's define a basic Hello World scenario using WSO2 Micro Integrator and deploy it on your Kubernetes environment.

Prerequisites

Step 1: Create the integration solution

Follow the steps given below.

  1. Create a Maven Multi Module project using WSO2 Integration Studio.

    Create Maven Multi Module Project

  2. Create an ESB Config Project inside the Maven Multi Module project:

    Right-click the Maven Multi Module project in the project explorer, go to New → Project, and select ESB Config Project to open the New ESB Config Project dialog.

    Create ESB Config Project

  3. Add the following proxy service configuration inside the ESB Config Project. This will return the "{"Hello":"World"}" response payload for the service request.

    1. Right-click the ESB Config project in the project explorer, go to New -> Proxy Service and create a custom proxy service named HelloWorld. Create ESB Config Project

    2. You can then use the Source View to copy the following configuration.

      <?xml version="1.0" encoding="UTF-8"?>
      <proxy name="HelloWorld" startOnLoad="true" transports="http https" xmlns="http://ws.apache.org/ns/synapse">
          <target>
              <inSequence>
                  <payloadFactory media-type="json">
                      <format>{"Hello":"World"}</format>
                      <args/>
                  </payloadFactory>
                  <respond/>
              </inSequence>
              <outSequence/>
              <faultSequence/>
          </target>
      </proxy>

  4. Create a Composite Application Project with the above proxy service inside the Maven Multi Module project.

    1. Right-click the maven multi modiule project, go to New → Project, select Composite Application Project, and click Next.
    2. Be sure to select the proxy service under Dependencies as shown below. Create Composite Application Project

    3. Click Finish.

  5. Create a Kubernetes Project inside the Maven Multi Module Project.

    1. Right-click the Maven Multi Module project, go to New → Project, select Kubernetes Exporter Project, and click Next. Create Kubernetes Project
    2. In the Kubernetes Project Information dialog that opens, enter the following details:
      Parameter Description
      Kubernetes Project 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 hello-world as the integration name for this example.
      Number of Replicas Specify the number of pods that should be created in the kubernetes cluster.
      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.

Finally, the created Maven Multi Module project should look as follows:

Hello World Project

Step 2: Package and build the solution

You need to build a Docker image of the integration solution and push it to your Docker registry.

  1. Start the Docker daemon in the host machine.
  2. Open the pom.xml file in the Kubernetes project, ensure that the composite application is selected under Dependencies, and click Build and Push. Select composite projects

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

    docker registry credentials

    Info

    Alternatively, you can build the Docker image and push it to the Docker registry as follows:

    1. Navigate to the Maven Multi Module project and run the following command to build the project. It will create a docker image with the provided target repository and tag once the build is successfull.
      mvn clean install -Dmaven.test.skip=true
    2. Navigate to the Kubernetes project inside the MavenParentProject and run the following command to push the docker image to the remote docker registry.
      mvn dockerfile:push -Ddockerfile.username={username} -Ddockerfile.password={password}
  3. Run the docker image ls command to verify that the Docker image is created.

Step 3: Deploy the solution in K8s

Info

Before you begin, be sure that the system requrements are in place, and that the EI Kubernetes Operator is installed.

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 routing-example solution are updated:

    apiVersion: "integration.wso2.com/v1alpha2"
    kind: "Integration"
    metadata:
      name: "hello-world"
    spec:
      replicas: 1
      image: "<Docker image for the Hello World Scenario>"
  3. Open a terminal, 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 hello-world integration, hello-world-deployment, hello-world-service, and ei-operator-ingress as follows:

Tip

The ei-operator-ingress will not be created if you have disabled the ingress controller.

kubectl get integration

NAME          STATUS    SERVICE-NAME    AGE
hello-world   Running   hello-service   2m

kubectl get deployment

NAME                     READY   UP-TO-DATE   AVAILABLE   AGE
hello-world-deployment   1/1     1            1           2m

kubectl get services
NAME                     TYPE        CLUSTER-IP       EXTERNAL-IP   PORT(S)       AGE
hello-world-service      ClusterIP   10.101.107.154   <none>        8290/TCP      2m
kubernetes               ClusterIP   10.96.0.1        <none>        443/TCP       2d
k8s-ei-operator          ClusterIP   10.98.78.238     <none>        443/TCP       1d

kubectl get ingress
NAME                  HOSTS     ADDRESS     PORTS     AGE
ei-operator-ingress   wso2ei    10.0.2.15   80, 443   2m

Step 4: Test the deployment

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

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

    kubectl port-forward service/hello-world-service 8290:8290

  2. Invoke the service as follows:

    curl http://localhost:8290/services/HelloWorld

You will receive the following response:

{"Hello":"World"}%
Top