Skip to content

Commit dc7255d

Browse files
ncappsantoooks
authored andcommitted
Add Generator Tasks to Documentation (kubernetes-sigs#5368)
* 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
1 parent c1903b7 commit dc7255d

File tree

8 files changed

+519
-467
lines changed

8 files changed

+519
-467
lines changed

site/content/en/docs/Reference/API/Kustomization File/configMapGenerator.md

Lines changed: 0 additions & 351 deletions
Original file line numberDiff line numberDiff line change
@@ -6,354 +6,3 @@ weight: 6
66
description: >
77
Generate ConfigMap resources.
88
---
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
140-
list of `literals`.
141-
142-
{{< alert color="success" title="Literal Syntax" >}}
143-
- The key/value are separated by a `=` sign (left side is the key)
144-
- The value of each literal will appear as a data item in the ConfigMap keyed by its key.
145-
{{< /alert >}}
146-
147-
**Example:** Create a ConfigMap with 2 data items generated from literals.
148-
149-
The example illustrates how you can create ConfigMaps from Literals using Generators.
150-
151-
### File Input
152-
153-
```yaml
154-
# kustomization.yaml
155-
apiVersion: kustomize.config.k8s.io/v1beta1
156-
kind: Kustomization
157-
configMapGenerator:
158-
- name: my-java-server-env-vars
159-
literals:
160-
- JAVA_HOME=/opt/java/jdk
161-
- JAVA_TOOL_OPTIONS=-agentlib:hprof
162-
163-
```
164-
165-
### Build Output
166-
167-
```yaml
168-
apiVersion: v1
169-
data:
170-
JAVA_HOME: /opt/java/jdk
171-
JAVA_TOOL_OPTIONS: -agentlib:hprof
172-
kind: ConfigMap
173-
metadata:
174-
name: my-java-server-env-vars-44k658k8gk
175-
```
176-
177-
## ConfigMap `from env file`
178-
179-
ConfigMap Resources may be generated from key-value pairs much the same as using the literals option
180-
but taking the key-value pairs from an environment file. These generally end in `.env`.
181-
To generate a ConfigMap Resource from an environment file, add an entry to `configMapGenerator` with a
182-
single `envs` entry, e.g. `envs: [ 'config.env' ]`.
183-
184-
{{< alert color="success" title="Environment File Syntax" >}}
185-
- 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
272-
273-
```yaml
274-
# kustomization.yaml
275-
apiVersion: kustomize.config.k8s.io/v1beta1
276-
kind: Kustomization
277-
configMapGenerator:
278-
- name: my-java-server-env-vars
279-
literals:
280-
- JAVA_HOME=/opt/java/jdk
281-
- JAVA_TOOL_OPTIONS=-agentlib:hprof
282-
resources:
283-
- deployment.yaml
284-
```
285-
286-
```yaml
287-
# deployment.yaml
288-
apiVersion: apps/v1
289-
kind: Deployment
290-
metadata:
291-
name: test-deployment
292-
labels:
293-
app: test
294-
spec:
295-
selector:
296-
matchLabels:
297-
app: test
298-
template:
299-
metadata:
300-
labels:
301-
app: test
302-
spec:
303-
containers:
304-
- name: container
305-
image: registry.k8s.io/busybox
306-
command: [ "/bin/sh", "-c", "ls /etc/config/" ]
307-
volumeMounts:
308-
- name: config-volume
309-
mountPath: /etc/config
310-
volumes:
311-
- name: config-volume
312-
configMap:
313-
name: my-java-server-env-vars
314-
```
315-
316-
**Result:** The output of the Kustomize build.
317-
318-
```yaml
319-
apiVersion: v1
320-
kind: ConfigMap
321-
metadata:
322-
# The name has been updated to include the suffix
323-
name: my-java-server-env-vars-k44mhd6h5f
324-
data:
325-
JAVA_HOME: /opt/java/jdk
326-
JAVA_TOOL_OPTIONS: -agentlib:hprof
327-
---
328-
apiVersion: apps/v1
329-
kind: Deployment
330-
metadata:
331-
labels:
332-
app: test
333-
name: test-deployment
334-
spec:
335-
selector:
336-
matchLabels:
337-
app: test
338-
template:
339-
metadata:
340-
labels:
341-
app: test
342-
spec:
343-
containers:
344-
- command:
345-
- /bin/sh
346-
- -c
347-
- ls /etc/config/
348-
image: registry.k8s.io/busybox
349-
name: container
350-
volumeMounts:
351-
- mountPath: /etc/config
352-
name: config-volume
353-
volumes:
354-
- configMap:
355-
# The name has been updated to include the
356-
# suffix matching the ConfigMap
357-
name: my-java-server-env-vars-k44mhd6h5f
358-
name: config-volume
359-
```

0 commit comments

Comments
 (0)