mirror of
https://github.com/kubernetes-sigs/kustomize.git
synced 2026-06-12 01:14:22 +00:00
kustomize.yaml becomes kustomization.yaml
This commit is contained in:
@@ -57,7 +57,7 @@ Expecting something like:
|
|||||||
> └── base
|
> └── base
|
||||||
> ├── configMap.yaml
|
> ├── configMap.yaml
|
||||||
> ├── deployment.yaml
|
> ├── deployment.yaml
|
||||||
> ├── kustomize.yaml
|
> ├── kustomization.yaml
|
||||||
> ├── LICENSE
|
> ├── LICENSE
|
||||||
> ├── README.md
|
> ├── README.md
|
||||||
> └── service.yaml
|
> └── service.yaml
|
||||||
@@ -81,7 +81,7 @@ The `base` directory has a [kustomization] file:
|
|||||||
<!-- @showKustomization @test -->
|
<!-- @showKustomization @test -->
|
||||||
```
|
```
|
||||||
BASE=$DEMO_HOME/base
|
BASE=$DEMO_HOME/base
|
||||||
more $BASE/kustomize.yaml
|
more $BASE/kustomization.yaml
|
||||||
```
|
```
|
||||||
|
|
||||||
Run `kustomize` on the base to emit customized resources
|
Run `kustomize` on the base to emit customized resources
|
||||||
@@ -100,7 +100,7 @@ label_ applied to all resources:
|
|||||||
<!-- @addLabel @test -->
|
<!-- @addLabel @test -->
|
||||||
```
|
```
|
||||||
sed -i 's/app: hello/app: my-hello/' \
|
sed -i 's/app: hello/app: my-hello/' \
|
||||||
$BASE/kustomize.yaml
|
$BASE/kustomization.yaml
|
||||||
```
|
```
|
||||||
|
|
||||||
See the effect:
|
See the effect:
|
||||||
@@ -132,12 +132,12 @@ defining a new name prefix, and some different labels.
|
|||||||
|
|
||||||
<!-- @makeStagingKustomization @test -->
|
<!-- @makeStagingKustomization @test -->
|
||||||
```
|
```
|
||||||
cat <<'EOF' >$OVERLAYS/staging/kustomize.yaml
|
cat <<'EOF' >$OVERLAYS/staging/kustomization.yaml
|
||||||
namePrefix: staging-
|
namePrefix: staging-
|
||||||
labelsToAdd:
|
commonLabels:
|
||||||
instance: staging
|
instance: staging
|
||||||
org: acmeCorporation
|
org: acmeCorporation
|
||||||
annotationsToAdd:
|
commonAnnotations:
|
||||||
note: Hello, I am staging!
|
note: Hello, I am staging!
|
||||||
bases:
|
bases:
|
||||||
- ../../base
|
- ../../base
|
||||||
@@ -173,12 +173,12 @@ with a different name prefix and labels.
|
|||||||
|
|
||||||
<!-- @makeProductionKustomization @test -->
|
<!-- @makeProductionKustomization @test -->
|
||||||
```
|
```
|
||||||
cat <<EOF >$OVERLAYS/production/kustomize.yaml
|
cat <<EOF >$OVERLAYS/production/kustomization.yaml
|
||||||
namePrefix: production-
|
namePrefix: production-
|
||||||
labelsToAdd:
|
commonLabels:
|
||||||
instance: production
|
instance: production
|
||||||
org: acmeCorporation
|
org: acmeCorporation
|
||||||
annotationsToAdd:
|
commonAnnotations:
|
||||||
note: Hello, I am production!
|
note: Hello, I am production!
|
||||||
bases:
|
bases:
|
||||||
- ../../base
|
- ../../base
|
||||||
@@ -231,16 +231,16 @@ Expecting something like:
|
|||||||
> ├── base
|
> ├── base
|
||||||
> │ ├── configMap.yaml
|
> │ ├── configMap.yaml
|
||||||
> │ ├── deployment.yaml
|
> │ ├── deployment.yaml
|
||||||
> │ ├── kustomize.yaml
|
> │ ├── kustomization.yaml
|
||||||
> │ ├── LICENSE
|
> │ ├── LICENSE
|
||||||
> │ ├── README.md
|
> │ ├── README.md
|
||||||
> │ └── service.yaml
|
> │ └── service.yaml
|
||||||
> └── overlays
|
> └── overlays
|
||||||
> ├── production
|
> ├── production
|
||||||
> │ ├── deployment.yaml
|
> │ ├── deployment.yaml
|
||||||
> │ └── kustomize.yaml
|
> │ └── kustomization.yaml
|
||||||
> └── staging
|
> └── staging
|
||||||
> ├── kustomize.yaml
|
> ├── kustomization.yaml
|
||||||
> └── map.yaml
|
> └── map.yaml
|
||||||
> ```
|
> ```
|
||||||
|
|
||||||
@@ -373,7 +373,7 @@ kustomize build $OVERLAYS/staging |\
|
|||||||
|
|
||||||
The configMap name is prefixed by _staging-_, per the
|
The configMap name is prefixed by _staging-_, per the
|
||||||
`namePrefix` field in
|
`namePrefix` field in
|
||||||
`$OVERLAYS/staging/kustomize.yaml`.
|
`$OVERLAYS/staging/kustomization.yaml`.
|
||||||
|
|
||||||
The suffix to the configMap name is generated from a
|
The suffix to the configMap name is generated from a
|
||||||
hash of the maps content - in this case the name suffix
|
hash of the maps content - in this case the name suffix
|
||||||
|
|||||||
@@ -30,16 +30,16 @@ done
|
|||||||
```
|
```
|
||||||
|
|
||||||
|
|
||||||
### Initialize kustomize.yaml
|
### Initialize kustomization.yaml
|
||||||
|
|
||||||
The `kustomize` program gets its instructions from
|
The `kustomize` program gets its instructions from
|
||||||
a file called `kustomize.yaml`.
|
a file called `kustomization.yaml`.
|
||||||
|
|
||||||
Start this file:
|
Start this file:
|
||||||
|
|
||||||
<!-- @kustomizeYaml @test -->
|
<!-- @kustomizeYaml @test -->
|
||||||
```
|
```
|
||||||
touch $DEMO_HOME/kustomize.yaml
|
touch $DEMO_HOME/kustomization.yaml
|
||||||
```
|
```
|
||||||
|
|
||||||
### Add the resources
|
### Add the resources
|
||||||
@@ -52,10 +52,10 @@ kustomize edit add resource secret.yaml
|
|||||||
kustomize edit add resource service.yaml
|
kustomize edit add resource service.yaml
|
||||||
kustomize edit add resource deployment.yaml
|
kustomize edit add resource deployment.yaml
|
||||||
|
|
||||||
cat kustomize.yaml
|
cat kustomization.yaml
|
||||||
```
|
```
|
||||||
|
|
||||||
`kustomize.yaml`'s resources section should contain:
|
`kustomization.yaml`'s resources section should contain:
|
||||||
|
|
||||||
> ```
|
> ```
|
||||||
> resources:
|
> resources:
|
||||||
@@ -76,10 +76,10 @@ cd $DEMO_HOME
|
|||||||
|
|
||||||
kustomize edit set nameprefix 'prod-'
|
kustomize edit set nameprefix 'prod-'
|
||||||
|
|
||||||
cat kustomize.yaml
|
cat kustomization.yaml
|
||||||
```
|
```
|
||||||
|
|
||||||
`kustomize.yaml` should have updated value of namePrefix field:
|
`kustomization.yaml` should have updated value of namePrefix field:
|
||||||
|
|
||||||
> ```
|
> ```
|
||||||
> namePrefix: prod-
|
> namePrefix: prod-
|
||||||
@@ -128,15 +128,13 @@ We want resources in production environment to have
|
|||||||
certain labels so that we can query them by label
|
certain labels so that we can query them by label
|
||||||
selector.
|
selector.
|
||||||
|
|
||||||
`kustomize` does not have `set label` command to add
|
`kustomize` does not have `edit set label` command to add
|
||||||
label, but we can edit `kustomize.yaml` file under
|
a label, but one can always edit `kustomization.yaml` directly:
|
||||||
`prod` directory and add the production labels under
|
|
||||||
`labelsToAdd` fields as highlighted below.
|
|
||||||
|
|
||||||
<!-- @customizeLabels @test -->
|
<!-- @customizeLabels @test -->
|
||||||
```
|
```
|
||||||
sed -i 's/app: helloworld/app: prod/' \
|
sed -i 's/app: helloworld/app: prod/' \
|
||||||
$DEMO_HOME/kustomize.yaml
|
$DEMO_HOME/kustomization.yaml
|
||||||
```
|
```
|
||||||
|
|
||||||
At this point, running `kustomize build` will
|
At this point, running `kustomize build` will
|
||||||
@@ -170,11 +168,11 @@ spec:
|
|||||||
EOF
|
EOF
|
||||||
```
|
```
|
||||||
|
|
||||||
Add the patch file to `kustomize.yaml`:
|
Add the patch file to `kustomization.yaml`:
|
||||||
|
|
||||||
<!-- @specifyPatch @test -->
|
<!-- @specifyPatch @test -->
|
||||||
```
|
```
|
||||||
cat <<'EOF' >> $DEMO_HOME/kustomize.yaml
|
cat <<'EOF' >> $DEMO_HOME/kustomization.yaml
|
||||||
patches:
|
patches:
|
||||||
- persistent-disk.yaml
|
- persistent-disk.yaml
|
||||||
EOF
|
EOF
|
||||||
@@ -187,7 +185,7 @@ Lets break this down:
|
|||||||
in deployment.yaml
|
in deployment.yaml
|
||||||
|
|
||||||
- Then we added `persistent-disk.yaml` to list of
|
- Then we added `persistent-disk.yaml` to list of
|
||||||
`patches` in `kustomize.yaml`. `kustomize build`
|
`patches` in `kustomization.yaml`. `kustomize build`
|
||||||
will apply this patch to the deployment resource with
|
will apply this patch to the deployment resource with
|
||||||
the name `mysql` as defined in the patch.
|
the name `mysql` as defined in the patch.
|
||||||
|
|
||||||
|
|||||||
@@ -31,16 +31,16 @@ for f in service deployment; do \
|
|||||||
done
|
done
|
||||||
```
|
```
|
||||||
|
|
||||||
### Initialize kustomize.yaml
|
### Initialize kustomization.yaml
|
||||||
|
|
||||||
The `kustomize` program gets its instructions from
|
The `kustomize` program gets its instructions from
|
||||||
a file called `kustomize.yaml`.
|
a file called `kustomization.yaml`.
|
||||||
|
|
||||||
Start this file:
|
Start this file:
|
||||||
|
|
||||||
<!-- @kustomizeYaml @test -->
|
<!-- @kustomizeYaml @test -->
|
||||||
```
|
```
|
||||||
touch $DEMO_HOME/kustomize.yaml
|
touch $DEMO_HOME/kustomization.yaml
|
||||||
```
|
```
|
||||||
|
|
||||||
### Add the resources
|
### Add the resources
|
||||||
@@ -52,10 +52,10 @@ cd $DEMO_HOME
|
|||||||
kustomize edit add resource service.yaml
|
kustomize edit add resource service.yaml
|
||||||
kustomize edit add resource deployment.yaml
|
kustomize edit add resource deployment.yaml
|
||||||
|
|
||||||
cat kustomize.yaml
|
cat kustomization.yaml
|
||||||
```
|
```
|
||||||
|
|
||||||
`kustomize.yaml`'s resources section should contain:
|
`kustomization.yaml`'s resources section should contain:
|
||||||
|
|
||||||
> ```
|
> ```
|
||||||
> resources:
|
> resources:
|
||||||
@@ -71,10 +71,10 @@ cd $DEMO_HOME
|
|||||||
wget -q $CONTENT/example-springboot/master/application.properties
|
wget -q $CONTENT/example-springboot/master/application.properties
|
||||||
kustomize edit add configmap demo-configmap --from-file application.properties
|
kustomize edit add configmap demo-configmap --from-file application.properties
|
||||||
|
|
||||||
cat kustomize.yaml
|
cat kustomization.yaml
|
||||||
```
|
```
|
||||||
|
|
||||||
`kustomize.yaml`'s configMapGenerator section should contain:
|
`kustomization.yaml`'s configMapGenerator section should contain:
|
||||||
|
|
||||||
> ```
|
> ```
|
||||||
> configMapGenerator:
|
> configMapGenerator:
|
||||||
@@ -111,7 +111,7 @@ spec:
|
|||||||
value: prod
|
value: prod
|
||||||
EOF
|
EOF
|
||||||
|
|
||||||
cat <<EOF >>$DEMO_HOME/kustomize.yaml
|
cat <<EOF >>$DEMO_HOME/kustomization.yaml
|
||||||
patches:
|
patches:
|
||||||
- patch.yaml
|
- patch.yaml
|
||||||
EOF
|
EOF
|
||||||
@@ -125,10 +125,10 @@ EOF
|
|||||||
|
|
||||||
kustomize edit add configmap demo-configmap --from-file application-prod.properties
|
kustomize edit add configmap demo-configmap --from-file application-prod.properties
|
||||||
|
|
||||||
cat kustomize.yaml
|
cat kustomization.yaml
|
||||||
```
|
```
|
||||||
|
|
||||||
`kustomize.yaml`'s configMapGenerator section should contain:
|
`kustomization.yaml`'s configMapGenerator section should contain:
|
||||||
> ```
|
> ```
|
||||||
> configMapGenerator:
|
> configMapGenerator:
|
||||||
> - files:
|
> - files:
|
||||||
@@ -149,14 +149,14 @@ cd $DEMO_HOME
|
|||||||
|
|
||||||
kustomize edit set nameprefix 'prod-'
|
kustomize edit set nameprefix 'prod-'
|
||||||
|
|
||||||
cat kustomize.yaml
|
cat kustomization.yaml
|
||||||
```
|
```
|
||||||
|
|
||||||
`kustomize.yaml` should have updated value of namePrefix field:
|
`kustomization.yaml` should have updated value of namePrefix field:
|
||||||
|
|
||||||
> ```
|
> ```
|
||||||
> namePrefix: prod-
|
> namePrefix: prod-
|
||||||
> annotationsToAdd:
|
> commonAnnotations:
|
||||||
> note: This is a example annotation
|
> note: This is a example annotation
|
||||||
> ```
|
> ```
|
||||||
|
|
||||||
@@ -204,14 +204,12 @@ certain labels so that we can query them by label
|
|||||||
selector.
|
selector.
|
||||||
|
|
||||||
`kustomize` does not have `edit set label` command to add
|
`kustomize` does not have `edit set label` command to add
|
||||||
label, but we can edit `kustomize.yaml` file under
|
a label, but one can always edit `kustomization.yaml` directly:
|
||||||
`prod` directory and add the production labels under
|
|
||||||
`labelsToAdd` fields as highlighted below.
|
|
||||||
|
|
||||||
<!-- @customizeLabels @test -->
|
<!-- @customizeLabels @test -->
|
||||||
```
|
```
|
||||||
sed -i 's/app: helloworld/app: prod/' \
|
sed -i 's/app: helloworld/app: prod/' \
|
||||||
$DEMO_HOME/kustomize.yaml
|
$DEMO_HOME/kustomization.yaml
|
||||||
```
|
```
|
||||||
|
|
||||||
At this point, running `kustomize build` will
|
At this point, running `kustomize build` will
|
||||||
@@ -301,18 +299,18 @@ The output contains
|
|||||||
|
|
||||||
### Add patches
|
### Add patches
|
||||||
|
|
||||||
Currently `kustomize` doesn't provide a command to add a file as a patch, but we can edit the file `kustomize.yaml` to
|
Currently `kustomize` doesn't provide a command to add a file as a patch, but we can edit the file `kustomization.yaml` to
|
||||||
include this patch.
|
include this patch.
|
||||||
|
|
||||||
<!-- @addPatch @test -->
|
<!-- @addPatch @test -->
|
||||||
```
|
```
|
||||||
mv $DEMO_HOME/kustomize.yaml $DEMO_HOME/tmp.yaml
|
mv $DEMO_HOME/kustomization.yaml $DEMO_HOME/tmp.yaml
|
||||||
|
|
||||||
sed '/patches:$/{N;s/- patch.yaml/- patch.yaml\n- memorylimit_patch.yaml\n- healthcheck_patch.yaml/}' \
|
sed '/patches:$/{N;s/- patch.yaml/- patch.yaml\n- memorylimit_patch.yaml\n- healthcheck_patch.yaml/}' \
|
||||||
$DEMO_HOME/tmp.yaml >& $DEMO_HOME/kustomize.yaml
|
$DEMO_HOME/tmp.yaml >& $DEMO_HOME/kustomization.yaml
|
||||||
```
|
```
|
||||||
|
|
||||||
`kustomize.yaml` should have patches field:
|
`kustomization.yaml` should have patches field:
|
||||||
|
|
||||||
> ```
|
> ```
|
||||||
> patches
|
> patches
|
||||||
|
|||||||
@@ -122,15 +122,16 @@ an [overlay] to a [base].
|
|||||||
|
|
||||||
## kustomization
|
## kustomization
|
||||||
|
|
||||||
A _kustomization_ is a file called `kustomize.yaml` that
|
A _kustomization_ is a file called `kustomization.yaml` that
|
||||||
describes a configuration consumable by [kustomize].
|
describes a configuration consumable by [kustomize].
|
||||||
|
|
||||||
Here's an [example](kustomize.yaml).
|
|
||||||
|
Here's an [example](kustomization.yaml).
|
||||||
|
|
||||||
A kustomization contains fields falling into these categories:
|
A kustomization contains fields falling into these categories:
|
||||||
|
|
||||||
* Immediate customization instructions -
|
* Immediate customization declarations, e.g.
|
||||||
_namePrefix_, _labelsToAdd_, etc.
|
_namePrefix_, _commonLabels_, etc.
|
||||||
* Resource _generators_ for configmaps and secrets.
|
* Resource _generators_ for configmaps and secrets.
|
||||||
* References to _external files_ in these categories:
|
* References to _external files_ in these categories:
|
||||||
* [resources] - completely specified k8s API objects,
|
* [resources] - completely specified k8s API objects,
|
||||||
@@ -166,7 +167,7 @@ E.g. one might create a github repository like this:
|
|||||||
|
|
||||||
> ```
|
> ```
|
||||||
> github.com/username/someapp/
|
> github.com/username/someapp/
|
||||||
> kustomize.yaml
|
> kustomization.yaml
|
||||||
> deployment.yaml
|
> deployment.yaml
|
||||||
> configmap.yaml
|
> configmap.yaml
|
||||||
> README.md
|
> README.md
|
||||||
@@ -252,7 +253,7 @@ The _target_ is the argument to `build`, e.g.:
|
|||||||
|
|
||||||
`$target` must be a path to a directory that
|
`$target` must be a path to a directory that
|
||||||
immediately contains a file called
|
immediately contains a file called
|
||||||
`kustomize.yaml` (i.e. a [kustomization]).
|
`kustomization.yaml` (i.e. a [kustomization]).
|
||||||
|
|
||||||
The target contains, or refers to, all the information
|
The target contains, or refers to, all the information
|
||||||
needed to create customized resources to send to the
|
needed to create customized resources to send to the
|
||||||
|
|||||||
Reference in New Issue
Block a user