Deploying WSO2 Micro Integrator 4.0.0 Project along with a connector through Jenkins pipeline to Kubernetes
This article is to explain how we can develop and deploy micro integrator project into kubernetes through Jenkins pipeline.
Prerequisite
- Setup a Kubernetes cluster it can be a production grade cluster or a minikube cluster, here in this article I’m using the minikube cluster deployed in the DigitalOcean.
- Setup NFS server to use as the persistence volume
- Setup MySQL database
- Setup Nexus Server
- Setup Jenkins Server
What we are going to setup
Once the pre-requisites are fine then we can start the development. First we will create a connector to start with that follow the below steps.
1. Connector Implementation
Execute the below command to generate the connector project structure.
After a successful execution we can see a result like below:
Then load the project into one of your favourite IDE, here I’m using the Visual Studio code.
Under src/main/resources create a folder called fetchip_volume. Then create a file called fetchip.xml and add the below content
Then create a component.xml and add the below content in the same folder.
Then go to connector.xml and replace the below content.
Then make sure you are creating a folder called icon and adding both icon-small.gif and icon-large.gif otherwise there will be issue in importing the connector to the Integration Studio when attaching the connector to a project.
now our structure will be like below:
Also to add some logic to the Java code add the below.
Then execute the mvn clean install
When you build the connector sometimes can experience an error like the default mirror is blocked to overcome this go to the .m2 folder and create a file called settings.xml. and add the content as below.
If everything will be fine then you will see a log like below:
2. Adding the connector to a Project
Now we need to add the connector to the project to make it use through Micro Integrator.
Go to Integration Studio and create a project and add the connector or else if project creation also needs to be automated in future can use the below script to generate it. This was developed by Lakshani Gamage and I’m re-using that script here.
mkdir FetchIP and then get the location of the project then execute the project generator script.
Once this is executed properly the below structure will be created.
Now to start our implementation we can load the project to integration studio and then start to implement the logics.
Now we need to add our connector to the Integration studio to get it integrated.
Note: Specifically in MAC if you try to go to Add/Remove Connector functionality in the Integration studio you will get an error like below:
To fix this you need to add the below configuration to the file /Applications/IntegrationStudio.app/Contents/Info.plist
After adding restart the Integration Studio IDE. Then you will be able to continue without any issue.
Now Create a Sequence to use the Connector we have created into a project.
Then to invoke and test we need to create an API. Use the below synapse configuration to create the API.
Now we have successfully added the connector to the project.
3. Testing the API in the standalone Micro Integrator
Download a Micro Integrator 4.0.0 distribution from the WSO2 and Export a CAR file and test whether the flow is working.
and once all completed check the API using Postman client.
4. Preparation for kubernetes deployment
As an initial step to configure the log4j.properties based on our need Go to the FetchIPDockerExporter folder and copy the base log4j.properties and update the needed info.
Then we need to update the wso2carbon.jks and the client-truststore.jks files , so for that under the Resources folder in the FetchIPDockerExporter, for now copy the files from a MI distribution and place it there.
Then go to Dockerfile and update with the below content.
Regarding the deployment.toml, based on our need we can add the database interactions and for this I’m using the default configuration and only want to parameterize the hostname and offset for testing purpose of the configuration.
This sample will be looks like below:
Then to do the deployments to kubernetes we need to prepare the deployment yaml file for the kubernetes.
To do that first create a folder inside the FetchIPDockerExporter as “kubernetesDeployment” and add the below content.
5. Preparing the Environment Variable Config Project
Create a folder called mi-projects and create a similar project structure like this to keep the environment wise config maps and do the deployment through pipeline.
sample file contents:
dashboard-configmap.yaml
fetchip-configmap.yaml
mi-common-configmap.yaml
mi-common-secret.yaml
create the above secrets in the Jenkins as secret text.
Then do the deployment through pipeline. A sample pipeline script will be as below.
Sample Groovy file for deployment
K8sDeployerProd.groovy
6. Deploying the Dashboard
Build the custom image by overriding the deployment.toml through Dockerfile by adding the base image of wso2 micro integrator dashboard.
Then deploy the micro integrator dashboard to the kubernetes cluster.
sample deployment.yaml file
sample pipeline scripts
To release a build and push the image to nexus repository
to deploy the dashboard
sample K8sDeployer.groovy
7. Deploying the Micro Integrator Project
Create a pipeline and deploy the project
sample pipeline for build
sample pipeline for deploy
sample K8sDeployer.groovy
8. Deployment Order
- Initially deploy the configs project
- then micro integrator dashboard
- finally the micro integrator projects