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
Copy file name to clipboardExpand all lines: content/en/docs/tasks/manage-kubernetes-objects/kustomization.md
+139Lines changed: 139 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -114,6 +114,98 @@ metadata:
114
114
name: example-configmap-2-g2hdhfc6tk
115
115
```
116
116
117
+
To use a generated ConfigMap in a Deployment, reference it by the name of the configMapGenerator. Kustomize will automatically replace this name with the generated name.
118
+
119
+
This is an example deployment that uses a generated ConfigMap:
120
+
121
+
```yaml
122
+
# Create a application.properties file
123
+
cat <<EOF >application.properties
124
+
FOO=Bar
125
+
EOF
126
+
127
+
cat <<EOF >deployment.yaml
128
+
apiVersion: apps/v1
129
+
kind: Deployment
130
+
metadata:
131
+
name: my-app
132
+
labels:
133
+
app: my-app
134
+
spec:
135
+
selector:
136
+
matchLabels:
137
+
app: my-app
138
+
template:
139
+
metadata:
140
+
labels:
141
+
app: my-app
142
+
spec:
143
+
containers:
144
+
- name: app
145
+
image: my-app
146
+
volumeMount:
147
+
- name: config
148
+
mountPath: /config
149
+
volumes:
150
+
- name: config
151
+
configMap:
152
+
name: example-configmap-1
153
+
EOF
154
+
155
+
cat <<EOF >./kustomization.yaml
156
+
resources:
157
+
- deployment.yaml
158
+
configMapGenerator:
159
+
- name: example-configmap-1
160
+
files:
161
+
- application.properties
162
+
EOF
163
+
```
164
+
165
+
Generate the ConfigMap and Deployment:
166
+
167
+
```shell
168
+
kubectl kustomize ./
169
+
```
170
+
171
+
The generated Deployment will refer to the generated ConfigMap by name:
172
+
173
+
```yaml
174
+
apiVersion: v1
175
+
data:
176
+
application.properties: |
177
+
FOO=Bar
178
+
kind: ConfigMap
179
+
metadata:
180
+
name: example-configmap-1-g4hk9g2ff8
181
+
---
182
+
apiVersion: apps/v1
183
+
kind: Deployment
184
+
metadata:
185
+
labels:
186
+
app: my-app
187
+
name: my-app
188
+
spec:
189
+
selector:
190
+
matchLabels:
191
+
app: my-app
192
+
template:
193
+
metadata:
194
+
labels:
195
+
app: my-app
196
+
spec:
197
+
containers:
198
+
- image: my-app
199
+
name: app
200
+
volumeMount:
201
+
- mountPath: /config
202
+
name: config
203
+
volumes:
204
+
- configMap:
205
+
name: example-configmap-1-g4hk9g2ff8
206
+
name: config
207
+
```
208
+
117
209
#### secretGenerator
118
210
119
211
You can generate Secrets from files or literal key-value pairs. To generate a Secret from a file, add an entry to the `files` list in `secretGenerator`. Here is an example of generating a Secret with a data item from a file:
@@ -170,6 +262,53 @@ metadata:
170
262
type: Opaque
171
263
```
172
264
265
+
Like ConfigMaps, generated Secrets can be used in Deployments by refering to the name of the secretGenerator:
266
+
267
+
```shell
268
+
# Create a password.txt file
269
+
cat <<EOF >./password.txt
270
+
username=admin
271
+
password=secret
272
+
EOF
273
+
274
+
cat <<EOF >deployment.yaml
275
+
apiVersion: apps/v1
276
+
kind: Deployment
277
+
metadata:
278
+
name: my-app
279
+
labels:
280
+
app: my-app
281
+
spec:
282
+
selector:
283
+
matchLabels:
284
+
app: my-app
285
+
template:
286
+
metadata:
287
+
labels:
288
+
app: my-app
289
+
spec:
290
+
containers:
291
+
- name: app
292
+
image: my-app
293
+
volumeMount:
294
+
- name: password
295
+
mountPath: /secrets
296
+
volumes:
297
+
- name: password
298
+
secret:
299
+
secretName: example-secret-1
300
+
EOF
301
+
302
+
cat <<EOF >./kustomization.yaml
303
+
resources:
304
+
- deployment.yaml
305
+
secretGenerator:
306
+
- name: example-secret-1
307
+
files:
308
+
- password.txt
309
+
EOF
310
+
```
311
+
173
312
#### generatorOptions
174
313
175
314
The generated ConfigMaps and Secrets have a content hash suffix appended. This ensures that a new ConfigMap or Secret is generated when the contents are changed. To disable the behavior of appending a suffix, one can use `generatorOptions`. Besides that, it is also possible to specify cross-cutting options for generated ConfigMaps and Secrets.
0 commit comments