Kustomize/Kubernetes - 嵌套 envFrom 注入
我正在尝试添加基于 envFrom
的 envs 注入
。简化的结构看起来像这样:
├── base
│ ├ ─ backend
│ ├── backend.properties
│ ├── app1
│ │ ├── app1_backend.properties
├ ── deployment.yaml
│ │ ├── ingress.yaml
│ │ ├── kustomization.yaml
├── common.properties
├── frontend
│ ├── app1
│ ├── app1_frontend.properties
│ │ ├── deployment.yaml
│ │ ├── ingress.yaml
│ │ ├── kustomization.yaml
│ │ └── service.yaml
│ ├── frontend.properties
│ └── kustomization.yaml
└── kustomization.yaml
我想在主级别(公共)、后端/前端级别和特定应用程序级别生成属性。 所以我试图在主级别上添加以下补丁并且它可以工作:
- op: add
path: /spec/template/spec/containers/0/envFrom
value:
- configMapRef:
name: common-properties
并将以下代码添加到嵌套目录(后端/前端/特定应用程序)
- op: add
path: "/spec/template/spec/containers/0/envFrom/-"
value:
configMapRef:
name: backend-properties
但它不适用于以下错误:
add operation does not apply: doc is missing path: "/spec/template/spec/containers/0/envFrom/-": missing value
我在 GitHub 上看到了一些示例,其中使用语法:https://github.com/search?l=YAML&p=1&q=%2Fspec%2Ftemplate%2Fspec%2Fcontainers%2F0%2FenvFrom%2F-&type=Code (您有登录查看结果)而且我不确定这是否会在特定的 Kustomize 版本上停止工作(我正在使用最新版本 - 4.5.3)或者它从未工作过
我已经使用 /-
向资源编写一些 Kustomize 补丁和语法通常对于清单上已存在的资源效果很好。 可以在不同级别注入 envFrom
吗?
I'm trying to add envs injection based on envFrom
A simplified structure looks something like that:
├── base
│ ├ ─ backend
│ ├── backend.properties
│ ├── app1
│ │ ├── app1_backend.properties
├ ── deployment.yaml
│ │ ├── ingress.yaml
│ │ ├── kustomization.yaml
├── common.properties
├── frontend
│ ├── app1
│ ├── app1_frontend.properties
│ │ ├── deployment.yaml
│ │ ├── ingress.yaml
│ │ ├── kustomization.yaml
│ │ └── service.yaml
│ ├── frontend.properties
│ └── kustomization.yaml
└── kustomization.yaml
I would like to generate properties on the main level(common), backend/frontend level, and particular app level.
So I was trying to add the following patch on main level and it works:
- op: add
path: /spec/template/spec/containers/0/envFrom
value:
- configMapRef:
name: common-properties
and following code to nested directories(backend/frontend/particular app)
- op: add
path: "/spec/template/spec/containers/0/envFrom/-"
value:
configMapRef:
name: backend-properties
But it doesn't work with the following error:
add operation does not apply: doc is missing path: "/spec/template/spec/containers/0/envFrom/-": missing value
I have seen some examples on GitHub where that syntax was used: https://github.com/search?l=YAML&p=1&q=%2Fspec%2Ftemplate%2Fspec%2Fcontainers%2F0%2FenvFrom%2F-&type=Code (you have to be logged in to see results) And I'm not sure this stopped work on specific Kustomize version(I'm using the newest version - 4.5.3) or it never worked
I have already written some Kustomize patches and syntax with /-
to resources usually worked fine to resources that already exist on the manifest.
It's possible to inject that envFrom
on different levels?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果没有可重现的示例,很难诊断您的问题,但如果我从这个部署开始:
并使用这个 kustomization.yaml,其中包含您的补丁,而无需
变化:
然后一切似乎都有效,我得到了结果输出
kustomize 构建
:It's hard to diagnose your problem without a reproducible example, but if I start with this
Deployment
:And use this
kustomization.yaml
, which includes your patch withoutchanges:
Then everything seems to work and I get the resulting output from
kustomize build
: