Kustomize

Deploy a Kustomize directory or overlay from git, choose how overlays map to apps and deployments, and know what the sandbox refuses.

A Kustomize app builds a directory that holds a kustomization.yaml, the way kustomize build would, on the Wardn server. The result is stored as a snapshot and applied by the operator. Nothing runs kubectl apply -k in your cluster. Read Apps first for how apps, sources and renders fit together.

Kustomize has no values. What differs between environments lives in overlays in git, and you choose which overlay an app builds with its Path. That makes the way you map overlays to apps the main decision on this page.

A repository with a base and overlays

kustomization.yaml
deployment.yaml
service.yaml
deploy/overlays/production/kustomization.yaml
apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization
resources:
  - ../../base
patches:
  - path: replicas.yaml
images:
  - name: registry.example.com/shop/web
    newTag: 1.4.2

Wardn gives the renderer the whole repository, not only the app's directory, so an overlay can refer to a base beside it (../../base). It then builds the directory named by Path. Refer to a base by its directory, as above.

Leave namespace: out of the kustomization, or set it to the deployment's namespace. The operator refuses any object that names a different namespace than the deployment's, and puts objects that name none into the deployment's.

Create the app

Create a source whose Path is the directory to build, then an app on it that is Rendered with Kustomize.

Open /apps/new. Under Source choose A new repository, Git repository, paste the URL and set Path to deploy/overlays/production. Under App, name it web-production and choose Kustomize for Rendered with. Choose Create app, then New deployment on the app's page.

The directory needs a file named kustomization.yaml, kustomization.yml or Kustomization; without one the render fails with the directory has no kustomization.yaml.

One app per overlay, or one app with a promoted snapshot

An app has one Path, and every deployment of that app builds it. Kustomize has no per-deployment values, so two environments that need different overlays need two apps. This has a consequence you should choose on purpose.

One app per overlayOne app, one path
Layoutweb-staging on overlays/staging, web-production on overlays/productionweb on a single directory
How production gets a versionEach deployment tracks a branch (or is asked) and renders its own overlay at its own commitProduction takes the exact snapshot staging ran, by promotion
What you tested is what shipsThe same repository state, but rendered separatelyByte for byte, nothing is rendered again
Differences between environmentsIn overlay files, reviewed in gitNone in the manifests. Use Helm values, or keep the differences in the cluster
Good forGenuinely different configuration per environmentThe same manifests everywhere, promoted through stages

Promotion needs both deployments to hold the same apps, so deployments of different overlay apps cannot take each other's snapshots. If you want both a per-environment difference and promotion, render with Helm and set the difference as values (Helm charts). The cookbook recipe Kustomize overlays per environment shows the first layout end to end.

What is refused

The sandbox has no network and runs no programs, so it refuses what would reach outside the repository. The check runs on every kustomization file in the source tree, not only the one being built, so a refused entry in an unrelated directory fails your build too.

In a kustomizationResult
helmCharts, helmGlobalsRefused: render the chart with a Helm app instead.
generators, transformers, validatorsRefused: they run programs or plugins.
A remote entry under resources, bases, components, crds or configurations: a URL, git@host:path, or github.com/org/repoRefused: commit the base into the repository.
An entry that is not in the repositoryRefused with the entry's name.
Files read from outside the directory being builtKustomize's root-only load restriction applies. Refer to other directories as bases or components, not as single files.
Exec and container pluginsDisabled.

Other Kustomize features that work inside the repository are available, for example patches, images, replacements, name prefixes and suffixes, labels and annotations, configMapGenerator, secretGenerator and local components. The images transformer sets a tag, and Wardn then pins that tag to a digest like any other image (Apps).

Secrets in a secretGenerator are in the snapshot

A secretGenerator renders a Secret with its values into the snapshot, like any Secret object you commit. Wardn masks Secret values in diffs, but it stores them. Keep values out of git and refer to a Secret that exists in the cluster, or that External Secrets Operator creates.

Troubleshooting

SymptomCheck
Kustomize cannot build the directory: ...Kustomize's own message. Run kustomize build <path> locally at the same commit.
... names a remote base ... for a path you did not changeAnother kustomization in the repository has a remote entry. Fix or remove it.
The deployment is Held for review with few objectsThe overlay's patches or resources dropped objects. Open the held snapshot to see how many were removed; see Held snapshots.
The apply is refused for a namespaceThe kustomization sets namespace: to something other than the deployment's namespace.

Next

Related: Apps, Sources and apps, Compare snapshots.

On this page