Updating a Key with a JSON 6902 Patch
────────────────────────────────────────────── Assume you have a deployment configuration with a labelcomponent: api that needs to be updated to component: web. First, consider the original deployment configuration:
kustomization.yaml:
The patch uses the “replace” operation to update the existing key at the specified path (
/spec/template/metadata/labels/component) with the new value web.Updating a Key with a Strategic Merge Patch
────────────────────────────────────────────── You can achieve the same update using a strategic merge patch. Instead of including the patch inline, store it in a separate file namedlabel-patch.yaml and reference it in your kustomization.yaml.
In your kustomization.yaml, include:
label-patch.yaml with only the fields that need to be updated:
component label value from api to web.
──────────────────────────────────────────────
Adding a New Key Using a JSON 6902 Patch
────────────────────────────────────────────── Suppose you want to add a new labelorg: KodeKloud to the existing deployment configuration. Consider the following original configuration:
kustomization.yaml:
• The path defines where the new label should be inserted (
/spec/template/metadata/labels/org).• The value
KodeKloud is the new label value.
After applying the patch, the final configuration will include both labels—component: api and org: KodeKloud:
Adding a New Key with a Strategic Merge Patch
────────────────────────────────────────────── To add a new label using a strategic merge patch, reference an external patch file. In yourkustomization.yaml, include:
label-patch.yaml file, specify the new key:
org label.
──────────────────────────────────────────────
Removing a Key Using a JSON 6902 Patch
────────────────────────────────────────────── Consider a deployment that currently has two labels:org: KodeKloud and component: api. Here is the existing configuration:
org label, apply the following JSON 6902 patch:
org label. After merging, only the component: api label remains.
──────────────────────────────────────────────
Removing a Key with a Strategic Merge Patch
────────────────────────────────────────────── With a strategic merge patch, you can remove a key by setting its value tonull. Starting with the same configuration as above, reference an external patch file in your kustomization.yaml:
label-patch.yaml, mark the org label for removal:
org label, leaving only the component: api label in the configuration.
──────────────────────────────────────────────