Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Kubernetes kustomize command giving error when we specify base manifest files in kustomization.yaml file under resources section

I am trying to build manifest file for specific environment example:- test and I want to re-use base manifest files as mentioned below.

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

But I got below error when I run the command - 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}

I am new to kubernetes and kustomize. Could Please help me ?

like image 736
shivakumar sajjan Avatar asked Feb 19 '20 10:02

shivakumar sajjan


People also ask

What is Kustomization YAML file?

Kustomize is a configuration management solution that leverages layering to preserve the base settings of your applications and components by overlaying declarative yaml artifacts (called patches) that selectively override default settings without actually changing the original files.

What is Kustomization in Kubernetes?

Kustomize is a tool for customizing Kubernetes configurations. It has the following features to manage application configuration files: generating resources from other sources. setting cross-cutting fields for resources. composing and customizing collections of resources.

Is Kustomize built into Kubectl?

Kustomize is built into kubectl , from version 1.14. So, as long as you're using kubectl , there's no need to install or manage Kustomize as a separate dependency. Kustomize is purely declarative. Being a Kubernetes-native tool, Kustomize aligns with the Kubernetes approach to declarative configuration.

What is patchesStrategicMerge in Kustomize?

A kustomization file supports patching in three ways: patchesStrategicMerge: A list of patch files where each file is parsed as a Strategic Merge Patch. patchesJSON6902: A list of patches and associated targets, where each file is parsed as a JSON Patch and can only be applied to one target resource.


2 Answers

Kustomize doesn't allow you to directly include resource files that are not in the same directory or a subdirectory of where your kustomization.yml file is located.

The usual way to use a base in your overlay is to add a kustomization.yml file in the base and include the base directory in the kustomization.yml of your overlay. For example:

k8s/kustomize/base/kustomization.yaml:

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

and in k8s/kustomize/overlays/test/kustomization.yaml:

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

namespace: app-test

commonLabels:
  variant: test
  app: test-app

patchesStrategicMerge:
- secret.yaml
- configmap.yaml
like image 113
ITChap Avatar answered Oct 19 '22 14:10

ITChap


Maybe something change because the following example does that the question was trying to do: 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
like image 25
Sebastien Tardif Avatar answered Oct 19 '22 13:10

Sebastien Tardif