【问题标题】:How can we specify custom path to .Files.Get when creating ConfigMap with Helm使用 Helm 创建 ConfigMap 时如何指定 .Files.Get 的自定义路径
【发布时间】:2021-03-16 22:03:53
【问题描述】:

我正在创建如下配置图

kubectl create configmap testconfigmap --from-file=testkey=/var/opt/testfile.txt

由于我正在使用 helm 图表,我想使用 YAML 文件而不是运行 kubectl 创建配置映射。 我浏览了Kubernetes - How to define ConfigMap built using a file in a yaml?,我们可以使用.Files.Get 来访问这些文件。 但是 testfile.txt 需要成为 helm 的一部分。我想要类似的东西

kind: ConfigMap
metadata:
  name: testconfigmap
data:
  fromfile: |-
{{ .Files.Get "/var/opt/testfile.txt" | indent 4 }}

当“testfile.txt”位于主 helm 目录下时,它可以工作。所以,{{ .Files.Get "testfile.txt" | indent 4 }} 有效,但 {{ .Files.Get "/var/opt/testfile.txt" | indent 4 }} 无效。使用自定义路径,ConfigMap 的值为空。

是否可以将文件放在 helm 文件夹之外的自定义路径中,这样我就可以在 Values.yaml 中定义我的路径并在我的 ConfigMap yaml 中读取它?

【问题讨论】:

标签: kubernetes kubernetes-helm configmap


【解决方案1】:

这是一个社区 Wiki 答案,因此请随时对其进行编辑并添加您认为重要的任何其他详细信息。

正如mdaniel 已经在他的评论中所说:

是否可以将文件放置在 helm 外部的自定义路径中 文件夹 不,因为helm considers that a security risk – mdaniel 2 几天前

您还可以将其与 GitHub 上的this 功能请求进行比较,您可以在其中找到非常相似的要求,例如简短描述。在this comment:

我有这个确切的需要。我的图表发布了从文件中读取的秘密 /密钥库。此文件故意不在图表中。

我相信 .Files.Get 的文件不应该被假定在 图表...

一个有趣的comment

lenalebt 于 2017 年 12 月 23 日发表评论 我很确定 .Files.Get 不是 能够任意访问文件系统是一种安全 功能,所以我不认为当前的行为是错误的 - 它只是 不能满足所有用例。

这个问题是很久以前(2017 年 12 月 19 日)创建的,但最近又重新打开了。甚至还有some specific proposals on how it could be handled

titou10titou10 于 4 月 2 日发表评论 @misberner 你能确认一下吗 using--include-dir =将允许我们使用 .Files.Glob().AsConfig(),因此创建一个 ConfigMap 每个文件在 CM 中的条目?

@misberner misberner 于 4 月 2 日发表评论 是的,就是这样。一个开放的 从我的角度来看,问题是 --include-dir 是否带有 指定引入覆盖,或阴影下的所有内容 / 来自先前的参数和包本身。我不是超级 固执己见,但更喜欢前者。

最近的 cmets 给了一些希望,这个功能可能会在未来的 helm 版本中可用。

【讨论】:

    【解决方案2】:

    正如mdanielmario 已经提到的,目前这是不可能的,因为它被认为是安全风险。

    但实际上 是一种解决方法。
    您可以使用 Helm 模板来解析您的属性文件并将其加载到 ConfigMap 中。

    # create the following ConfigMap in your Chart
    # this is just a simple prototype
    # it requires strict key=value syntax in your property file (no empty strings etc.)
    # but it shows the idea - improve the syntax, if needed
    apiVersion: v1
    kind: ConfigMap
    metadata:
      name: example
    data:
      {{- if .Values.example.map }}
      {{- range $line := splitList "\n" .Values.example.map }}
      {{- $words := splitList "=" $line }}
      {{- $key := index $words 0 | trim }}
      {{- $value := rest $words | join "=" | trim }}
      {{ $key }}: "{{ $value }}"
      {{- end }}
      {{- end }}
    {{- end }}
    

    然后你可以将你的属性文件加载到这个 ConfigMap 中。

    helm install mychart --set-file example.map="/test/my.properties"
    

    当然,只有在完全控制输入的情况下才能安全使用,即。 e.如何填充属性文件的每一行。

    【讨论】:

      猜你喜欢
      • 2019-11-23
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-01-10
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多