当我们在资源部分下的 kustomization.yaml 文件中指定基本清单文件时,Kubernetes kustomize 命令给出错误

shi*_*jan 9 yaml kubernetes kustomize

我正在尝试为特定环境示例构建清单文件:- 测试,我想重新使用基本清单文件,如下所述。

k8s/kustomize/overlays/test/kustomization.yaml

commonLabels:
  variant: test
  app: test-app
resources:
- ../../base/deployment.yaml
- ../../base/service.yaml
- ../../base/configmap.yaml
- ../../base/secret.yaml
- namespace.yaml
namespace: app-test
patchesStrategicMerge:
- secret.yaml
- configmap.yaml
Run Code Online (Sandbox Code Playgroud)

但是当我运行命令时出现以下错误 - kustomize build k8s/kustomize/overlay/test

2020/02/19 16:04:36 got file 'deployment.yaml', but 'path/k8s/kustomize/base/deployment.yaml' must be a directory to be a root
Error: accumulating resources: accumulating resources from '../../base/deployment.yaml': security; file 'path/k8s/kustomize/base/deployment.yaml' is not in or below 'path/k8s/kustomize/overlay/test'

Run Code Online (Sandbox Code Playgroud)
P.S: kustomize version is - Version: {KustomizeVersion:3.2.0 GitCommit:a3103f1e62ddb5b696daa3fd359bb6f2e8333b49 BuildDate:2019-09-18T18:31:04+01:00 GoOs:darwin GoArch:amd64}
Run Code Online (Sandbox Code Playgroud)

我是 kubernetes 和 kustomize 的新手。请帮帮我好吗?

ITC*_*hap 23

Kustomize 不允许您直接包含不在 kustomization.yml 文件所在目录或子目录中的资源文件。

在覆盖层中使用基础的常用方法是在基础中添加 kustomization.yml 文件,并将基础目录包含在覆盖层的 kustomization.yml 中。例如:

k8s/kustomize/base/kustomization.yaml:

resources:
- deployment.yaml
- service.yaml
- configmap.yaml
- secret.yaml
Run Code Online (Sandbox Code Playgroud)

并在k8s/kustomize/overlays/test/kustomization.yaml

resources:
- ../../base
- namespace.yaml

namespace: app-test

commonLabels:
  variant: test
  app: test-app

patchesStrategicMerge:
- secret.yaml
- configmap.yaml
Run Code Online (Sandbox Code Playgroud)