0

My configMap file:

kind: ConfigMap 
apiVersion: v1 
metadata:
  name: config
data:
  config.xml: |
{{ .Files.Get "configuration/config.tpl" | indent 4 }}
  control1.xml: |
{{ .Files.Get "controlsets/control1.tpl" | indent 4 }}
  control2.xml: |
{{ .Files.Get "controlsets/control2.tpl" | indent 4 }}

How do I achieve that config.xml will be mounted to configuration folder and both control files to controlsets folder? Thank you for answer.

EDIT: I solved issue but I think it can be done more dynamically.

configMap file stays the same.

volumeMounts part of deployment file:

volumeMounts:
    - name: config-volume
      mountPath: /app/Configuration/config.xml
      subPath: config.xml
    - name: config-volume
      mountPath: /app/Controlsets/control1.xml
      subPath: control1.xml
    - name: config-volume
      mountPath: /app/Controlsets/control2.xml
      subPath: control2.xml

How would I achieve that all files which are in controlsets folder go into /app/Controlsets folder and all files in configuration go to /app/Configuration folder with script? Now I have to change yaml files for each config file I add. It would be nice If just write relations between folders and the rest is done by helm.

4

1 回答 1

0

可以通过遍历文件夹来解决。

配置.yaml

apiVersion: v1
kind: ConfigMap
metadata:
  name: {{ $.Values.test.name }}
  labels:
    {{- range $k, $v := $.Values.test.labels}}
    {{ $k }}: {{ $v }}
    {{- end }}
data:
  {{- range $path, $_ :=  .Files.Glob  "configuration/**" }}
  {{ (base $path) | trimSuffix ".tpl" }}.xml: |-
    {{ $.Files.Get $path | nindent 4 }}
  {{- end }}

部署.yaml

apiVersion: apps/v1
kind: Deployment
metadata:
  name: {{ include "test.fullname" . }}
spec:
  template:
    spec:
      containers:
        - name: {{ .Chart.Name }}
          image: "{{ .Values.image.repository }}:{{ .Values.image.tag | default .Chart.AppVersion }}"
          imagePullPolicy: {{ .Values.image.pullPolicy }}
          volumeMounts:
            - mountPath: config-volume
              name: /app/Configuration
      volumes:
        - name: config-volume
          configMap:
            name: {{ $.Values.test.name }}

于 2021-08-25T03:49:14.590 回答