繁体   English   中英

Helm - 如何使用 ConfigMap 在卷中写入文件?

[英]Helm - How to write a file in a Volume using ConfigMap?

我已经定义了values.yaml ,如下所示:

name: custom-streams
image: streams-docker-images
imagePullPolicy: Always
restartPolicy: Always
replicas: 1
port: 8080
nodeSelector:
  nodetype: free
configHocon: |-
  streams {
          monitoring {
            custom {
              uri = ${?URI}
              method = ${?METHOD}
            }
          }
  }

configmap.yaml如下:

apiVersion: v1
kind: ConfigMap
metadata:
  name: custom-streams-configmap
data:
  config.hocon: {{ .Values.configHocon | indent 4}}

最后,我定义了deployment.yaml ,如下所示:

apiVersion: apps/v1
kind: Deployment
metadata:
  name: {{ .Values.name }}
spec:
  replicas: {{ default 1 .Values.replicas }}
  strategy: {}
  template:
    spec:
      containers:
      - env:
        {{- range $key, $value := .Values.env }}
        - name: {{ $key }}
          value: {{ $value | quote }}
        {{- end }}
        image: {{ .Values.image }}
        name: {{ .Values.name }}
        volumeMounts:
        - name: config-hocon
          mountPath: /config
        ports:
        - containerPort: {{ .Values.port }}
      restartPolicy: {{ .Values.restartPolicy }}
      volumes:
      - name: config-hocon
        configmap:
          name: custom-streams-configmap
          items:
          - key: config.hocon
            path: config.hocon
status: {}

当我通过以下方式运行容器时:

helm install --name custom-streams custom-streams -f values.yaml --debug --namespace streaming

然后 pod 运行良好,但我在容器中看不到config.hocon文件:

$ kubectl exec -it custom-streams-55b45b7756-fb292 sh -n streaming
/ # ls
...
config
...
/ # cd config/
/config # ls
/config #

我需要写在/config文件夹中的config.hocon 谁能告诉我配置有什么问题?

我能够解决这个问题。 问题是在deployment.yaml中使用configmap代替configMap

apiVersion: apps/v1
kind: Deployment
metadata:
  name: {{ .Values.name }}
spec:
  replicas: {{ default 1 .Values.replicas }}
  strategy: {}
  template:
    spec:
      containers:
      - env:
        {{- range $key, $value := .Values.env }}
        - name: {{ $key }}
          value: {{ $value | quote }}
        {{- end }}
        image: {{ .Values.image }}
        name: {{ .Values.name }}
        volumeMounts:
        - name: config-hocon
          mountPath: /config
        ports:
        - containerPort: {{ .Values.port }}
      restartPolicy: {{ .Values.restartPolicy }}
      volumes:
      - name: config-hocon
        configMap:
          name: custom-streams-configmap
          items:
          - key: config.hocon
            path: config.hocon
status: {}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM