Deploying a Kubernetes Sidecar Connected to API Gateway
This section describes a Microgateway Kubernetes sidecar deployment where the 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.
Before you start with the deployment ensure you have done the following:
Ensure you have a running Kubernetes environment.
For details on setting up of a Kubernetes environment, see Kubernetes documentation.
There is an
API Gateway instance running in a dedicated Kubernetes service.
There is a native service Docker image in the Docker registry (employees-service).
Follow these steps to set up a Kubernetes sidecar deployment connected to API Gateway:
1. Create a Microgateway Docker image that can be pushed to the registry the Kubernetes cluster is connected to.
./microgateway.sh createDockerFile -c ../pull-employee-service.yml
--docker_file DockerFileEmployees -dod .
The command creates the Docker file DockerFileEmployees based on the custom settings file pull-employee-service.yml that holds the configuration for pulling the definition of the EmployeeService API.
api_gateway:
url: 'http://localhost:5555/rest/apigateway'
user: 'Administrator'
password: 'manage'
ports:
http: '9090'
downloads:
apis: "EmployeeService"
microgatewayPool:
microgatewayPoolName: employee-service-mcgw
microgatewayPoolDescription: Microgateways of EmployeeServices.
The configuration also holds entries to register the Microgateway to the Microgateway pool employee-service-mcgw in the referenced API Gateway.
2. Create the image mg-employees-registered, from the resulting Docker file DockerFileEmployees, using docker build.
docker build -t mg-employees-registered -f DockerFileEmployees .
3. Tag the resulting image and push it to the registry.
docker tag mg-employees-sidecar reghost :regport /mg-employees-registered
docker push reghost :regport /mg-employees-registered
4. Create the Kubernetes YAML file using the createKubernetesFile command.
./microgateway.sh createKubernetesFile
--docker_image reghost:regport/mg-employees-registered
--pod_name mg-employees-registered
--sidecar_docker_image reghost:regport/employees-sservice
--sidecar_pod_name employees-sservice
--output mg-employees-registered-deployment.yml
5. Change the Microgateway configuration, in the resulting Kubernetes file, 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:
containers:
name: mg-employees-registered
image: reghost:regport/mg-employees-registered
imagePullPolicy: IfNotPresent
- env:
- name: mcgw_api_gateway_url
value: http://10.20.198.90:31929/rest/apigateway
- name: mcgw_api_gateway_user
value: Administrator
- name: mcgw_api_gateway_password
value: manage
livenessProbe:
exec:
command:
- /bin/sh
- -c
- /opt/softwareag/Microgateway/files/k8s-lifenesscheck.sh
failureThreshold: 3
initialDelaySeconds: 10
periodSeconds: 10
successThreshold: 1
timeoutSeconds: 5
readinessProbe:
exec:
command:
- /bin/sh
- -c
- /opt/softwareag/Microgateway/files/k8s-readinesscheck.sh
failureThreshold: 3
initialDelaySeconds: 10
periodSeconds: 10
successThreshold: 1
timeoutSeconds: 5