First Steps to deploy WSO2 API Manager in Kubernetes.

Hi Mates,

In this article I am going to explain how we can deploy WSO2 API Manager in Kubernetes with the basic configurations.

Kubernetes (K8s) is an open-source system for automating deployment, scaling, and management of containerized applications.

Note: It is not necessary to have any prior knowledge in Kubernetes in order to create this deployment if you can follow the below steps.

Let’s begin.

First we need an Kubernetes cluster in order to create the deployment. So I am going to use the Google Cloud Kubernetes engine with a free trial account.

Open a web browser and navigate to the following link create a free trial Google cloud account with your gmail.

https://console.cloud.google.com

Lets create our first Kubernetes cluster with the necessary resources.

Click on the Navigation Menu in the top left side of the console and then navigate to the Kubernetes Engine.

Then You will be able to find an UI as below

Click on CREATE CLUSTER and follow the steps as shown in the screenshots and create the cluster.

Set the basic configurations of the cluster

Set the configurations of the node pool

Set the configurations of the node

Enable basic authentication for the cluster.

And then click on create button which you can find in the left lower corner to create the cluster.

Then you can see the cluster is created in the UI console. Then click on connect button and copy the command line access command. This will be needed when we are accessing the cluster using the Kubernetes client.

We also need the Cluster credentials when we are accessing the cluster, So click on the cluster we created and click on show credentials.

Then copy and save the password of the cluster.

Then we need to setup the Google cloud SDK and Kubernetes client in our local machine.

Navigate to the following link and install the Google cloud SDK in your machine.

https://cloud.google.com/sdk/install

For the mac users, you can use the brew to install this.

brew install google-cloud-sdk

Navigate to the following link and install the kubectl in your machine.

https://kubernetes.io/docs/tasks/tools/install-kubectl/

For the mac users, you can use the brew to install this.

brew install kubectl

Test kubectl client

kubectl version --client

Lets install the Helm which will be use for the future.

For the mac users, you can use the brew to install this.

brew install helm

Congratulations you have successfully created the environment.

Lets start the deployment.

Clone the following git repo which contain all the kubernetes artifacts for this deployment.

https://github.com/shiransilva/my-kubernetes-apim

First we have to log in to the gloud cluster using the kubectl client.

Open a terminal and execute the command line access command which we copied previously.

gcloud container clusters get-credentials cluster-2 --zone us-cantral1-c --project mapping-174505

Then navigate to the kubernetes-apim/scripts directory which is inside the cloned repo.

Then execute the following command to create our WSO2 API Manager deployment.

Here we need an WSO2 subsription to pull the docker images from the docker hub.

sh deploy.sh — wu=test@wso2.com — wp=testPassword — cap=clusterPassword

test@wso2.com> username/email of the WSO2 subscription

testPassword> password of the WSO2 subscription

clusterPssword> Cluster password which we copied previously.

By this command it will create WSO2 API Manager container with the relevant config maps and secrets along with the Kubernetes service and the ingresses.

Then Let’s create the nginx load balancer to expose this service to the outside of the cluster by using the created ingresses.

Execute the following command.

sh nginx-deploy.sh --cap=clusterPassword

Congratulations You have finished deploying WSO2 API manager in Kubernetes.

If you wanna un deploy this, please execute the following two commands.

sh undeploy.sh --h
sh nginx-undeploy.sh

Please execute the below two commands to get details of the running pods and tail the logs of the containers.

Get pods:

kubectl get pods

Results:

NAME                       READY   STATUS    RESTARTS   AGEwso2apim-9c7747685-86h2z   1/1     Running   0          2m28s

Tail logs:

kubectl logs -f wso2apim-9c7747685-86h2z

Let’s access the API manager consoles.

First we need to get the IP address of the nginx load balancer. Execute the below command to retrieve these details. It is possible to find these details in the gloud console as well.

kubectl get ing

Results:

NAME                       HOSTS              ADDRESS        PORTS     AGEwso2apim-gateway-ingress   wso2apim-gateway   34.72.192.31   80, 443   15hwso2apim-ingress           wso2apim           34.72.192.31   80, 443   15h

We need to add this IP address with these host names to the hosts(/etc/hosts) file in our local machine as below.

34.72.192.31 wso2apim wso2apim-gateway

Open a browser and hit the following URLs to access the consoles.

https://wso2apim/publisher
https://wso2apim/devportal
https://wso2apim/carbon
https://wso2apim/admin

You may be wondering about the Kubernetes artifacts, If you wanna have a better understanding, you can go through the repository artifacts, change it and test it out. I will be writing another story explaining these artifacts for better understanding.

Untill then See Ya.

“The Deeper You Dig, The Deeper You get”.“The Tired You Feel, The Success You Achieve”- Shiran

Senior Software Engineer @WSO2 | MIT @ UOK 🇱🇰 | Athlete 🎖️🤾🏋️🕴️| Stylish Marketer 2016 1st Runners Up 🏆 | Mister International Srilanka Finalist 🏆 |