Let's get started with WSO2 Micro Integrator by running a simple use case on your local environment. In this example, we use a REST API to simulate a simple HTTP service (HelloWorld service) deployed in an instance of WSO2 Micro Integrator. You can deploy this HelloWorld service on a Docker container or on Kubernetes. When invoked, the HelloWorld service will return the following response: {"Hello":"World"}
...
- Install Docker (version 17.09.0-ce or higher).
- Install Curl.
- To set up the integration workspace for this quick guide, we will use an integration project that was built using WSO2 Integration Studio:
- Download the project file for this guide, and extract it to a know known location. Let's call this
<MI_QSG_HOME>
. Go to the
<MI_GS_HOME>
directory. The following project files, and Docker/Kubernetes configuration files are available.hello-world-config-project This is the ESB Config Project folder with the integration artifacts (synapse artifacts) for the HelloWorld service. This service consists of the following REST API:
Code Block title HelloWorld.xml <api context="/hello-world" name="HelloWorld" xmlns="http://ws.apache.org/ns/synapse"> <resource methods="GET"> <inSequence> <payloadFactory media-type="json"> <format>{"Hello":"World"}</format> <args/> </payloadFactory> <respond/> </inSequence> <outSequence/> <faultSequence/> </resource> </api>
hello-world-config-projectCompositeApplication This is the Composite Application Project folder, which contains the packaged CAR file of the HelloWorld service.
Dockerfile This Docker configuration file is configured to build a Docker image for WSO2 Micro Integrator with the HelloWorld service.Expand title Dockerfile Code Block FROM wso2/micro-integrator:1.0.0 COPY hello-world-config-projectCompositeApplication/target/hello-world-config-projectCompositeApplication_1.0.0.car /home/wso2carbon/wso2mi/repository/deployment/server/carbonapps
Note that this file is configured to use the community version of the WSO2 Micro Integrator base Docker image (from Docker DockerHub). If you want to use the Micro Integrator that includes the latest product updates, you can update the image name in this Docker file as explained here.
k8s-deployment.yaml This is sample Kubernetes configuration file that is configured to deploy WSO2 Micro Integrator in a Kubernetes cluster.
Expand title k8s-deployment.yaml Code Block apiVersion: apps/v1 kind: Deployment metadata: name: mi-helloworld-deployment labels: event: mi-helloworld spec: strategy: type: Recreate replicas: 2 selector: matchLabels: event: mi-helloworld template: metadata: labels: event: mi-helloworld spec: containers: - image: wso2-mi-hello-world name: helloworld imagePullPolicy: IfNotPresent ports: - name: web containerPort: 8290 --- apiVersion: v1 kind: Service metadata: name: mi-helloworld-service labels: event: mi-helloworld spec: type: NodePort ports: - name: web port: 8290 targetPort: 8290 nodePort: 32100 selector: event: mi-helloworld
- Download the project file for this guide, and extract it to a know known location. Let's call this
...
Open a terminal, navigate to the <MI_QSG_HOME>
directory (which stores the Dockerfile), and execute the following command to build a Docker image with WSO2 Micro Integrator and the integration artifacts.
...
- The base Docker image of WSO2 Micro Integrator is downloaded from DockerHub and a custom, deployable Docker image of the Micro Integrator is created in a Docker container.
- The CAR file with the integration artifacts that define the HelloWorld service is deployed.
Run Docker container
From the <MI_QSG_HOME>
directory, execute the following command to start a Docker container for the Micro Integrator.
Code Block |
---|
docker run -d -p 8290:8290 hello_world_docker_image |
...
Once you have set up your workspace, you can run the HelloWorld service on Kubernetes:
Install Minikube
Let's use Minikube to run a Kubernetes cluster for this example.
- Install Minikube. Once you have completed this step, you should have kubectl configured to use Minikube from your terminal.
Start Minikube from your terminal:
Code Block minikube start
Execute the command given below to start using Minikube's built-in Docker daemon. You need this Docker daemon to be able to create Docker images for the Minikube environment.
Code Block eval $(minikube docker-env)
Now you can build a Docker image for your HelloWorld service in Minikube as explained below.
Build a Docker image
Open a terminal, navigate to the <MI_QSG_HOME>
directory (which stores the Dockerfile), and execute the following command to build a Docker image (with WSO2 Micro Integrator and the integration artifacts) in the Minikube environment.
Code Block |
---|
docker build -t wso2-mi-hello-world . |
Run container (on Minikube)
Follow the steps given below to start a Docker container for Docker image on Minikube.
Navigate to the
<MI_QSG_HOME>
directory (which stores thek8s-deployment.yaml
file), and execute the following command:Code Block kubectl create -f k8s-deployment.yaml
Check whether all the Kubernetes artifacts are deployed successfully by executing the following command:
Code Block kubectl get all
You will get a result similar to the following. Be sure that the deployment is in 'Running' state.
Code Block NAME READY STATUS RESTARTS AGE pod/mi-helloworld-deployment-56f58c9676-djbwh 1/1 Running 0 14m pod/mi-helloworld-deployment-56f58c9676-xj4fq 1/1 Running 0 14m NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE service/kubernetes ClusterIP 10.96.0.1 <none> 443/TCP 25m service/mi-helloworld-service NodePort 10.110.50.146 <none> 8290:32100/TCP 14m NAME READY UP-TO-DATE AVAILABLE AGE deployment.apps/mi-helloworld-deployment 2/2 2 2 14m NAME DESIRED CURRENT READY AGE replicaset.apps/mi-helloworld-deployment-56f58c9676 2 2 2 14m
...