简体   繁体   English

在 k8s yaml 文件中将布尔变量作为 env、secret 或 configmap 传递

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

We are working on creating a deployment yaml file for our Java spring-boot application to run on AKS.我们正在为我们的 Java spring-boot 应用程序创建一个部署 yaml 文件,以便在 AKS 上运行。

I need a way to add a boolean variable as env, secret or configmap which I can pass the following application.properties我需要一种方法来添加一个布尔变量作为 env、secret 或 configmap,我可以通过以下 application.properties

azure.activedirectory.session-stateless=true

to environment variable inside my pod like that到我的 pod 内的环境变量

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.我读到 yaml 似乎无法使用引号 - “ture” - 或不解析布尔值。 Is there any workaround?有什么解决方法吗?

application.properties can be configured by the SPRING_APPLICATION_JSON env variable application.properties可以通过SPRING_APPLICATION_JSON变量配置

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请参阅: https : //docs.spring.io/spring-boot/docs/current/reference/html/spring-boot-features.html#boot-features-external-config

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.要让环境变量覆盖 application.properties 中的值,您必须使用下划线作为分隔符以大写形式声明环境变量名称。

In your case the name of the environment variable should be AZURE_ACTIVEDIRECTORY_SESSIONSTATELESS在您的情况下,环境变量的名称应为AZURE_ACTIVEDIRECTORY_SESSIONSTATELESS

See the Relaxed Binding rules in the Spring Boot docs for further details.有关更多详细信息,请参阅 Spring Boot 文档中的宽松绑定规则。

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.环境变量本身本质上是字符串,因此值必须也是如此,否则无论如何它都会为您转换它。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM