Environment variables
Overview
IBM Financial Services Workbench provides the possibility to define any custom environment variables (like DB connection, URLs,...) for
your service projects. If a new service project is created you will find an extension-values.yaml
file in your Git
repository. It's possible to add this file by yourself if it is missing. But you need to use the file
name extension-values.yaml
and the described file structure.
Add new environment variables
By default, the extension-values.yaml
file contains only comments that should explain how the file can be used. To use
this feature you need to remove the comments and place your needed environment variables in the file as described later.
The service project pipeline will add this additional variables to the Helm chart that gets created via the pipeline.
The built Helm chart of the service project will react on these values and add the additional environment variables to the deployment of your service project:
Supported types of environment variables:
secretKeyRef
configMapKeyRef
keyValue
fieldRef
Structure of extension-values.yaml
env:
variables:
secretKeyRef:
- variableName: VARIABLE1
secretName: k5-service1-variable1-secret
secretKey: key1
optional: false
configMapKeyRef:
- variableName: VARIABLE2
configMapName: k5-service1-variable2-cm
configMapKey: key2
optional: false
keyValue:
- variableName: VARIABLE3
value: myString
fieldRef:
- variableName: VARIABLE4
apiVersion: v1
fieldPath: metadata.namespace
Supported type secretKeyRef
Key | Description | Example |
---|---|---|
variableName | Name of the environment variable | VARIABLE1 |
secretName | Name of the Kubernetes secret | k5-service1-variable1-secret |
secretKey | Name of the Key used in the Kubernetes secret | key1 |
optional | Defines if the Pod will start if the secret is missing | false |
Supported type configMapKeyRef
Key | Description | Example |
---|---|---|
variableName | Name of the environment variable | VARIABLE2 |
configMapName | Name of the Kubernetes configmap | k5-service1-variable2-cm |
configMapKey | Name of the Key used in the Kubernetes configmap | key2 |
optional | Defines if the Pod will start if the configmap is missing | false |
Supported type keyValue
Key | Description | Example |
---|---|---|
variableName | Name of the environment variable | VARIABLE3 |
value | Value of the environment variable | myString |
Supported type fieldRef
Key | Description | Example |
---|---|---|
variableName | Name of the environment variable | VARIABLE4 |
apiVersion | API Version of the Kubernetes resource | v1 |
fieldPath | Path to the value | metadata.namespace |
Deployment of new environment variables
In your deployed service the environment variables will be added to the deployment of the service project so that they can be used in the implementation, e.g.:
kind: Deployment
apiVersion: apps/v1
metadata:
name: k5-service1
...
spec:
containers:
- env:
- name: VARIABLE1
valueFrom:
secretKeyRef:
name: k5-service1-variable1-secret
key: key1
optional: false
- name: VARIABLE2
valueFrom:
configMapKeyRef:
name: k5-service1-variable2-cm
key: key2
optional: false
- name: VARIABLE3
value: myString
- name: VARIABLE4
valueFrom:
fieldRef:
apiVersion: v1
fieldPath: metadata.namespace
Using secrets or ConfigMaps
Example to create a required secret:
cat <<EOF | oc apply -f -
kind: Secret
apiVersion: v1
metadata:
name: k5-service1-variable1-secret
spec:
data:
key1: bXlWYWx1ZTE=
type: Opaque
EOF
Example to create a required ConfigMap:
cat <<EOF | oc apply -f -
kind: ConfigMap
apiVersion: v1
metadata:
name: k5-service1-variable2-cm
spec:
data:
key2: myValue2
type: Opaque
EOF