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

ibrsph3r  于 2023-10-17  发布在  Kubernetes
关注(0)|答案(3)|浏览(188)

我试图为特定的环境构建清单文件示例:- test,我想重复使用下面提到的基本清单文件。
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

但是当我运行命令- 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'
P.S: kustomize version is - Version: {KustomizeVersion:3.2.0 GitCommit:a3103f1e62ddb5b696daa3fd359bb6f2e8333b49 BuildDate:2019-09-18T18:31:04+01:00 GoOs:darwin GoArch:amd64}

我是Kubernetes和Kustomize的新手。请帮帮我好吗?

1tu0hz3e

1tu0hz3e1#

Kustomize不允许您直接包含不在kustomization.yml文件所在目录或目录下的资源文件。
在覆盖中使用基目录的常用方法是在基目录中添加一个kustomization.yml文件,并在覆盖的kustomization.yml中包含基目录。举例来说:
k8s/kustomize/base/kustomization.yaml

resources:
- deployment.yaml
- service.yaml
- configmap.yaml
- secret.yaml

k8s/kustomize/overlays/test/kustomization.yaml

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

namespace: app-test

commonLabels:
  variant: test
  app: test-app

patchesStrategicMerge:
- secret.yaml
- configmap.yaml
aydmsdu9

aydmsdu92#

也许有些事情会改变,因为下面的例子确实是问题试图做的:https://kubectl.docs.kubernetes.io/references/kustomize/kustomization/resource/

apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization

resources:
- myNamespace.yaml
- sub-dir/some-deployment.yaml
- ../../commonbase
- github.com/kubernetes-sigs/kustomize/examples/multibases?ref=v1.0.6
- deployment.yaml
- github.com/kubernets-sigs/kustomize/examples/helloWorld?ref=test-branch
ttvkxqim

ttvkxqim3#

您可以按以下方式禁用此限制:

kustomize build --load-restrictor LoadRestrictionsNone

相关问题