Add a reusable component

Mix in reusable patches and resources with components: (Kustomize v4+)

cat <<'EOF' >> kustomization.yaml components: - ../../components/monitoring EOF

tool
kustomize23 commands
tags
kustomizegitopsk8s

More kustomize commands

  • cat <<'EOF' >> kustomization.yaml replacements: - source: {kind: ConfigMap, name: cfg, fieldPath: data.host} targets: - select: {kind: Deployment} fieldPaths: [spec.template.spec.containers.0.env.0.value] EOF

    Copy a field from one resource to another; replacements: is the modern way instead of the deprecated vars:

  • cat <<'EOF' >> kustomization.yaml patches: - target: {kind: Deployment, labelSelector: app=api} patch: |- - op: replace path: /spec/replicas value: 3 EOF

    Apply a JSON6902 patch to all matching resources, no separate file needed

  • kustomize edit set image app=registry.example.com/app@sha256:<id>

    Pin the image to an immutable digest; you can also set newName and digest in the images: block

  • cat <<'EOF' >> kustomization.yaml secretGenerator: - name: db-creds literals: [PASSWORD=s3cr3t] generatorOptions: disableNameSuffixHash: true EOF

    disableNameSuffixHash keeps the name stable, but pods no longer roll out when the secret changes

  • cat <<'EOF' >> kustomization.yaml openapi: path: crd-schema.json EOF

    Teach kustomize the merge rules of your CRDs, so patches merge correctly

all 23 kustomize commands