You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
@@ -520,7 +522,15 @@ The Resources from `kubectl kustomize ./` contain both the Deployment and the Se
520
522
#### Customizing
521
523
522
524
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.
524
534
525
535
```shell
526
536
# Create a deployment.yaml file
@@ -575,9 +585,9 @@ EOF
575
585
cat <<EOF >./kustomization.yaml
576
586
resources:
577
587
- deployment.yaml
578
-
patchesStrategicMerge:
579
-
- increase_replicas.yaml
580
-
- set_memory.yaml
588
+
patches:
589
+
- path: increase_replicas.yaml
590
+
- path: set_memory.yaml
581
591
EOF
582
592
```
583
593
@@ -608,11 +618,12 @@ spec:
608
618
memory: 512Mi
609
619
```
610
620
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.
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`.
689
701
690
702
```shell
691
703
cat <<EOF > deployment.yaml
@@ -745,7 +757,8 @@ spec:
745
757
Sometimes, the application running in a Pod may need to use configuration values from other objects. For example,
746
758
a Pod from a Deployment object need to read the corresponding Service name from Env or as a command argument.
747
759
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`.
749
762
750
763
```shell
751
764
# Create a deployment.yaml file (quoting the here doc delimiter)
| 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 | |
992
1011
| 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
1002
1014
| 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) |
1003
1015
| 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 |
| 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
0 commit comments