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
* Update tasks index description
* Create generators folder
* Update tasks/generators titles
* Add rollouts placeholder
* Add generate configmap from file example
* Add literals and env file example
* Add propogation example
* Consistent punctuation
* Update grammar
* Clean up configmaps page
* Remove examples from configMapGenerator ref page
* Move secret examples to Tasks
* Clean up spacing
* Consolidate cm and secret
* Consistent grammar
* Cleanup
* Address feedback
* Bump date
* Fix propagate spelling
* Remove roll out updates section
* Separate configmap and secret generator tasks
* Add secret from file example
* Add secret from literals example
* Update tls secret example
* Update task page weights
* Link cm generator reference
* Add link to secret reference
* Remove secretGenerator example from reference section
* Add configmap options task, clean up reference
* Add file with key example
* Secrets are base64 encoded
Copy file name to clipboardExpand all lines: site/content/en/docs/Reference/API/Kustomization File/configMapGenerator.md
-351Lines changed: 0 additions & 351 deletions
Original file line number
Diff line number
Diff line change
@@ -6,354 +6,3 @@ weight: 6
6
6
description: >
7
7
Generate ConfigMap resources.
8
8
---
9
-
10
-
Each entry in this list results in the creation of
11
-
one ConfigMap resource (it's a generator of n maps).
12
-
13
-
The example below creates four ConfigMaps:
14
-
15
-
- first, with the names and contents of the given files
16
-
- second, with key/value as data using key/value pairs from files
17
-
- third, also with key/value as data, directly specified using `literals`
18
-
- and a fourth, which sets an annotation and label via `options` for that single ConfigMap
19
-
20
-
Each configMapGenerator item accepts a parameter of
21
-
`behavior: [create|replace|merge]`.
22
-
This allows an overlay to modify or
23
-
replace an existing configMap from the parent.
24
-
25
-
Also, each entry has an `options` field, that has the
26
-
same subfields as the kustomization file's `generatorOptions` field.
27
-
28
-
This `options` field allows one to add labels and/or
29
-
annotations to the generated instance, or to individually
30
-
disable the name suffix hash for that instance.
31
-
Labels and annotations added here will not be overwritten
32
-
by the global options associated with the kustomization
33
-
file `generatorOptions` field. However, due to how
34
-
booleans behave, if the global `generatorOptions` field
35
-
specifies `disableNameSuffixHash: true`, this will
36
-
trump any attempt to locally override it.
37
-
38
-
```yaml
39
-
apiVersion: kustomize.config.k8s.io/v1beta1
40
-
kind: Kustomization
41
-
42
-
# These labels are added to all configmaps and secrets.
43
-
generatorOptions:
44
-
labels:
45
-
fruit: apple
46
-
47
-
configMapGenerator:
48
-
- name: my-java-server-props
49
-
behavior: merge
50
-
files:
51
-
- application.properties
52
-
- more.properties
53
-
- name: my-java-server-env-file-vars
54
-
envs:
55
-
- my-server-env.properties
56
-
- more-server-props.env
57
-
- name: my-java-server-env-vars
58
-
literals:
59
-
- JAVA_HOME=/opt/java/jdk
60
-
- JAVA_TOOL_OPTIONS=-agentlib:hprof
61
-
options:
62
-
disableNameSuffixHash: true
63
-
labels:
64
-
pet: dog
65
-
- name: dashboards
66
-
files:
67
-
- mydashboard.json
68
-
options:
69
-
annotations:
70
-
dashboard: "1"
71
-
labels:
72
-
app.kubernetes.io/name: "app1"
73
-
```
74
-
75
-
It is also possible to
76
-
[define a key](https://kubernetes.io/docs/tasks/configure-pod-container/configure-pod-configmap/#define-the-key-to-use-when-creating-a-configmap-from-a-file)
77
-
to set a name different than the filename.
78
-
79
-
The example below creates a ConfigMap
80
-
with the name of file as `myFileName.ini`
81
-
while the _actual_ filename from which the
82
-
configmap is created is `whatever.ini`.
83
-
84
-
```yaml
85
-
apiVersion: kustomize.config.k8s.io/v1beta1
86
-
kind: Kustomization
87
-
88
-
configMapGenerator:
89
-
- name: app-whatever
90
-
files:
91
-
- myFileName.ini=whatever.ini
92
-
```
93
-
94
-
## ConfigMap `from File`
95
-
96
-
ConfigMap Resources may be generated from files - such as a java `.properties` file. To generate a ConfigMap
97
-
Resource for a file, add an entry to `configMapGenerator` with the filename.
98
-
99
-
**Example:** Generate a ConfigMap with a data item containing the contents of a file.
100
-
101
-
The ConfigMaps will have data values populated from the file contents. The contents of each file will
102
-
appear as a single data item in the ConfigMap keyed by the filename.
103
-
104
-
The example illustrates how you can create ConfigMaps from File using Generators.
105
-
106
-
### File Input
107
-
108
-
```yaml
109
-
# kustomization.yaml
110
-
apiVersion: kustomize.config.k8s.io/v1beta1
111
-
kind: Kustomization
112
-
configMapGenerator:
113
-
- name: my-application-properties
114
-
files:
115
-
- application.properties
116
-
117
-
```
118
-
119
-
```yaml
120
-
# application.properties
121
-
FOO=Bar
122
-
```
123
-
124
-
### Build Output
125
-
126
-
```yaml
127
-
apiVersion: v1
128
-
data:
129
-
application.properties: |-
130
-
FOO=Bar
131
-
kind: ConfigMap
132
-
metadata:
133
-
name: my-application-properties-f7mm6mhf59
134
-
```
135
-
136
-
## ConfigMap `from Literals`
137
-
138
-
ConfigMap Resources may be generated from literal key-value pairs - such as `JAVA_HOME=/opt/java/jdk`.
139
-
To generate a ConfigMap Resource from literal key-value pairs, add an entry to `configMapGenerator` with a
- The key/value pairs inside of the environment file are separated by a `=` sign (left side is the key)
186
-
- The value of each line will appear as a data item in the ConfigMap keyed by its key.
187
-
- Pairs may span a single line only.
188
-
{{< /alert >}}
189
-
190
-
**Example:** Create a ConfigMap with 3 data items generated from an environment file.
191
-
192
-
### File Input
193
-
194
-
```yaml
195
-
# kustomization.yaml
196
-
apiVersion: kustomize.config.k8s.io/v1beta1
197
-
kind: Kustomization
198
-
configMapGenerator:
199
-
- name: tracing-options
200
-
envs:
201
-
- tracing.env
202
-
```
203
-
204
-
```bash
205
-
# tracing.env
206
-
ENABLE_TRACING=true
207
-
SAMPLER_TYPE=probabilistic
208
-
SAMPLER_PARAMETERS=0.1
209
-
```
210
-
211
-
### Build Output
212
-
213
-
```yaml
214
-
apiVersion: v1
215
-
kind: ConfigMap
216
-
metadata:
217
-
# The name has had a suffix applied
218
-
name: tracing-options-6bh8gkdf7k
219
-
# The data has been populated from each literal pair
220
-
data:
221
-
ENABLE_TRACING: "true"
222
-
SAMPLER_TYPE: "probabilistic"
223
-
SAMPLER_PARAMETERS: "0.1"
224
-
```
225
-
226
-
## Overriding Base ConfigMap Values
227
-
228
-
ConfigMap values from bases may be overridden by adding another generator for the ConfigMap
229
-
in the overlay and specifying the `behavior` field. `behavior` may be
230
-
one of:
231
-
* `create` (default value): used to create a new ConfigMap. A name conflict error will be thrown if a ConfigMap with the same name and namespace already exists.
232
-
* `replace`: replace an existing ConfigMap from the base.
233
-
* `merge`: add or update the values in an existing ConfigMap from the base.
234
-
235
-
When updating an existing ConfigMap with the `merge` or `replace` strategies, you must ensure that both the name and namespace match the ConfigMap you're targeting. For example, if the namespace is unspecified in the base, you should not specify it in the overlay. Conversely, if it is specified in the base, you must specify it in the overlay as well. This is true even if the overlay Kustomization includes a namespace, because configMapGenerator runs before the namespace transformer.
236
-
237
-
```yaml
238
-
apiVersion: kustomize.config.k8s.io/v1beta1
239
-
kind: Kustomization
240
-
241
-
namespace: my-new-namespace
242
-
243
-
resources:
244
-
- ../base
245
-
246
-
configMapGenerator:
247
-
- name: existing-name
248
-
namespace: existing-ns # needs to match target ConfigMap from base
249
-
behavior: replace
250
-
literals:
251
-
- ENV=dev
252
-
```
253
-
254
-
{{< alert color="warning" title="Name suffixing with overlay configMapGenerator" >}}
255
-
When using configMapGenerator to override values of an existing ConfigMap, the overlay configMapGenerator does not cause suffixing of the existing ConfigMap's name to occur. To take advantage of name suffixing, use configMapGenerator in the base, and the overlay generator will correctly update the suffix based on the new content.
256
-
{{< /alert >}}
257
-
258
-
## Propagating the Name Suffix
259
-
260
-
Workloads that reference the ConfigMap or Secret will need to know the name of the generated Resource,
261
-
including the suffix. Kustomize takes care of this automatically by identifying
262
-
references to generated ConfigMaps and Secrets, and updating them.
263
-
264
-
In the following example, the generated ConfigMap name will be `my-java-server-env-vars` with a suffix unique to its contents.
265
-
Changes to the contents will change the name suffix, resulting in the creation of a new ConfigMap,
266
-
which Kustomize will transform Workloads to point to.
267
-
268
-
The PodTemplate volume references the ConfigMap by the name specified in the generator (excluding the suffix).
269
-
Kustomize will update the name to include the suffix applied to the ConfigMap name.
270
-
271
-
**Input:** The kustomization.yaml and deployment.yaml files
0 commit comments