kubernetes - 使用 Helm 创建 ConfigMap 时如何指定 .Files.Get 的自定义路径

标签 kubernetes kubernetes-helm configmap

我正在创建如下配置图

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"|缩进 4 }} 有效,但 {{ .Files.Get "/var/opt/testfile.txt"|缩进 4 }} 没有。使用自定义路径时,ConfigMap 的值为空。

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

最佳答案

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

作为mdaniel已经在他的评论中表示:

Is is possible to place the file at a custom path outside the helm folder no, because helm considers that a security risk – mdaniel 2 days ago

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

I have this exact need. My chart publishes a secret read from file at /keybase. This file is deliberately not in the chart.

I believe files for .Files.Get should not be assumed to be inside the chart ...

一个有趣的comment :

lenalebt commented on Dec 23, 2017 I am quite sure .Files.Get not being able to access the file system arbitrarily is a security feature, so I don't think the current behaviour is wrong - it just does not fulfill all use cases.

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

titou10titou10 commented on Apr 2 @misberner can you confirm that using--include-dir =will allow us to use .Files.Glob().AsConfig(), and so create a ConfigMap with one entry in the CM per file in?

@misberner misberner commented on Apr 2 Yeah that's the idea. An open question from my point of view is whether an --include-dir with a specified introduces an overlay, or shadows everything under / from previous args and from the bundle itself. I'm not super opinionated on that one but would prefer the former.

最近的评论给出了一些希望,即此功能可能会在未来的 helm 版本中可用。

关于kubernetes - 使用 Helm 创建 ConfigMap 时如何指定 .Files.Get 的自定义路径,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/65150554/

相关文章:

elasticsearch - 如何在 Kubernetes 上的 Elasticsearch 中禁用交换?

kubernetes-helm - 仅获取文件内容并对此内容运行 `tpl` [kubernetes-helm]

kubernetes-helm - 如何在 Helm 安装中通过 `prometheus.io/scrape`参数传递 `--set`值

java - 无法读取名称为 : [my-configmap] in namespace:[my-namespace]. 的 configMap 忽略

kubernetes - kubectl 补丁无法应用于 ConfigMap 数据

kubernetes - Kubectl-如何从配置变量读取入口主机?

azure - 如何将 Kubernetes 集群应用到现有的 azure 虚拟机

templates - 如何使用 K8S 在 pod 模板中测试删除GracePeriodSeconds

kubernetes - 如何将 Windows docker 容器部署到 docker-for-desktop Kubernetes 集群?拉取访问被拒绝

kubernetes - 如何 kubectl 端口转发 GitLab web 服务?