Skip to content

Commit 679d205

Browse files
committed
Clean up wording and remove duplicate content
Trim environment variable content in concept - Remove steps and link to the relevant task - Add a brief intro to task heading Clean up wording about Secrets as env vars - Improve clarity of the list items - Improve clarity of the intro paragraph for invalid vars Delete environment variable use case
1 parent 15e374d commit 679d205

File tree

2 files changed

+57
-126
lines changed

2 files changed

+57
-126
lines changed

content/en/docs/concepts/configuration/secret.md

Lines changed: 42 additions & 121 deletions
Original file line numberDiff line numberDiff line change
@@ -165,15 +165,35 @@ for that Pod, including details of the problem fetching the Secret.
165165

166166
#### Optional Secrets {#restriction-secret-must-exist}
167167

168-
When you define a container environment variable based on a Secret,
169-
you can mark it as _optional_. The default is for the Secret to be
170-
required.
168+
When you reference a Secret in a Pod, you can mark the Secret as _optional_,
169+
such as in the following example. If an optional Secret doesn't exist,
170+
Kubernetes ignores it.
171171

172-
None of a Pod's containers will start until all non-optional Secrets are
173-
available.
172+
```yaml
173+
apiVersion: v1
174+
kind: Pod
175+
metadata:
176+
name: mypod
177+
spec:
178+
containers:
179+
- name: mypod
180+
image: redis
181+
volumeMounts:
182+
- name: foo
183+
mountPath: "/etc/foo"
184+
readOnly: true
185+
volumes:
186+
- name: foo
187+
secret:
188+
secretName: mysecret
189+
optional: true
190+
```
191+
192+
By default, Secrets are required. None of a Pod's containers will start until
193+
all non-optional Secrets are available.
174194
175-
If a Pod references a specific key in a Secret and that Secret does exist, but
176-
is missing the named key, the Pod fails during startup.
195+
If a Pod references a specific key in a non-optional Secret and that Secret
196+
does exist, but is missing the named key, the Pod fails during startup.
177197
178198
### Using Secrets as files from a Pod {#using-secrets-as-files-from-a-pod}
179199
@@ -232,53 +252,23 @@ watch propagation delay, the configured cache TTL, or zero for direct polling).
232252
To use a Secret in an {{< glossary_tooltip text="environment variable" term_id="container-env-variables" >}}
233253
in a Pod:
234254

235-
1. Create a Secret (or use an existing one). Multiple Pods can reference the same Secret.
236-
1. Modify your Pod definition in each container that you wish to consume the value of a secret
237-
key to add an environment variable for each secret key you wish to consume. The environment
238-
variable that consumes the secret key should populate the secret's name and key in `env[].valueFrom.secretKeyRef`.
239-
1. Modify your image and/or command line so that the program looks for values in the specified
240-
environment variables.
241-
242-
This is an example of a Pod that uses a Secret via environment variables:
243-
244-
```yaml
245-
apiVersion: v1
246-
kind: Pod
247-
metadata:
248-
name: secret-env-pod
249-
spec:
250-
containers:
251-
- name: mycontainer
252-
image: redis
253-
env:
254-
- name: SECRET_USERNAME
255-
valueFrom:
256-
secretKeyRef:
257-
name: mysecret
258-
key: username
259-
optional: false # same as default; "mysecret" must exist
260-
# and include a key named "username"
261-
- name: SECRET_PASSWORD
262-
valueFrom:
263-
secretKeyRef:
264-
name: mysecret
265-
key: password
266-
optional: false # same as default; "mysecret" must exist
267-
# and include a key named "password"
268-
restartPolicy: Never
269-
```
255+
1. For each container in your Pod specification, add an environment variable
256+
for each Secret key that you want to use to the
257+
`env[].valueFrom.secretKeyRef` field.
258+
1. Modify your image and/or command line so that the program looks for values
259+
in the specified environment variables.
270260

261+
For instructions, refer to
262+
[Define container environment variables using Secret data](/docs/tasks/inject-data-application/distribute-credentials-secure/#define-container-environment-variables-using-secret-data).
271263

272264
#### Invalid environment variables {#restriction-env-from-invalid}
273265

274-
Secrets used to populate environment variables by the `envFrom` field that have keys
275-
that are considered invalid environment variable names will have those keys
276-
skipped. The Pod is allowed to start.
266+
If your environment variable definitions in your Pod specification are
267+
considered to be invalid environment variable names, those keys aren't made
268+
available to your container. The Pod is allowed to start.
277269

278-
If you define a Pod with an invalid variable name, the failed Pod startup includes
279-
an event with the reason set to `InvalidVariableNames` and a message that lists the
280-
skipped invalid keys. The following example shows a Pod that refers to a Secret
281-
named `mysecret`, where `mysecret` contains 2 invalid keys: `1badkey` and `2alsobad`.
270+
Kubernetes adds an Event with the reason set to `InvalidVariableNames` and a
271+
message that lists the skipped invalid keys. The following example shows a Pod that refers to a Secret named `mysecret`, where `mysecret` contains 2 invalid keys: `1badkey` and `2alsobad`.
282272

283273
```shell
284274
kubectl get events
@@ -291,42 +281,6 @@ LASTSEEN FIRSTSEEN COUNT NAME KIND SUBOBJECT
291281
0s 0s 1 dapi-test-pod Pod Warning InvalidEnvironmentVariableNames kubelet, 127.0.0.1 Keys [1badkey, 2alsobad] from the EnvFrom secret default/mysecret were skipped since they are considered invalid environment variable names.
292282
```
293283

294-
295-
#### Consuming Secret values from environment variables
296-
297-
Inside a container that consumes a Secret using environment variables, the secret keys appear
298-
as normal environment variables. The values of those variables are the base64 decoded values
299-
of the secret data.
300-
301-
This is the result of commands executed inside the container from the example above:
302-
303-
```shell
304-
echo "$SECRET_USERNAME"
305-
```
306-
307-
The output is similar to:
308-
309-
```
310-
admin
311-
```
312-
313-
```shell
314-
echo "$SECRET_PASSWORD"
315-
```
316-
317-
The output is similar to:
318-
319-
```
320-
1f2d1e2e67df
321-
```
322-
323-
{{< note >}}
324-
If a container already consumes a Secret in an environment variable,
325-
a Secret update will not be seen by the container unless it is
326-
restarted. There are third party solutions for triggering restarts when
327-
secrets change.
328-
{{< /note >}}
329-
330284
### Container image pull secrets {#using-imagepullsecrets}
331285

332286
If you want to fetch container images from a private repository, you need a way for
@@ -369,43 +323,10 @@ You cannot use ConfigMaps or Secrets with {{< glossary_tooltip text="static Pods
369323

370324
## Use cases
371325

372-
### Use case: As container environment variables
373-
374-
Create a secret
375-
```yaml
376-
apiVersion: v1
377-
kind: Secret
378-
metadata:
379-
name: mysecret
380-
type: Opaque
381-
data:
382-
USER_NAME: YWRtaW4=
383-
PASSWORD: MWYyZDFlMmU2N2Rm
384-
```
385-
386-
Create the Secret:
387-
```shell
388-
kubectl apply -f mysecret.yaml
389-
```
390-
391-
Use `envFrom` to define all of the Secret's data as container environment variables. The key from
392-
the Secret becomes the environment variable name in the Pod.
326+
### Use case: As container environment variables {#use-case-as-container-environment-variables}
393327

394-
```yaml
395-
apiVersion: v1
396-
kind: Pod
397-
metadata:
398-
name: secret-test-pod
399-
spec:
400-
containers:
401-
- name: test-container
402-
image: registry.k8s.io/busybox
403-
command: [ "/bin/sh", "-c", "env" ]
404-
envFrom:
405-
- secretRef:
406-
name: mysecret
407-
restartPolicy: Never
408-
```
328+
You can create a Secret and use it to
329+
[set environment variables for a container](/docs/tasks/inject-data-application/distribute-credentials-secure/#define-container-environment-variables-using-secret-data).
409330

410331
### Use case: Pod with SSH keys
411332

content/en/docs/tasks/inject-data-application/distribute-credentials-secure.md

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,8 @@ following:
199199

200200
You can set the POSIX file access permission bits for a single Secret key.
201201
If you don't specify any permissions, `0644` is used by default.
202-
You can also set a default mode for the entire Secret volume and override per key if needed.
202+
You can also set a default POSIX file mode for the entire Secret volume, and
203+
you can override per key if needed.
203204

204205
For example, you can specify a default mode like this:
205206

@@ -222,18 +223,27 @@ spec:
222223
defaultMode: 0400
223224
```
224225

225-
The secret is mounted on `/etc/foo`; all the files created by the
226+
The Secret is mounted on `/etc/foo`; all the files created by the
226227
secret volume mount have permission `0400`.
227228

228229
{{< note >}}
229230
If you're defining a Pod or a Pod template using JSON, beware that the JSON
230-
specification doesn't support octal notation. You can use the decimal value
231-
for the `defaultMode` (for example, 0400 in octal is 256 in decimal) instead.
232-
If you're writing YAML, you can write the `defaultMode` in octal.
231+
specification doesn't support octal literals for numbers because JSON considers
232+
`0400` to be the _decimal_ value `400`. In JSON, use decimal values for the
233+
`defaultMode` instead. If you're writing YAML, you can write the `defaultMode`
234+
in octal.
233235
{{< /note >}}
234236

235237
## Define container environment variables using Secret data
236238

239+
You can consume the data in Secrets as environment variables in your
240+
containers.
241+
242+
If a container already consumes a Secret in an environment variable,
243+
a Secret update will not be seen by the container unless it is
244+
restarted. There are third party solutions for triggering restarts when
245+
secrets change.
246+
237247
### Define a container environment variable with data from a single Secret
238248

239249
* Define an environment variable as a key-value pair in a Secret:

0 commit comments

Comments
 (0)