首页 > 解决方案 > 如何在 HelmV3 中正确声明卷?

问题描述

我目前正在努力将 Helm 图表从 Helm V2 修改为 Helm V3,但我遇到了许多兼容性错误。

我有这样的 configmap 声明:

  ConfigMap:
      data.properties: |
        data1: my_data
        data2: my beautiful_data
        data3: my wonderful_data
      config.properties: |
        config1: my_config
        config2: my_beautiful_config
        config3: my_wonderful_config

直到现在我这样宣布我的卷:

  volumes:
      - name: configmap-config
        configMap:
          name: "config-configmap"
          key: config.properties
          path: config.properties
      - name: configmap-data
        configMap:
          name: "data-configmap"
          key: data.properties
          path: data.properties

但是使用 Helm V3 我得到了这个错误:

[ValidationError(Deployment.spec.template.spec.volumes[0].configMap): unknown field \"key\" in io.k8s.api.core.v1.ConfigMapVolumeSource,
ValidationError(Deployment.spec.template.spec.volumes[0].configMap): unknown field \"path\" in io.k8s.api.core.v1.ConfigMapVolumeSource,

我进行了多次搜索,但没有找到解释 V2 中的图表和 V3 中的图表之间差异的文档。如何在 Helm V3 中使用此 configmap 声明卷?

标签: kubernetes-helm

解决方案


这不是 helm 版本的真正问题。我想这与您的 kubernetes yaml 文件有关。使用卷挂载配置映射的正确方法

 volumes:
    - name: data
      emptyDir: {}
    - name: config
      configMap:
        name: example-redis-config
        items:
        - key: redis-config
          path: redis.conf

我不确定为什么它可以与 helm v2 一起使用,但请尝试更新您的 yaml 文件


推荐阅读