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: docs/user-guide/secrets/index.md
+54-20Lines changed: 54 additions & 20 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -214,7 +214,53 @@ You can package many files into one secret, or use many secrets, whichever is co
214
214
215
215
See another example of creating a secret and a pod that consumes that secret in a volume [here](/docs/user-guide/secrets/).
216
216
217
-
##### Consuming Secret Values from Volumes
217
+
**Projection of secret keys to specific paths**
218
+
219
+
We can also control the paths within the volume where Secret keys are projected.
220
+
You can use `spec.volumes[].secret.items` field to change target path of each key:
221
+
222
+
```json
223
+
{
224
+
"apiVersion": "v1",
225
+
"kind": "Pod",
226
+
"metadata": {
227
+
"name": "mypod",
228
+
"namespace": "myns"
229
+
},
230
+
"spec": {
231
+
"containers": [{
232
+
"name": "mypod",
233
+
"image": "redis",
234
+
"volumeMounts": [{
235
+
"name": "foo",
236
+
"mountPath": "/etc/foo",
237
+
"readOnly": true
238
+
}]
239
+
}],
240
+
"volumes": [{
241
+
"name": "foo",
242
+
"secret": {
243
+
"secretName": "mysecret",
244
+
"items": [{
245
+
"key": "username",
246
+
"path": "my-group/my-username"
247
+
}]
248
+
}
249
+
}]
250
+
}
251
+
}
252
+
```
253
+
254
+
What will happen:
255
+
256
+
* `username` secret is stored under `/etc/foo/my-group/my-username` file instead of `/etc/foo/username`.
257
+
* `password` secret is not projected
258
+
259
+
If `spec.volumes[].secret.items` is used, only keys specified in `items` are projected.
260
+
To consume all keys from the secret, all of them must be listed in the `items` field.
261
+
All listed keys must exist in the corresponding secret. Otherwise, the volume is not created.
262
+
263
+
**Consuming Secret Values from Volumes**
218
264
219
265
Inside the container that mounts a secret volume, the secret keys appear as
220
266
files and the secret values are base-64 decoded and stored inside these files.
@@ -234,6 +280,11 @@ $ cat /etc/foo/password
234
280
The program in a container is responsible for reading the secret(s) from the
235
281
files.
236
282
283
+
**Mounted Secrets are updated automatically**
284
+
285
+
When a secret being already consumed in a volume is updated, projected keys are eventually updated as well.
286
+
The update time depends on the kubelet syncing period.
287
+
237
288
#### Using Secrets as Environment Variables
238
289
239
290
To use a secret in an environment variable in a pod:
@@ -267,7 +318,7 @@ spec:
267
318
restartPolicy: Never
268
319
```
269
320
270
-
##### Consuming Secret Values from Environment Variables
321
+
**Consuming Secret Values from Environment Variables**
271
322
272
323
Inside a container that consumes a secret in an environment variables, the secret keys appear as
273
324
normal environment variables containing the base-64 decoded values of the secret data.
@@ -285,7 +336,7 @@ $ echo $SECRET_PASSWORD
285
336
An imagePullSecret is a way to pass a secret that contains a Docker (or other) image registry
286
337
password to the Kubelet so it can pull a private image on behalf of your Pod.
287
338
288
-
##### Manually specifying an imagePullSecret
339
+
**Manually specifying an imagePullSecret**
289
340
290
341
Use of imagePullSecrets is described in the [images documentation](/docs/user-guide/images/#specifying-imagepullsecrets-on-a-pod)
291
342
@@ -338,23 +389,6 @@ reason it is not started yet. Once the secret is fetched, the kubelet will
338
389
create and mount a volume containing it. None of the pod's containers will
339
390
start until all the pod's volumes are mounted.
340
391
341
-
Once the kubelet has started a pod's containers, its secret volumes will not
342
-
change, even if the secret resource is modified. To change the secret used,
343
-
the original pod must be deleted, and a new pod (perhaps with an identical
344
-
`PodSpec`) must be created. Therefore, updating a secret follows the same
345
-
workflow as deploying a new container image. The `kubectl rolling-update`
346
-
command can be used ([man page](/docs/user-guide/kubectl/kubectl_rolling-update)).
347
-
348
-
The [`resourceVersion`](https://github.com/kubernetes/kubernetes/tree/{{page.githubbranch}}/docs/devel/api-conventions.md#concurrency-control-and-consistency)
349
-
of the secret is not specified when it is referenced.
350
-
Therefore, if a secret is updated at about the same time as pods are starting,
351
-
then it is not defined which version of the secret will be used for the pod. It
352
-
is not possible currently to check what resource version of a secret object was
353
-
used when a pod was created. It is planned that pods will report this
354
-
information, so that a replication controller restarts ones using an old
355
-
`resourceVersion`. In the interim, if this is a concern, it is recommended to not
356
-
update the data of existing secrets, but to create new ones with distinct names.
0 commit comments