Helm变量替换在appsettings文件中。

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

Helm variable substitution in an appsettings file

问题

  "auth": {
    "apiScopeSecret": "${auth__apiScopeSecret}"
  },
  "discovery": {
    "uri": "${discovery__uri}"
  }
英文:

I am trying to use helm to define some variables (including secrets which have been defined in GCP) and use them in an appsettings.json file. None are pulling through. My helm chart defines the vars as below. Some 'secrets' are pulling from the helm chart and some will be from GCP secrets):

  - name: ASPNETCORE_ENVIRONMENT
    value: qa-k8
  - name: auth__apiScopeSecret
    value: foo
  - name: discovery__uri
    value: bar


envFrom:
  - secretRef:
      name: blah-secrets

gcpSecrets:
  enabled: true
  secretsFrom:
    - blah-secrets

And my appsettings.json file is configured as per the below example. When I check the container, none of the variables within the helm chart have translated and the values are blank. What am I missing? I understand that the double underscores are required to locate the variables in the correct locations and probably aren't required in the appsettings file.

  "auth": {
    "apiScopeSecret": "${auth__apiScopeSecret}"
  },
  "discovery": {
    "uri": "${discovery__uri}"

答案1

得分: 2

这也是预期行为。通常,您会创建一个包含Helm值的appsettings文件,作为配置映射(ConfigMap)或密钥(Secret)在部署期间进行替换,然后将其挂载到容器中。在您的情况下,我看不到您将任何内容挂载到容器中,您只是将其作为环境变量提供。

  1. 您应该指定一个包含Helm值的密钥或配置映射,以提供appsettings文件。
apiVersion: v1
kind: ConfigMap
metadata:
  name: appsettings
data:
  appsettings.dev.json: |-
    {
      "Logging": {
        "LogLevel": {
          "Default": {{my__helmvalue}},
        }
      }
    }    
  1. 在您的Pod中,您应该指定卷(volumes),并在容器中使用volumeMounts来指定appsettings文件应该挂载到哪个位置。
apiVersion: v1
kind: Pod
metadata:
   name: examplepod
spec:
   containers:
     - name: test-container
       image: myimage
       volumeMounts:
       - name: config-volume
         mountPath: /app ## 指定要覆盖appsettings文件的路径!
   volumes:
     - name: config-volume
       configMap:
         name: appsettings
   restartPolicy: Never
英文:

That is also the expected Behaviour. Usually You create the appsettings file with the helm values as a cm or secret that are replaced during the deployment and then you mount it into your container. In your case I dont see that you mount something into the container you just provide it as an env.

  1. You should specify a secret or configMap with your helm values that provide the appsettings file.
apiVersion: v1
kind: ConfigMap
metadata:
  name: appsettings
data:
  appsettings.dev.json: |-
    {
      "Logging": {
        "LogLevel": {
          "Default": {{my__helmvalue}},
        }
      }
    }

  1. In your pod you should specify the volumes and in your container the volumeMounts to specify in wich location the appsetting file should get mounted into.
apiVersion: v1
kind: Pod
metadata:
   name: examplepod
spec:
   containers:
     - name: test-container
       image: myimage
       volumeMounts:
       - name: config-volume
         mountPath: /app ## specify your path to overwrite the appsettingsfile!
   volumes:
     - name: config-volume
       configMap:
         name: appsettings
   restartPolicy: Never

huangapple
  • 本文由 发表于 2023年7月18日 04:03:12
  • 转载请务必保留本文链接:https://go.coder-hub.com/76707751.html
匿名

发表评论

匿名网友

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

确定