gpt4 book ai didi

kubernetes-helm - Helm 从多个配置 YAML 文件构建动态 configmap

转载 作者:行者123 更新时间:2023-12-05 05:50:13 25 4
gpt4 key购买 nike

我有两个文件如下:

_config-dev.yaml

frontend:
NODE_ENV: dev
REACT_APP_API_URL: 'https://my-dev-apiurl/'

database:
DB_USER: admin-dev
DB_PASSWORD: password-dev

_config-stag.yaml


frontend:
NODE_ENV: stag
REACT_APP_API_URL: 'https://my-stag-api-url/'

database:
DB_USER: admin-stag
DB_PASSWORD: password-stag

我的ConfigMap.yaml

kind: ConfigMap
apiVersion: v1
metadata:
name: {{ .Release.Name }}-frontend
namespace: {{ .Values.global.namespace }}
data:
# Here I want to insert only frontend data from _config-dev.yaml file if my {{ eq .Values.global.environment "dev" }} like below
NODE_ENV: dev
REACT_APP_API_URL: 'https://my-dev-apiurl/'

# if my {{ eq .Values.global.environment "stag" }} i want to get frontend values from _config-dev.yaml like below
NODE_ENV: stag
REACT_APP_API_URL: 'https://my-stag-api-url/'

任何人都可以弄清楚如何按照 myConfigMap.yaml 文件中提到的上述场景插入数据作为数据下的注释:。

最佳答案

我的测试项目

test
├── Chart.yaml
├── cfg
│   ├── _config-dev.yaml
│   └── _config-stag.yaml
├── templates
│   └── configmap.yaml
└── values.yaml

值.yaml

global:
environment: dev

测试/cfg/_config-dev.yaml

frontend:
NODE_ENV: dev
REACT_APP_API_URL: 'https://my-dev-apiurl/'

database:
DB_USER: admin-dev
DB_PASSWORD: password-dev

测试/cfg/_config-stag.yaml

frontend:
NODE_ENV: stag
REACT_APP_API_URL: 'https://my-stag-api-url/'

database:
DB_USER: admin-stag
DB_PASSWORD: password-stag

测试/模板/configmap.yaml

apiVersion: v1
kind: ConfigMap
metadata:
name: {{ include "test.fullname" . }}
data:
{{- $data := .Files.Get "cfg/_config-stag.yaml" }}
{{- if eq .Values.global.environment "dev" }}
{{- $data = .Files.Get "cfg/_config-dev.yaml" }}
{{- end }}
{{- $cfg := fromYaml $data }}
{{- range $k, $v := $cfg.frontend }}
{{ $k }}: {{ $v }}
{{- end }}

输出

apiVersion: v1
kind: ConfigMap
metadata:
name: test
data:
NODE_ENV: dev
REACT_APP_API_URL: https://my-dev-api-url/

关于kubernetes-helm - Helm 从多个配置 YAML 文件构建动态 configmap,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/70546983/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com