如何使用fabric8 maven插件使用环境变量中的值指定 spring.profiles.active 参数? [英] How can I specify the spring.profiles.active param with a value from an environment variable using fabric8 maven plugin?

查看:143
本文介绍了如何使用fabric8 maven插件使用环境变量中的值指定 spring.profiles.active 参数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个定义环境参数的 K8s 配置映射.

I have a K8s config map that defines an ENVIRONMENT parameter.

使用 src/fabric8/deployment.yml 中的摘录将该值作为环境变量挂载到部署 yaml 上:

That value is mounted as an environment variable on the deployment yaml using an excerpt in src/fabric8/deployment.yml:

spec:
  template:
    spec:
      containers:
      - env:
        - name: "ENVIRONMENT"
          valueFrom:
              configMapKeyRef:
                  name: global-configmap
                  key: ENVIRONMENT

我想使用那个 ENVIRONMENT 环境变量来配置 spring.active.profiles 属性.

I would like to use that ENVIRONMENT env variable to configure the spring.active.profiles property.

fabric8 maven 插件是否以某种方式支持它?如果没有,您能提出一些解决方法吗?

Is it supported in some way by fabric8 maven plugin? If not, can you suggest some workaround?

推荐答案

首先要注意的一点是,注入到 Pod 中的环境变量的名称与 configmap 中使用的键不必匹配.所以你可以这样做:

One thing to note first is that the name given to the environment variable injected into the Pod and the key being used from the configmap don't have to match. So you could do:

      - env:
        - name: SPRING_PROFILES_ACTIVE
          valueFrom:
              configMapKeyRef:
                  name: global-configmap
                  key: ENVIRONMENT

如果 ENVIRONMENT 是名为 global-configmap 的配置映射中的键.如果不是,那么您很自然地想要使用与您正在寻找的值相匹配的任何键(如果可能的话,像 spring.profiles.active 这样的东西可能会更清晰,但从您的描述来看,您似乎有一个名为 global- 的现有配置映射 -configmap 的键名为 ENVIRONMENT).我希望您需要调用环境变量(名称部分)SPRING_PROFILES_ACTIVE,因为这将与 宽松绑定.

If ENVIRONMENT is a key within the configmap called global-configmap. If it's not then naturally you want to use whatever the key is that matches the value you're looking for (something like spring.profiles.active might be clearer if possible but from your description it sounds like you have an existing configmap called global-configmap with the key called ENVIRONMENT). I expect you'll need to call the environment variable (the name section) SPRING_PROFILES_ACTIVE because this will match to the property spring.profiles.active by relaxed binding.

或者,您确实有其他选项与 fabric8 maven 插件,似乎您正在使用它.您可以简单地直接设置环境变量或直接在您的属性文件中设置 spring.profiles.active 值,您可以将其作为配置映射挂载.

Alternatively, you do have other options with the fabric8 maven plugin, which it seems you're using for generation. You could simply set an environment variable directly or set the spring.profiles.active value directly in your property file, which you could mount as a configmap.

这篇关于如何使用fabric8 maven插件使用环境变量中的值指定 spring.profiles.active 参数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆