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
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
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.
277
269
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`.
282
272
283
273
```shell
284
274
kubectl get events
@@ -291,42 +281,6 @@ LASTSEEN FIRSTSEEN COUNT NAME KIND SUBOBJECT
291
281
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.
292
282
```
293
283
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
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
369
323
370
324
## Use cases
371
325
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}
393
327
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).
0 commit comments