DEV Community

Mariela Dimitrova for Software AG Tech Community

Posted on • Originally published at tech.forums.softwareag.com on

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

Enter fullscreen mode Exit fullscreen mode

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

Enter fullscreen mode Exit fullscreen mode

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>>

Enter fullscreen mode Exit fullscreen mode

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 .

Enter fullscreen mode Exit fullscreen mode

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

Enter fullscreen mode Exit fullscreen mode

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

Enter fullscreen mode Exit fullscreen mode

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

Enter fullscreen mode Exit fullscreen mode

ii. NodePort Type

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

Enter fullscreen mode Exit fullscreen mode

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

Run the below command

kubectl get services

Enter fullscreen mode Exit fullscreen mode

image

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”.

For example, http://localhost:30163/gateway/PetStore/1.0/pet/findByStatus

image

If the service is exposed as type LoadBalancer,

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

image

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

For example - http://localhost:9090/gateway/PetStore/1.0/pet/findByStatus

image

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)

Read full topic

Top comments (0)