Quarkus未捕获Kubernetes环境变量。

huangapple go评论61阅读模式
英文:

Quarkus not picking up Kubernetes environment variable

问题

这是您要翻译的内容:

我在GitHub上部署时有两个环境,希望能够在日志中区分它们,因此我有一个名为 ENVIRONMENT 的字段,可以设置为 QALIVE

以下是我在 main.tf 中设置这些字段的方式:

locals {
  environment = {
    qa = "QA"
    live = "LIVE"
  }
}

resource "kubernetes_manifest" "config" {
  manifest = {
    "apiVersion" = "v1"
    "kind"       = "ConfigMap"
    "metadata" = {
      "name"      = "config"
      "namespace" = "test"
    }
    "data" = {
      "ENVIRONMENT" = local.environment[terraform.workspace]
    }
  }
}

这会设置我的 ConfigMap 中的 ENVIRONMENT 字段。我已经通过运行 kubectl 命令进行确认,并可以在部署中的 ConfigMap 中看到该字段。

然后,我在 application.properties 中如下读取此字段:

quarkus.log.json.additional-field."environment".value=${ENVIRONMENT:unknown}

因为这是在运行时设置的,当有可供读取的 ConfigMap 时,它将被设置。所以我非常困惑为什么我的所有日志仍然显示环境为 unknown?我在我的日志记录中使用了 quarkus-logging-json

英文:

I have two environments when I am deploying on GitHub, and want to be able to discern between the two in my logs, therefore I have an ENVIRONMENT field which is set to either QA or LIVE.

Here is how I set these fields in main.tf:

locals {
  environment = {
    qa = "QA"
    live = "LIVE"
  }
}

resource "kubernetes_manifest" "config" {
  manifest = {
    "apiVersion" = "v1"
    "kind"       = "ConfigMap"
    "metadata" = {
      "name"      = "config"
      "namespace" = "test"
    }
    "data" = {
      "ENVIRONMENT" = local.environment[terraform.workspace],
    }
  }
}

This sets the ENVIRONMENT field in my configMap. I have confirmed this running kubectl commands, and can see this field with in the configMap with the deployment.

I then read this field in my application.properties like so:

quarkus.log.json.additional-field."environment".value=${ENVIRONMENT:unknown}

Because this is set on runtime, it will be set when there is a configMap available to read from, so I am very confused as to why all my logs still say unknown for the environment? I am using quarkus-logging-json for my logging

答案1

得分: 0

Adding the following line to my application.properties resolved the issue.

It seems as though the issue was that the configMap was being deployed correctly in the container, but wasn't setting the values as environment variables in quarkus. This line sets all the values in the configMap as environment variables in Quarkus.

英文:

Adding the following line to my application.properties resolved the issue.

quarkus.kubernetes.env.configmaps=CONFIG_MAP_NAME

It seems as though the issue was that the configMap was being deployed correctly in the container, but wasn't setting the values as environment variables in quarkus. This line sets all the values in the configMap as environment variables in Quarkus.

huangapple
  • 本文由 发表于 2023年6月15日 00:15:32
  • 转载请务必保留本文链接:https://go.coder-hub.com/76475625.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定