mpe*_*pen 7 kubernetes kustomize
在我的kustomization.yaml我有:
...\nsecretGenerator:\n - name: db-env\n behavior: create\n envs:\n - my.env\npatchesStrategicMerge:\n - app.yaml\nRun Code Online (Sandbox Code Playgroud)\n然后在我的app.yaml(补丁)中我有:
apiVersion: apps/v1\nkind: Deployment\nmetadata:\n name: app-deployment\nspec:\n template:\n spec:\n containers:\n - name: server\n envFrom:\n - secretRef:\n name: db-env\nRun Code Online (Sandbox Code Playgroud)\n当我尝试通过构建这个时,kustomize build k8s/development我退出了:
apiVersion: apps/v1\nkind: Deployment\n...\n spec:\n containers:\n - envFrom:\n - secretRef:\n name: db-env\n name: server\nRun Code Online (Sandbox Code Playgroud)\n什么时候应该是:
\n - envFrom:\n - secretRef:\n name: db-env-4g95hhmhfc\nRun Code Online (Sandbox Code Playgroud)\n如何让secretGenerator名称哈希也适用patchesStrategicMerge?
或者,将一些环境变量注入到特定覆盖的部署中的正确方法是什么?
\n这是为了发展。
\n我的文件结构是这样的:
\n\xe2\x9d\xaf tree k8s\nk8s\n\xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 base\n\xe2\x94\x82\xc2\xa0\xc2\xa0 \xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 app.yaml\n\xe2\x94\x82\xc2\xa0\xc2\xa0 \xe2\x94\x94\xe2\x94\x80\xe2\x94\x80 kustomization.yaml\n\xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 development\n\xe2\x94\x82\xc2\xa0\xc2\xa0 \xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 app.yaml\n\xe2\x94\x82\xc2\xa0\xc2\xa0 \xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 golinks.sql\n\xe2\x94\x82\xc2\xa0\xc2\xa0 \xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 kustomization.yaml\n\xe2\x94\x82\xc2\xa0\xc2\xa0 \xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 mariadb.yaml\n\xe2\x94\x82\xc2\xa0\xc2\xa0 \xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 my.cnf\n\xe2\x94\x82\xc2\xa0\xc2\xa0 \xe2\x94\x94\xe2\x94\x80\xe2\x94\x80 my.env\n\xe2\x94\x94\xe2\x94\x80\xe2\x94\x80 production\n \xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 ingress.yaml\n \xe2\x94\x94\xe2\x94\x80\xe2\x94\x80 kustomization.yaml\nRun Code Online (Sandbox Code Playgroud)\n哪里base/kustomization.yaml:
\xe2\x9d\xaf tree k8s\nk8s\n\xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 base\n\xe2\x94\x82\xc2\xa0\xc2\xa0 \xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 app.yaml\n\xe2\x94\x82\xc2\xa0\xc2\xa0 \xe2\x94\x94\xe2\x94\x80\xe2\x94\x80 kustomization.yaml\n\xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 development\n\xe2\x94\x82\xc2\xa0\xc2\xa0 \xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 app.yaml\n\xe2\x94\x82\xc2\xa0\xc2\xa0 \xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 golinks.sql\n\xe2\x94\x82\xc2\xa0\xc2\xa0 \xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 kustomization.yaml\n\xe2\x94\x82\xc2\xa0\xc2\xa0 \xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 mariadb.yaml\n\xe2\x94\x82\xc2\xa0\xc2\xa0 \xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 my.cnf\n\xe2\x94\x82\xc2\xa0\xc2\xa0 \xe2\x94\x94\xe2\x94\x80\xe2\x94\x80 my.env\n\xe2\x94\x94\xe2\x94\x80\xe2\x94\x80 production\n \xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 ingress.yaml\n \xe2\x94\x94\xe2\x94\x80\xe2\x94\x80 kustomization.yaml\nRun Code Online (Sandbox Code Playgroud)\n并且development/kustomization.yaml是:
namespace: go-mpen\nresources:\n- app.yaml\nimages:\n- name: server\n newName: reg/proj/server\nRun Code Online (Sandbox Code Playgroud)\n
这对我来说效果很好kustomize v3.8.4。您能否检查一下您的版本,如果disableNameSuffixHash没有设置为 true。
以下是我用来测试这一点的清单:
\n\xe2\x9e\x9c app.yaml deployment.yaml kustomization.yaml my.env\nRun Code Online (Sandbox Code Playgroud)\n应用程序.yaml
\nkind: Deployment\nmetadata:\n name: app-deployment\nspec:\n template:\n spec:\n containers:\n - name: server\n envFrom:\n - secretRef:\n name: db-env\nRun Code Online (Sandbox Code Playgroud)\n部署.yaml
\napiVersion: apps/v1\nkind: Deployment\nmetadata:\n name: app-deployment \n labels:\n app: nginx\nspec:\n replicas: 3\n selector:\n matchLabels:\n app: nginx\n template:\n metadata:\n labels:\n app: nginx\n spec:\n containers:\n - name: nginx\n image: nginx:1.14.2\n ports:\n - containerPort: 80\nRun Code Online (Sandbox Code Playgroud)\n和我的 kustomization.yaml
\napiVersion: kustomize.config.k8s.io/v1beta1\nkind: Kustomization\n\nsecretGenerator:\n - name: db-env\n behavior: create\n envs:\n - my.env\npatchesStrategicMerge:\n - app.yaml\n\nresources: \n - deployment.yaml \nRun Code Online (Sandbox Code Playgroud)\n这是结果:
\napiVersion: v1\ndata:\n ASD: MTIz\nkind: Secret\nmetadata:\n name: db-env-f5tt4gtd7d\ntype: Opaque\n---\napiVersion: apps/v1\nkind: Deployment\nmetadata:\n labels:\n app: nginx\n name: app-deployment\nspec:\n replicas: 3\n selector:\n matchLabels:\n app: nginx\n template:\n metadata:\n labels:\n app: nginx\n spec:\n containers:\n - image: nginx:1.14.2\n name: nginx\n ports:\n - containerPort: 80\n - envFrom:\n - secretRef:\n name: db-env-f5tt4gtd7d\n name: server\nRun Code Online (Sandbox Code Playgroud)\n
| 归档时间: |
|
| 查看次数: |
7594 次 |
| 最近记录: |