WSO2 EI Kubernetes Operator
In this brief article, I am going to explain how to create a microservice in WSO2 Micro Integrator and deploy it in the k8s cluster using the EI k8s operator. To know the in-depth details of the WSO2 Micro Integrator please follow this official documentation.
For this demonstration, I am going to use the following software:
- WSO2 Integration Studio 7.2.0
- WSO2 Micro Integrator 1.2.0
- Docker (latest)
- A k8s cluster
I am going to divide the article into the following sections.
- Create a microservice using the WSO2 Integration Studio.
- Export it as a k8s artifact.
- Deploy the EI k8s operator in a local k8s cluster.
- Deploy the microservice in the k8s cluster using the EI k8s operator.
1. Create a microservice using the WSO2 Integration Studio
Let's create an Integration Project as shown in the diagram below.
Look at these new features Create Docker Exporter and Create Kubernetes Exporter. When checked these features, the IDE creates additional modules to generate Docker and Kubernetes artifacts.
On the next screen, you have to specify the docker repository.
Note that when the docker image for our microservice will be created it will be based on the wso2mi-1.2.0 image. Click next and finish.
Now let's check the project structure.
Note that a k8s module is also added to the project structure. Cool !!!
You can open each individual file in the module and they are self-explanatory. The integration-cr.yaml is a custom resource. Let's check this out.
The kind (or resource) Integration is the custom resource. To be able to deploy this resource, first, we will need to deploy the custom operator itself who can interpret this kind of resource. It will be done in the next sections of the article.
For this demonstration, we are implementing a very simple Hello World REST API. After all the emphasis of the article is not on microservice.
2. Export it as a k8s artifact
Once implemented add the DemoAPI.xml to the composite exporter project.
After that add the artifact to the Kubernetes exporter project.
Now click Build & Push in the Kubernetes exporter project. It will ask for the credentials for the docker repository and once provided it will build the whole project, generate the .car, build the docker imager and push the docker image to your repository.
Also, you can check the docker image in your local system.
docker images | grep demo-ms
Or even better, let's run the image.
docker run — name demo -d -p 8290:8290 anupamgogoi/demo-ms
You should be able to see the below output.
Note that on port 8290 our microservice will listen to on HTTP protocol.
Let's test if the microservice is working.
Great!!!. We have a fully functional microservice. Now, let's install the EI k8s operator in our cluster in the next steps.
3. Deploy the EI k8s operator in a local k8s cluster
We will use a very simple 3 nodes k8s cluster. Please check this article to set up a k8s cluster rapidly. To deploy the EI k8s operator you can follow the WSO2 official documentation. However, I will summarise the steps.
Let's deploy the operator in a specific namespace. Let's say ei-operator.
- So, first, let's create the k8s namespace
kubectl create ns ei-operator
2. Clone the latest k8s-ei-operator GitHub repository.
3. Set up the service account
kubectl create -f deploy/service_account.yaml -n ei-operator
4. Set up RBAC
kubectl create -f deploy/role.yaml -n ei-operator
kubectl create -f deploy/role_binding.yaml -n ei-operator
5. Deploy the CRD
kubectl create -f deploy/crds/integration_v1alpha1_integration_crd.yaml
6. Finally deploy the operator
kubectl create -f deploy/operator.yaml -n ei-operator
Now let's check the resources deployed in the ei-operator namespace.
kubectl get all -n ei-operator
Great. The related resources of the operator are deployed. Now we can proceed to the next and final step to deploy the microservice.
4. Deploy the microservice in the k8s cluster using the EI k8s operator
In the first part when the project was generated, the IDE also created a deployment file for us named integration-cr.yaml. Now simply copy this YAML to our k8s master node and apply this file in the same namespace as the EI k8s operator i.e ei-operator.
kubectl apply -f integration_cr.yaml -n ei-operator
Let's check if the microservice is deployed.
kubectl get all -n ei-operator
Note that there is a deployment, pod, and service for our demo-ms microservice deployed in the ei-operator namespace.
The demo-ms-service is exposed as CluserIP. So, it is accessible inside the cluster. Let's try.
You should get a response for it.
For the time being the service is accessible only inside the Cluster. However, feel free to expose it to the outside world using an Ingress Controller.
In this article, I have shown how to create a microservice using WSO2 Micro Integrator and deploy it in a k8s cluster with the EI k8s operator. Note that the Micro Integrator is very small in size and so it can be directly embedded to the microservice as its runtime. That's the beauty of the MI. Give it a try and do let me know how do you feel about it.
Thanks for reading.