使用Helm在K8s中将yml的内容作为configmap加载

时间:2019-11-22 05:11:42

标签: kubernetes kubernetes-helm configmap

是否可以使用Helm Charts在k8​​s中将yml的内容作为configamp加载? ConfigMap的头盔图

Doc Number  Text           Amount
122        DB1 DB2 DB3     50
345        DB4 DB5 DB6 DB7 55

示例application.yml。

df.groupby('Doc Number').apply(lambda x: ' '.join(x.Text))

预期的configmap

{{- define "common.configmap.tpl" -}}
kind: ConfigMap
apiVersion: v1
{{ template "common.metadata" . }}
  namespace: {{ .Values.namespace | default "default" }}
data:
{{ range $path, $bytes := .Files.Glob "config/*.yml" }}
  {{- $.Files.Get $path | indent 2 }}
{{ end }}
{{- end }}
{{- define "common.configmap" -}}
{{- template "common.util.merge" (append . "common.configmap.tpl") -}}
{{- end }}

1 个答案:

答案 0 :(得分:0)

该文档可能对Accessing Files Inside Templates有帮助。

您应该可以对其进行调整以使其为您工作:

apiVersion: v1
kind: ConfigMap
metadata:
  name: {{ .Release.Name }}-configmap
data:
  config.json: |-
    {
{{- range $key, $val := .Values.json }}
{{ $key | quote | indent 6}}: {{ $val | quote }}
{{- end}}
    }

values.yaml

json:
  key1: val1
  key2: val2
  key3: val3
apiVersion: v1
kind: ConfigMap
metadata:
  name: mangy-hare-configmap
data:
  config.json: |-
    {
      "key1": "val1"
      "key2": "val2"
      "key3": "val3"
    }

或者您可以尝试通过以下方式加载yaml

{{ (.Files.Glob "files/indexes.conf").AsConfig | indent 2 }}