Describe resources required exclusively in environments with Kustomize's Component
kubernetesI tried to run a DB only in the local environment with Kustomize, but an error occurred as follows.
kustomizeでkubernetesのmanifestを環境ごとに生成する - sambaiz-net
$ tree manifest
manifest
├── base
│ ├── app.yaml
│ └── kustomization.yaml
└── local
├── kustomization.yaml
├── local_db_deployment.yaml
└── local_db_service.yaml
$ cat manifest/local/kustomization.yaml
apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization
resources:
- ../base
patches:
- path: local_db_deployment.yaml
- path: local_db_service.yaml
$ kubectl kustomize manifest/local
error: no matches for Id Deployment.v1.apps/local-db-deployment.[noNs]; failed to find unique target for patch Deployment.v1.apps/local-db-deployment.[noNs]
make: *** [kustomize] Error 1
patches can’t add resources that are not included in the base manifest, so you need to use Component instead. Also Component can be patched.
$ tree manifest
manifest
├── base
│ ├── app.yaml
│ └── kustomization.yaml
├── components
│ └── db
│ ├── db.yaml
│ └── kustomization.yaml
└── overlays
└── local
└── kustomization.yaml
$ cat manifest/components/db/kustomization.yaml
apiVersion: kustomize.config.k8s.io/v1alpha1
kind: Component
resources:
- db.yaml
$ cat manifest/overlays/local/kustomization.yaml
apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization
resources:
- ../../base
components:
- ../../components/db
$ kubectl apply -k manifest/overlays/local
service/mysql created
deployment.apps/local-db-deployment created
deployment.apps/testapp-deployment created