问题描述
我有以下 ConfigMap
。我正在尝试将两个数据源拆分为两个单独的文件,并在“构建时”使用 Kustomize 将它们合并。
但我就是不知道该怎么做?
这就是我所拥有的:
apiVersion: v1
kind: ConfigMap
Metadata:
name: grafana-datasources
namespace: grafana
data:
datasources.yaml: |-
apiVersion: 1
datasources:
- name: prometheus
type: prometheus
access: proxy
url: http://prometheus:9090
isDefault: true
version: 1
- name: Azure Monitor
type: grafana-azure-monitor-datasource
access: proxy
version: 1
我想拆分成单独文件(然后合并到 ConfigMap)的部分是:
- name: prometheus
type: prometheus
access: proxy
url: http://prometheus:9090
isDefault: true
version: 1
还有:
- name: Azure Monitor
type: grafana-azure-monitor-datasource
access: proxy
version: 1
解决方法
您必须为数据源创建两个单独的文件。 创建目录以放置基本配置:
$ mkdir -p $DEMO_HOME/base
第一个数据源应如下所示:
$ cat <<EOF >$DEMO_HOME/base/datasource1.yaml
apiVersion: 1
datasources:
- name: prometheus
type: prometheus
access: proxy
url: http://prometheus:9090
isDefault: true
version: 1
第二个数据源应如下所示:
$ cat <<EOF >$DEMO_HOME/base/datasource2.yaml
apiVersion: 1
datasources:
- name: Azure Monitor
type: grafana-azure-monitor-datasource
access: proxy
version: 1
$ cat <<EOF >$DEMO_HOME/base/kustomization.yaml
然后在 kustomization 文件中传递有关 configmap 的信息并添加文件:
$ cat <<EOF >$DEMO_HOME/base/kustomization.yaml
configMapGenerator:
- name: my-configmap
files:
- datasource1.yaml
- datasource2.yaml
EOF
最后,您可以生成用于开发的 configMap:
$ kustomize build $DEMO_HOME/base
请看:kustomize-operation,kustomize。
编辑:
您还可以将 ConfigMap 拆分为两个单独的 ConfigMap,它们都将包含一个文件。
第一个带有 datasources1.yaml
,第二个带有 datasources2.yaml
。