我有 kustomize 部署,它安装了 Helm Chart。 此 helm 图表需要特定的配置映射存在并安装到 pod 中。 configMapGenerator 组件生成带有哈希后缀的配置映射。
即以下定制部分:
configMapGenerator:
- name: my-config-map
files:
- my-file.json
将生成名为
my-config-map-fdt4f87bkm
的配置映射。我想将此配置映射传递到 HelmRelease
中的 helm 图表:
values:
configmap: my-config-map
但是这不起作用,因为配置映射的真实名称是
my-config-map-fdt4f87bkm
。
我想继续使用 configMapGenerator 以确保在配置发生更改时滚动 pod。
我如何才能在那里传递配置映射的真实姓名?
你有两种方法。要么关闭后缀哈希,例如:
configMapGenerator:
- name: my-config-map
files:
- my-file.json
options:
disableNameSuffixHash: true
或使用 kustomizeconfig。
(我正在考虑
HelmRelease
你的意思是 FluxCD HelmRelease 对象,并且你通过 .spec.valuesFrom
而不是 .spec.values
为其提供值)
对于 kustomize 配置,您必须提供包含以下内容的文件:
---
nameReference:
- kind: ConfigMap
version: v1
fieldSpecs:
- path: spec/valuesFrom/name
kind: HelmRelease
此文件使 kustomize 将 configMap 后缀附加到引用的 configMap 以获取 helm 发布值。 现在设置您的
kustomization.yaml
以使用此文件:
---
apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization
resources:
- helmrelease.yaml
configMapGenerator:
- name: my-config-map
files:
- my-file.json
configurations:
- kustomizeconfig.yaml
使用 kustomizeconfig 文件输出
kustomize build
:
apiVersion: v1
data:
my-file.json: |
{
"this": "that"
}
kind: ConfigMap
metadata:
name: my-config-map-mb2ck9tb4f
---
apiVersion: helm.toolkit.fluxcd.io/v2beta1
kind: HelmRelease
metadata:
name: my-release
spec:
chart:
spec:
chart: test
sourceRef:
kind: HelmRepository
name: test
namespace: test
version: 1.1.1
releaseName: my-release
targetNamespace: kkk
timeout: 15m
valuesFrom:
- kind: ConfigMap
name: my-config-map-mb2ck9tb4f