Deploying Microgateway as Kubernetes Sidecar Connected to API Gateway

Introduction

A Microgateway Kubernetes sidecar deployment can be established by creating a pod containing two containers; one container runs the native service, and the other container runs the Microgateway protecting the native service.

The native services are accessed by consumers through the Microgateway endpoint.

To access the native service from the Microgateway container, Microgateway has to use localhost as URL together with the port exposed by the native service as both the containers are treated as being within the same host.

There are two types of sidecar deployment models:

  1. A stand-alone Kubernetes sidecar deployment ( For more details please refer the article Microgateway Stand-alone Kubernetes Sidecar Deployment - Knowledge base - webMethods - Software AG Tech Community & Forums )

  2. A Kubernetes sidecar connected to API Gateway

In this article we will see how we can deploy Microgateway as Kubernetes sidecar connected to API Gateway

The diagram depicts Microgateway Kubernetes sidecar deployment connected to API Gateway. Each pod consists of a Microgateway container and the native service container. The Microgateway can be connected to an API Gateway to pull API definitions and to push runtime metrics.

Audience

This document is intended for users who wants to deploy microgateway as a Kubernetes sidecar connected to API Gateway.

Pre-Requisites

  • Basic Knowledge on Docker, Kubernetes
  • The native service Docker images are pushed to a Docker registry to make them available for the Kubernetes environment
  • Create API in API Gateway
  • Understanding on Microgateway
  • Docker and Kubernetes environment setup

Use Case

In this article we will be using PostalCode native Service docker image which is a simple Java based application which will return the postalCode when queried with the specific latitude and longitude.

Deploying Microgateway as Kubernetes Sidecar connected to API Gateway

Before you start with the deployment ensure you have done the following:

  • Ensure you have a running Kubernetes environment.
  • There is an API Gateway instance running in a dedicated Kubernetes service.
  • There is a native service Docker image in the Docker registry

Below are the steps about how we can achieve microgateway Kubernetes sidecar deployment, where the Microgateway are connected to an API Gateway for pulling API definitions and runtime metrics data aggregation.

1. Create a Microgateway Docker image

Navigate to the Microgateway installation directory <InstallationDir>\Microgateway

Create the configuration file pull-postalcode-service.yml that holds the configuration for pulling the definition of the PostalCode API from API Gateway.

Run the below docker command to create docker file

./microgateway.bat createDockerFile -c pull-postalcode-service.yml --docker_file DockerFilePostalCode -dod

Add the below environment variables to your docker file

ENV mcgw_api_gateway_url http://<<host>>:<<port>/rest/apigateway

ENV mcgw_api_gateway_user <<API Gateway Username>>

ENV mcgw_api_gateway_password <<API Gateway Password>>

Where,
<< host>> is the IP of the system where the API gateway server is hosted.
<< port>> is the Integration server port where the API gateway is installed.

Run the below command to create a docker image

docker build -t mg-postalcodeimg -f DockerFilePostalCode .

2. Push the image to the docker repository

Tag the image created in the Step 1 and push it to docker registry.

docker tag mg-postalcodeimg <<dockerRepo>>/mg-postalcodeimg

docker push <<dockerRepo>>/mg-postalcodeimg

3. Create new namespace in Kubernetes

Below command creates new namespace in Kubernetes.

kubectl create namespace postalcode

4. Set Kubernetes context

Below command sets the Kubernetes context to the namespace created in step 3.

kubectl config set-context --current --namespace= postalcode

5. Create a template for Kubernetes sidecar deployment

Microgateway offers a function to generate a Kubernetes YAML file, which can be used for a convenient deployment.

We can specify the sidecar parameters together with the Microgateway image parameters to have the two containers created within one pod.

The below command creates the Kubernetes YAML file.

./microgateway.bat createKubernetesFile --docker_image <<dockerRepo>>/mg-postalcodeimg --pod_name postalcode-sidecar --sidecar_docker_image <<dockerRepo>>/apiserver:latest --sidecar_pod_name postalcode-service --output postalcode-sidecar-deployment.yml

Here,

<<dockerRepo>>/mg-postalcodeimg is the microgateway image created in Step 1

<<dockerRepo>>/apiserver:latest is the native service image

6. Change the Microgateway configuration

In the resulting Kubernetes file change the microgateway configurations by modifying the Microgateway environment variables.

For example, the API Gateway URL can be reconfigured through the environment variable mcgw_api_gateway_url as shown by the following YAML fragment:

7. Create and check the Kubernetes deployment.

Create the Kubernetes deployment with the below command

kubectl create –f postalcode-sidecar-deployment.yml

If the deployment is successful you should see 2 out of 2 containers running

8. Expose Microgateway sidecar deployment as a Kubernetes service.

Run the below command to expose the deployment created in Step 7

kubectl expose deployment postalcode-sidecar --type=LoadBalancer --port=9090

9. Verify the Microgateway Kubernetes service definition including the exposed IP and port

Run the below command to see if the Kubernetes service as created along with the port details.

kubectl get svc

10. Check Microgateway service and Invoke the API

Once the deployment is exposed as service, we can check the Microgateway server status with the below

GET http://localhost:9090/rest/microgateway/status

We can also invoke the native API with the below endpoint.

GET http://localhost:9090/gateway/PostalCode/1.0/postalCodes?latitude=333&longitude=444444

Note here since the native services are not exposed by the Kubernetes configuration the Microgateway can’t be by-passed. Consumer requests are routed by the Microgateway to the native services.

From API Gateway, we can check the details of postalcode microgateway under Microgateways tab.