Deploying Microgateway as Kubernetes Service
Tags: kubernetes, microservices, docker, guide
Published: 2021-07-06 09:38:29

---
title: Deploying Microgateway as Kubernetes Service
published: true
date: 2021-06-10 11:11:00 UTC
tags: #kubernetes, #microservice, #docker, #guide
canonical_url: https://tech.forums.softwareag.com/t/deploying-microgateway-as-kubernetes-service/242084
---

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

```

![image](https://aws1.discourse-cdn.com/techcommunity/original/3X/2/7/273df245c6f3384b0de487454af8c35fdb485405.png)

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](http://localhost:30163/gateway/PetStore/1.0/pet/findByStatus)

![image](https://aws1.discourse-cdn.com/techcommunity/optimized/3X/0/3/03014bfb476c4dfdb40392052dfba3722406a92e_2_690x177.png)

If the service is exposed as type **LoadBalancer,**

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

![image](https://aws1.discourse-cdn.com/techcommunity/original/3X/3/f/3ff55c9a0a9bedc0abe6302914aba638054da20d.png)

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

For example - [http://localhost:9090/gateway/PetStore/1.0/pet/findByStatus](http://localhost:9090/gateway/PetStore/1.0/pet/findByStatus)

![image](https://aws1.discourse-cdn.com/techcommunity/optimized/3X/c/a/ca70c5cf7d0f50f2f719644d8c816a9c6f7f960d_2_690x188.png)

## 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)](https://documentation.softwareag.com/webmethods/microgateway/yam10-7/10-7_Microgateway_webhelp/index.html#page/microgateway-integrated-webhelp%2Fco-kubernetes_sidecar_deploy.html%23)

[Read full topic](https://tech.forums.softwareag.com/t/deploying-microgateway-as-kubernetes-service/242084)