pass boolean variable as env, secret or configmap in k8s yaml file

3/12/2020

We are working on creating a deployment yaml file for our Java spring-boot application to run on AKS.

I need a way to add a boolean variable as env, secret or configmap which I can pass the following application.properties

azure.activedirectory.session-stateless=true

to environment variable inside my pod like that

apiVersion: apps/v1
kind: Deployment
metadata:
  name: service
spec:
  replicas: 1
  selector:
    matchLabels:
      app: svc-deployment
  template:
    spec:
      containers:
      - name: image
        image: acr/image:tag
        env:
        - name: azure.activedirectory.session-stateless
          value: true

I read that yaml seems it can't parse the boolean values either with quote - "ture " - or without. Is there any workaround?

-- Helay
java
kubernetes
spring-boot
yaml

3 Answers

3/12/2020

There is no workaround, nor would any make sense. Env vars themselves are inherently strings so the values must be too or it would just be converting it for you anyway.

-- coderanger
Source: StackOverflow

3/12/2020

To have an environment variable override a value in application.properties you have to declare the environment variable name in upper case using underscores as the separator.

In your case the name of the environment variable should be AZURE_ACTIVEDIRECTORY_SESSIONSTATELESS

See the Relaxed Binding rules in the Spring Boot docs for further details.

-- Mark
Source: StackOverflow

3/12/2020

application.properties can be configured by the SPRING_APPLICATION_JSON env variable

apiVersion: apps/v1
kind: Deployment
metadata:
  name: service
spec:
  replicas: 1
  selector:
    matchLabels:
      app: svc-deployment
  template:
    spec:
      containers:
      - name: image
        image: acr/image:tag
        env:
        - name: SPRING_APPLICATION_JSON
          value: '{"azure": {"activedirectory": {"session-stateless": true}}}'

See: https://docs.spring.io/spring-boot/docs/current/reference/html/spring-boot-features.html#boot-features-external-config

-- whymatter
Source: StackOverflow