Configure secret references for the configurations defined in micro-gw.conf file in Kubernetes— WSO2 Micro Gateway

micro-gw.conf is the runtime configuration file located in <MGW-RUNTIME-HOME>/conf/ directory[1].

Today, we are going to discuss on how to configure secret references for the configurations defined in micro-gw.conf file.

Implementation

Let’s assume we want to fetch the configuration of “httpPort” under the “[listenerConfig]”.

[listenerConfig]
...
httpPort = 9090
...

Initially, we need to create a Kubernetes secret for this…

i. Create a file(secret.yaml) with the below content(data attributes needs to be base64 encoded, here we have encoded 8000).

apiVersion: v1
kind: Secret
metadata:
name: test-secret
data:
port: ODAwMA==

ii. Create the secret.

kubectl apply -f file-path/secret.yaml

Secondly, we need to declare this as an environment variable in deployment-config.toml file as below.

[kubernetes]
[kubernetes.kubernetesDeployment]
enable = true
...
env = '{ "listenerConfig_httpPort": {secretKeyRef: {key: "port",name: "test-secret"}} }'

Here, we need to create the variable name by appending the micro-gw.conf configuration hierarchy(Since the “httpPort” config is under the “listenerConfig”, the variable name can be obtained by appending both with “_”). Other than that, we need to use the same key(port) and the name(test-secret) of the secret we created.

Then we need to generate the Kubernetes artifacts by building the project.

micro-gw build k8s_project --deployment-config deployment.toml

Below is the generated k8 artifact (k8s_project.yaml) content with the environment variable,

...
spec:
containers:
- env:
- name: "listenerConfig_httpPort"
valueFrom:
secretKeyRef:
key: "port"
name: "test-secret"
- name: "CONFIG_FILE"
value: "/home/ballerina/conf/ballerina.conf"
...

👏 It’s almost done ✅.

We can start the Kubernetes cluster now.

CHEERS!
Happy Integration!

--

--

--

Live to code | Senior Software Engineer @ WSO2

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

Building a data lake: from batch to real-time using Kafka

Clearing the Dead Letter Queue on an Azure Service Bus Queue

ClickHouse Materialized Views Illuminated, Part 1 — Altinity

BATC Meetup — Modern Architecture

An Introduction to Flutter: Basic Flutter Layout Concepts

An Introduction to Flutter: Basic Flutter Layout Concepts

Your Summer Internship at Forsk

Define and contrast Information Management vs Data Management.

FLASK

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Lakshan Thilakarathne

Lakshan Thilakarathne

Live to code | Senior Software Engineer @ WSO2

More from Medium

The Vegetarian 5-Ingredient Gourmet: 250 Simple Recipes And Dozens Of Healthy Menus For Eating Well…

New Year, New Way: Striking Balance Between Creating and Allowing — Time + Space Solutions

3 Reasons Why.

Which Camera Drone To Buy? | A Guide