liveBook · Manning

Kustomize patch

As explained in Acing the Certified Kubernetes Administrator Exam, Second Edition

A Kustomize patch is a declarative transformation that changes selected fields of a Kubernetes resource without replacing its complete base manifest.

A Kustomize patch declaratively changes selected fields in a Kubernetes manifest while preserving the reusable base. Overlays use patches to adapt configurations for environments such as staging without duplicating complete YAML files. section 5.3.2

Change staging replicas

Keep Deployment and Service definitions in a base, then target the my-app Deployment from overlays/staging and replace /spec/replicas with 3. Apply the result with kubectl apply -k overlays/staging/ and verify it with kubectl get deploy. section 5.3.2

resources:
- ../../base

patches:
- target:
    kind: Deployment
    name: my-app
  patch: |-
    - op: replace
      path: /spec/replicas
      value: 3

Inspect the overlay structure: reference the base, select the Deployment by kind and name, and apply a JSON-style replacement patch. section 5.3.2

Preview generated objects without applying them by running kubectl kustomize overlays/staging/. Removing an object from Kustomize does not automatically remove that object from the cluster. section 5.3.2

How Acing the Certified Kubernetes Administrator Exam, Second Edition covers it

How deep it goes
Demonstrates targeted replica replacement, application, verification, preview, and removed-object behavior without deeper patch mechanics.
Examples
Uses a staging overlay that changes the my-app Deployment from one replica to three without editing the base YAML.
What it assumes
Assumes familiarity with Kubernetes Deployments, Services, YAML manifests, kubectl, and base-overlay directory structures.
What you can do after
Apply it via kubectl, preview generated objects, and verify the resulting Deployment replica count.
How it connects
Connects Kubernetes manifests, Kustomize overlays, kubectl apply, kubectl kustomize, and Helm template.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Acing the Certified Kubernetes Administrator Exam, Second Edition. The section links point to the parts of the book it draws on.