passing json string in environment variable in Kubernetes deployment yaml

4/20/2020

I am looking for something equivalent to SPRING_APPLICATION_JSON env variable of Docker Compose in Kubernetes Deployment yaml.

I am aware of that we can pass individual config as name-value pair. But there must be something through which all env variables can be passed in json or yaml format in Kubernetes.

-- Infotechie
kubernetes
spring-boot

2 Answers

4/21/2020

You can use the following command:

kubectl create cm env --from-file=SPRING_APPLICATION_JSON=./<your-json>.json
-- irvifa
Source: StackOverflow

4/20/2020

You can do that using ConfigMap. For example, create a configmap:

kind: ConfigMap
apiVersion: v1
metadata:
  name: appconfig
data:
  ENV_KEY1: val1
  ENV_KEY2: val2

Then in your deployment container, use

spec:
  containers:
  - image: <image>
    name: <name>
    envFrom:
    - configMapRef:
        name: appconfig
-- hoque
Source: StackOverflow