Skip to content

Commit c8ecc08

Browse files
authored
Merge pull request #48805 from iheartNathan/48782-Update-deprecated-fields-in-kustomization-documentation
update deprecated fields in kustomization documentation
2 parents 93f2deb + 5bd6790 commit c8ecc08

File tree

1 file changed

+59
-37
lines changed

1 file changed

+59
-37
lines changed

content/en/docs/tasks/manage-kubernetes-objects/kustomization.md

Lines changed: 59 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -419,8 +419,10 @@ cat <<EOF >./kustomization.yaml
419419
namespace: my-namespace
420420
namePrefix: dev-
421421
nameSuffix: "-001"
422-
commonLabels:
423-
app: bingo
422+
labels:
423+
- pairs:
424+
app: bingo
425+
includeSelectors: true
424426
commonAnnotations:
425427
oncallPager: 800-555-1212
426428
resources:
@@ -520,7 +522,15 @@ The Resources from `kubectl kustomize ./` contain both the Deployment and the Se
520522
#### Customizing
521523

522524
Patches can be used to apply different customizations to Resources. Kustomize supports different patching
523-
mechanisms through `patchesStrategicMerge` and `patchesJson6902`. `patchesStrategicMerge` is a list of file paths. Each file should be resolved to a [strategic merge patch](https://github.com/kubernetes/community/blob/master/contributors/devel/sig-api-machinery/strategic-merge-patch.md). The names inside the patches must match Resource names that are already loaded. Small patches that do one thing are recommended. For example, create one patch for increasing the deployment replica number and another patch for setting the memory limit.
525+
mechanisms through `StrategicMerge` and `Json6902` using the `patches` field. `patches` may be a file or
526+
an inline string, targeting a single or multiple resources.
527+
528+
The `patches` field contains a list of patches applied in the order they are specified. The patch target
529+
selects resources by `group`, `version`, `kind`, `name`, `namespace`, `labelSelector` and `annotationSelector`.
530+
531+
Small patches that do one thing are recommended. For example, create one patch for increasing the deployment
532+
replica number and another patch for setting the memory limit. The target resource is matched using `group`, `version`,
533+
`kind`, and `name` fields from the patch file.
524534

525535
```shell
526536
# Create a deployment.yaml file
@@ -575,9 +585,9 @@ EOF
575585
cat <<EOF >./kustomization.yaml
576586
resources:
577587
- deployment.yaml
578-
patchesStrategicMerge:
579-
- increase_replicas.yaml
580-
- set_memory.yaml
588+
patches:
589+
- path: increase_replicas.yaml
590+
- path: set_memory.yaml
581591
EOF
582592
```
583593

@@ -608,11 +618,12 @@ spec:
608618
memory: 512Mi
609619
```
610620

611-
Not all Resources or fields support strategic merge patches. To support modifying arbitrary fields in arbitrary Resources,
612-
Kustomize offers applying [JSON patch](https://tools.ietf.org/html/rfc6902) through `patchesJson6902`.
613-
To find the correct Resource for a Json patch, the group, version, kind and name of that Resource need to be
614-
specified in `kustomization.yaml`. For example, increasing the replica number of a Deployment object can also be done
615-
through `patchesJson6902`.
621+
Not all Resources or fields support `strategicMerge` patches. To support modifying arbitrary fields in arbitrary Resources,
622+
Kustomize offers applying [JSON patch](https://tools.ietf.org/html/rfc6902) through `Json6902`.
623+
To find the correct Resource for a `Json6902` patch, it is mandatory to specify the `target` field in `kustomization.yaml`.
624+
625+
For example, increasing the replica number of a Deployment object can also be done through `Json6902` patch. The target resource
626+
is matched using `group`, `version`, `kind`, and `name` from the `target` field.
616627

617628
```shell
618629
# Create a deployment.yaml file
@@ -650,7 +661,7 @@ cat <<EOF >./kustomization.yaml
650661
resources:
651662
- deployment.yaml
652663
653-
patchesJson6902:
664+
patches:
654665
- target:
655666
group: apps
656667
version: v1
@@ -685,7 +696,8 @@ spec:
685696
```
686697

687698
In addition to patches, Kustomize also offers customizing container images or injecting field values from other objects into containers
688-
without creating patches. For example, you can change the image used inside containers by specifying the new image in `images` field in `kustomization.yaml`.
699+
without creating patches. For example, you can change the image used inside containers by specifying the new image in the `images` field
700+
in `kustomization.yaml`.
689701

690702
```shell
691703
cat <<EOF > deployment.yaml
@@ -745,7 +757,8 @@ spec:
745757
Sometimes, the application running in a Pod may need to use configuration values from other objects. For example,
746758
a Pod from a Deployment object need to read the corresponding Service name from Env or as a command argument.
747759
Since the Service name may change as `namePrefix` or `nameSuffix` is added in the `kustomization.yaml` file. It is
748-
not recommended to hard code the Service name in the command argument. For this usage, Kustomize can inject the Service name into containers through `vars`.
760+
not recommended to hard code the Service name in the command argument. For this usage, Kustomize can inject
761+
the Service name into containers through `replacements`.
749762

750763
```shell
751764
# Create a deployment.yaml file (quoting the here doc delimiter)
@@ -767,7 +780,7 @@ spec:
767780
containers:
768781
- name: my-nginx
769782
image: nginx
770-
command: ["start", "--host", "$(MY_SERVICE_NAME)"]
783+
command: ["start", "--host", "MY_SERVICE_NAME_PLACEHOLDER"]
771784
EOF
772785
773786
# Create a service.yaml file
@@ -794,12 +807,17 @@ resources:
794807
- deployment.yaml
795808
- service.yaml
796809
797-
vars:
798-
- name: MY_SERVICE_NAME
799-
objref:
810+
replacements:
811+
- source:
800812
kind: Service
801813
name: my-nginx
802-
apiVersion: v1
814+
fieldPath: metadata.name
815+
targets:
816+
- select:
817+
kind: Deployment
818+
name: my-nginx
819+
fieldPaths:
820+
- spec.template.spec.containers.0.command.2
803821
EOF
804822
```
805823

@@ -835,8 +853,10 @@ Kustomize has the concepts of **bases** and **overlays**. A **base** is a direct
835853
set of resources and associated customization. A base could be either a local directory or a directory from a remote repo,
836854
as long as a `kustomization.yaml` is present inside. An **overlay** is a directory with a `kustomization.yaml` that refers to other
837855
kustomization directories as its `bases`. A **base** has no knowledge of an overlay and can be used in multiple overlays.
838-
An overlay may have multiple bases and it composes all resources
839-
from bases and may also have customization on top of them.
856+
857+
The `kustomization.yaml` in a **overlay** directory may refer to multiple `bases`, combining all the resources defined
858+
in these bases into a unified configuration. Additionally, it can apply customizations on top of these resources to meet specific
859+
requirements.
840860

841861
Here is an example of a base:
842862

@@ -944,8 +964,10 @@ EOF
944964
# Create a kustomization.yaml
945965
cat <<EOF >./kustomization.yaml
946966
namePrefix: dev-
947-
commonLabels:
948-
app: my-nginx
967+
labels:
968+
- pairs:
969+
app: my-nginx
970+
includeSelectors: true
949971
resources:
950972
- deployment.yaml
951973
EOF
@@ -985,23 +1007,23 @@ deployment.apps "dev-my-nginx" deleted
9851007

9861008
| Field | Type | Explanation |
9871009
|-----------------------|--------------------------------------------------------------------------------------------------------------|------------------------------------------------------------------------------------|
988-
| namespace | string | add namespace to all resources |
989-
| namePrefix | string | value of this field is prepended to the names of all resources |
990-
| nameSuffix | string | value of this field is appended to the names of all resources |
991-
| commonLabels | map[string]string | labels to add to all resources and selectors |
1010+
| bases | []string | Each entry in this list should resolve to a directory containing a kustomization.yaml file | |
9921011
| commonAnnotations | map[string]string | annotations to add to all resources |
993-
| resources | []string | each entry in this list must resolve to an existing resource configuration file |
994-
| configMapGenerator | [][ConfigMapArgs](https://github.com/kubernetes-sigs/kustomize/blob/master/api/types/configmapargs.go#L7) | Each entry in this list generates a ConfigMap |
995-
| secretGenerator | [][SecretArgs](https://github.com/kubernetes-sigs/kustomize/blob/master/api/types/secretargs.go#L7) | Each entry in this list generates a Secret |
996-
| generatorOptions | [GeneratorOptions](https://github.com/kubernetes-sigs/kustomize/blob/master/api/types/generatoroptions.go#L7) | Modify behaviors of all ConfigMap and Secret generator |
997-
| bases | []string | Each entry in this list should resolve to a directory containing a kustomization.yaml file |
998-
| patchesStrategicMerge | []string | Each entry in this list should resolve a strategic merge patch of a Kubernetes object |
999-
| patchesJson6902 | [][Patch](https://github.com/kubernetes-sigs/kustomize/blob/master/api/types/patch.go#L10) | Each entry in this list should resolve to a Kubernetes object and a Json Patch |
1000-
| vars | [][Var](https://github.com/kubernetes-sigs/kustomize/blob/master/api/types/var.go#L19) | Each entry is to capture text from one resource's field |
1001-
| images | [][Image](https://github.com/kubernetes-sigs/kustomize/blob/master/api/types/image.go#L8) | Each entry is to modify the name, tags and/or digest for one image without creating patches |
1012+
| commonLabels | map[string]string | labels to add to all resources and selectors |
1013+
| configMapGenerator | [][ConfigMapArgs](https://github.com/kubernetes-sigs/kustomize/blob/master/api/types/configmapargs.go#L7) | Each entry in this list generates a ConfigMap
10021014
| configurations | []string | Each entry in this list should resolve to a file containing [Kustomize transformer configurations](https://github.com/kubernetes-sigs/kustomize/tree/master/examples/transformerconfigs) |
10031015
| crds | []string | Each entry in this list should resolve to an OpenAPI definition file for Kubernetes types |
1004-
1016+
| generatorOptions | [GeneratorOptions](https://github.com/kubernetes-sigs/kustomize/blob/master/api/types/generatoroptions.go#L7) | Modify behaviors of all ConfigMap and Secret generator |
1017+
| images | [][Image](https://github.com/kubernetes-sigs/kustomize/blob/master/api/types/image.go#L8) | Each entry is to modify the name, tags and/or digest for one image without creating patches |
1018+
| labels | map[string]string | Add labels without automically injecting corresponding selectors |
1019+
| namePrefix | string | value of this field is prepended to the names of all resources |
1020+
| nameSuffix | string | value of this field is appended to the names of all resources | |
1021+
| patchesJson6902 | [][Patch](https://github.com/kubernetes-sigs/kustomize/blob/master/api/types/patch.go#L10) | Each entry in this list should resolve to a Kubernetes object and a Json Patch | |
1022+
| patchesStrategicMerge | []string | Each entry in this list should resolve a strategic merge patch of a Kubernetes object |
1023+
| replacements | [][Replacements](https://github.com/kubernetes-sigs/kustomize/blob/master/api/types/replacement.go#L15) | copy the value from a resource's field into any number of specified targets.
1024+
| resources | []string | Each entry in this list must resolve to an existing resource configuration file |
1025+
| secretGenerator | [][SecretArgs](https://github.com/kubernetes-sigs/kustomize/blob/master/api/types/secretargs.go#L7) | Each entry in this list generates a Secret |
1026+
| vars | [][Var](https://github.com/kubernetes-sigs/kustomize/blob/master/api/types/var.go#L19) | Each entry is to capture text from one resource's field
10051027

10061028

10071029
## {{% heading "whatsnext" %}}

0 commit comments

Comments
 (0)