Deploying Microgateway as Kubernetes Service

Introduction

Microgateway is a proxy that sits close to the microservice. Microgateways give control over a microservice landscape by enforcing policies which perform authentication, traffic monitoring and traffic management.

Microgateway contains a service for enforcing policy on REST API. Microgateway exposes REST APIs for querying status, system settings, and provisioned assets.

In this article we will see how we can create microgateway as Kubernetes service.

Audience

This document is intended for users who wants to deploy microgateway hosting few APIs as Kubernetes service.

Pre-Requisites

  • Basic Knowledge on Docker, Kubernetes
  • Create API in API Gateway
  • Export of APIs and related assets from the API Gateway
  • Understanding on Microgateway
  • Docker and Kubernetes environment setup

Deploying Microgateway as a Kubernetes Service

Microgateway can be run within a Kubernetes (k8s) environment. Kubernetes provides a platform for automating deployment, scaling, and operations of services. The basic scheduling unit in Kubernetes is a pod . It adds a higher level of abstraction by grouping containerized components. A pod consists of one or more containers that are co-located on the host machine and can share resources. A Kubernetes service is a set of pods that work together, such as one tier of a multi-tier application.

Below are the steps for deploying microgateway as k8s service.

1. Create a Microgateway Docker image

Navigate to the Microgateway installation directory

<InstallationDir>\Microgateway

Create an export of API from API Gateway and name the file apigw-archive.zip

Run the below docker command to create docker file

.\microgateway.bat createDockerFile --docker_dir . -p 9090 -a apigw-archive.zip

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.

Note : You can also move these variables into a separate environment config file, and read it from there instead of hardcoding inside the docker file.

Run the below command to create a docker image

docker build -f Microgateway_DockerFile -t sag:mcgwimg .

2. Push the image to the docker repository

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

docker tag sag:mcgwimg <<dockerRepo>>: mcgwimg


docker push <<dockerRepo>>: mcgwimg

where << dockerRepo> is the name of the repository created in the docker hub.

3. Create Microgateway as Kubernetes deployment

kubectl create deployment mcgwimg --image=<<dockerRepo>>: mcgwimg

4. Expose microgateway deployment in Kubernetes

A Kubernetes pod is created and started, after which a Kubernetes service is exposed through a port that can be accessed from outside the cluster. Expose the deployment created in the previous step.

Here in this sample, we are showing two ways of exposing the deployment.

i. LoadBalancer Type

kubectl expose deployment mcgwimg --name= mcgwimgk8s --type=LoadBalancer --port=9090

ii. NodePort Type

kubectl expose deployment mcgwimg --name= mcgwimgk8s --type=NodePort --port=9090

5. Verify the Microgateway Kubernetes service definition and the exposed IP and port.

Run the below command

kubectl get services

If the service is exposed as type NodePort ,

We can invoke API present inside microgateway server, using the port “30163” (present in the screenshot above) and “host name”.

If the service is exposed as type LoadBalancer,

Then microgateway server status can be checked by invoking URL http://localhost:9090/rest/microgateway/status

And can invoke API deployed in the microgateway with port “9090”

Kubernetes Sidecar Deployment

We have different ways of deploying kubernetes sidecar.

1. Deploying a Stand-alone Kubernetes Sidecar

In this deployment model, the Microgateways are not connected to an API Gateway. The API definitions are provided through API Gateway export archives.

2. Deploying a Kubernetes Sidecar Connected to API Gateway

Here Microgateways are connected to an API Gateway for pulling API definitions and runtime metrics data aggregation. The API Gateway instance may run as Kubernetes service.

3. Deploying a Kubernetes Sidecar using Helm Charts

For more details on the sidecar deployment, please refer documentation Kubernetes Sidecar Deployment (softwareag.com)

20