Helm变量替换在appsettings文件中。

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

Helm variable substitution in an appsettings file

问题

  1. "auth": {
  2. "apiScopeSecret": "${auth__apiScopeSecret}"
  3. },
  4. "discovery": {
  5. "uri": "${discovery__uri}"
  6. }
英文:

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):

  1. - name: ASPNETCORE_ENVIRONMENT
  2. value: qa-k8
  3. - name: auth__apiScopeSecret
  4. value: foo
  5. - name: discovery__uri
  6. value: bar
  7. envFrom:
  8. - secretRef:
  9. name: blah-secrets
  10. gcpSecrets:
  11. enabled: true
  12. secretsFrom:
  13. - 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.

  1. "auth": {
  2. "apiScopeSecret": "${auth__apiScopeSecret}"
  3. },
  4. "discovery": {
  5. "uri": "${discovery__uri}"

答案1

得分: 2

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

  1. 您应该指定一个包含Helm值的密钥或配置映射,以提供appsettings文件。
  1. apiVersion: v1
  2. kind: ConfigMap
  3. metadata:
  4. name: appsettings
  5. data:
  6. appsettings.dev.json: |-
  7. {
  8. "Logging": {
  9. "LogLevel": {
  10. "Default": {{my__helmvalue}},
  11. }
  12. }
  13. }
  1. 在您的Pod中,您应该指定卷(volumes),并在容器中使用volumeMounts来指定appsettings文件应该挂载到哪个位置。
  1. apiVersion: v1
  2. kind: Pod
  3. metadata:
  4. name: examplepod
  5. spec:
  6. containers:
  7. - name: test-container
  8. image: myimage
  9. volumeMounts:
  10. - name: config-volume
  11. mountPath: /app ## 指定要覆盖appsettings文件的路径!
  12. volumes:
  13. - name: config-volume
  14. configMap:
  15. name: appsettings
  16. 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.
  1. apiVersion: v1
  2. kind: ConfigMap
  3. metadata:
  4. name: appsettings
  5. data:
  6. appsettings.dev.json: |-
  7. {
  8. "Logging": {
  9. "LogLevel": {
  10. "Default": {{my__helmvalue}},
  11. }
  12. }
  13. }
  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.
  1. apiVersion: v1
  2. kind: Pod
  3. metadata:
  4. name: examplepod
  5. spec:
  6. containers:
  7. - name: test-container
  8. image: myimage
  9. volumeMounts:
  10. - name: config-volume
  11. mountPath: /app ## specify your path to overwrite the appsettingsfile!
  12. volumes:
  13. - name: config-volume
  14. configMap:
  15. name: appsettings
  16. 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:

确定