@@ -6,8 +6,8 @@ content_type: concept
6
6
feature :
7
7
title : Secret and configuration management
8
8
description : >
9
- Deploy and update secrets and application configuration without rebuilding your image
10
- and without exposing secrets in your stack configuration.
9
+ Deploy and update Secrets and application configuration without rebuilding your image
10
+ and without exposing Secrets in your stack configuration.
11
11
weight : 30
12
12
---
13
13
@@ -24,7 +24,7 @@ Because Secrets can be created independently of the Pods that use them, there
24
24
is less risk of the Secret (and its data) being exposed during the workflow of
25
25
creating, viewing, and editing Pods. Kubernetes, and applications that run in
26
26
your cluster, can also take additional precautions with Secrets, such as avoiding
27
- writing secret data to nonvolatile storage.
27
+ writing sensitive data to nonvolatile storage.
28
28
29
29
Secrets are similar to {{< glossary_tooltip text="ConfigMaps" term_id="configmap" >}}
30
30
but are specifically intended to hold confidential data.
@@ -68,7 +68,7 @@ help automate node registration.
68
68
### Use case: dotfiles in a secret volume
69
69
70
70
You can make your data "hidden" by defining a key that begins with a dot.
71
- This key represents a dotfile or "hidden" file. For example, when the following secret
71
+ This key represents a dotfile or "hidden" file. For example, when the following Secret
72
72
is mounted into a volume, ` secret-volume ` , the volume will contain a single file,
73
73
called ` .secret-file ` , and the ` dotfile-test-container ` will have this file
74
74
present at the path ` /etc/secret-volume/.secret-file ` .
@@ -78,35 +78,7 @@ Files beginning with dot characters are hidden from the output of `ls -l`;
78
78
you must use ` ls -la ` to see them when listing directory contents.
79
79
{{< /note >}}
80
80
81
- ``` yaml
82
- apiVersion : v1
83
- kind : Secret
84
- metadata :
85
- name : dotfile-secret
86
- data :
87
- .secret-file : dmFsdWUtMg0KDQo=
88
- ---
89
- apiVersion : v1
90
- kind : Pod
91
- metadata :
92
- name : secret-dotfiles-pod
93
- spec :
94
- volumes :
95
- - name : secret-volume
96
- secret :
97
- secretName : dotfile-secret
98
- containers :
99
- - name : dotfile-test-container
100
- image : registry.k8s.io/busybox
101
- command :
102
- - ls
103
- - " -l"
104
- - " /etc/secret-volume"
105
- volumeMounts :
106
- - name : secret-volume
107
- readOnly : true
108
- mountPath : " /etc/secret-volume"
109
- ` ` `
81
+ {{% code language="yaml" file="secret/dotfile-secret.yaml" %}}
110
82
111
83
### Use case: Secret visible to one container in a Pod
112
84
@@ -135,8 +107,8 @@ Here are some of your options:
135
107
[ ServiceAccount] ( /docs/reference/access-authn-authz/authentication/#service-account-tokens )
136
108
and its tokens to identify your client.
137
109
- There are third-party tools that you can run, either within or outside your cluster,
138
- that provide secrets management . For example, a service that Pods access over HTTPS,
139
- that reveals a secret if the client correctly authenticates (for example, with a ServiceAccount
110
+ that manage sensitive data . For example, a service that Pods access over HTTPS,
111
+ that reveals a Secret if the client correctly authenticates (for example, with a ServiceAccount
140
112
token).
141
113
- For authentication, you can implement a custom signer for X.509 certificates, and use
142
114
[ CertificateSigningRequests] ( /docs/reference/access-authn-authz/certificate-signing-requests/ )
@@ -251,18 +223,7 @@ fills in some other fields such as the `kubernetes.io/service-account.uid` annot
251
223
252
224
The following example configuration declares a ServiceAccount token Secret:
253
225
254
- ` ` ` yaml
255
- apiVersion: v1
256
- kind: Secret
257
- metadata:
258
- name: secret-sa-sample
259
- annotations:
260
- kubernetes.io/service-account.name: "sa-name"
261
- type: kubernetes.io/service-account-token
262
- data:
263
- # You can include additional key value pairs as you do with Opaque Secrets
264
- extra: YmFyCg==
265
- ` ` `
226
+ {{% code language="yaml" file="secret/serviceaccount-token-secret.yaml" %}}
266
227
267
228
After creating the Secret, wait for Kubernetes to populate the ` token ` key in the ` data ` field.
268
229
@@ -290,16 +251,7 @@ you must use one of the following `type` values for that Secret:
290
251
291
252
Below is an example for a ` kubernetes.io/dockercfg ` type of Secret:
292
253
293
- ` ` ` yaml
294
- apiVersion: v1
295
- kind: Secret
296
- metadata:
297
- name: secret-dockercfg
298
- type: kubernetes.io/dockercfg
299
- data:
300
- .dockercfg: |
301
- "<base64 encoded ~/.dockercfg file>"
302
- ` ` `
254
+ {{% code language="yaml" file="secret/dockercfg-secret.yaml" %}}
303
255
304
256
{{< note >}}
305
257
If you do not want to perform the base64 encoding, you can choose to use the
@@ -369,16 +321,7 @@ Secret manifest.
369
321
370
322
The following manifest is an example of a basic authentication Secret:
371
323
372
- ` ` ` yaml
373
- apiVersion: v1
374
- kind: Secret
375
- metadata:
376
- name: secret-basic-auth
377
- type: kubernetes.io/basic-auth
378
- stringData:
379
- username: admin # required field for kubernetes.io/basic-auth
380
- password: t0p-Secret # required field for kubernetes.io/basic-auth
381
- ` ` `
324
+ {{% code language="yaml" file="secret/basicauth-secret.yaml" %}}
382
325
383
326
{{< note >}}
384
327
The ` stringData ` field for a Secret does not work well with server-side apply.
@@ -401,17 +344,7 @@ as the SSH credential to use.
401
344
The following manifest is an example of a Secret used for SSH public/private
402
345
key authentication:
403
346
404
- ` ` ` yaml
405
- apiVersion: v1
406
- kind: Secret
407
- metadata:
408
- name: secret-ssh-auth
409
- type: kubernetes.io/ssh-auth
410
- data:
411
- # the data is abbreviated in this example
412
- ssh-privatekey: |
413
- MIIEpQIBAAKCAQEAulqb/Y ...
414
- ` ` `
347
+ {{% code language="yaml" file="secret/ssh-auth-secret.yaml" %}}
415
348
416
349
The SSH authentication Secret type is provided only for convenience.
417
350
You can create an ` Opaque ` type for credentials used for SSH authentication.
@@ -444,21 +377,7 @@ the base64 encoded certificate and private key. For details, see
444
377
445
378
The following YAML contains an example config for a TLS Secret:
446
379
447
- ` ` ` yaml
448
- apiVersion: v1
449
- kind: Secret
450
- metadata:
451
- name: secret-tls
452
- type: kubernetes.io/tls
453
- stringData:
454
- # the data is abbreviated in this example
455
- tls.crt: |
456
- --------BEGIN CERTIFICATE-----
457
- MIIC2DCCAcCgAwIBAgIBATANBgkqh ...
458
- tls.key: |
459
- -----BEGIN RSA PRIVATE KEY-----
460
- MIIEpgIBAAKCAQEA7yn3bRHQ5FHMQ ...
461
- ` ` `
380
+ {{% code language="yaml" file="secret/tls-auth-secret.yaml" %}}
462
381
463
382
The TLS Secret type is provided only for convenience.
464
383
You can create an ` Opaque ` type for credentials used for TLS authentication.
@@ -490,26 +409,12 @@ string of the token ID.
490
409
As a Kubernetes manifest, a bootstrap token Secret might look like the
491
410
following:
492
411
493
- ` ` ` yaml
494
- apiVersion: v1
495
- kind: Secret
496
- metadata:
497
- name: bootstrap-token-5emitj
498
- namespace: kube-system
499
- type: bootstrap.kubernetes.io/token
500
- data:
501
- auth-extra-groups: c3lzdGVtOmJvb3RzdHJhcHBlcnM6a3ViZWFkbTpkZWZhdWx0LW5vZGUtdG9rZW4=
502
- expiration: MjAyMC0wOS0xM1QwNDozOToxMFo=
503
- token-id: NWVtaXRq
504
- token-secret: a3E0Z2lodnN6emduMXAwcg==
505
- usage-bootstrap-authentication: dHJ1ZQ==
506
- usage-bootstrap-signing: dHJ1ZQ==
507
- ` ` `
412
+ {{% code language="yaml" file="secret/bootstrap-token-secret-base64.yaml" %}}
508
413
509
414
A bootstrap token Secret has the following keys specified under ` data ` :
510
415
511
416
- ` token-id ` : A random 6 character string as the token identifier. Required.
512
- - `token-secret` : A random 16 character string as the actual token secret . Required.
417
+ - ` token-secret ` : A random 16 character string as the actual token Secret . Required.
513
418
- ` description ` : A human-readable string that describes what the token is
514
419
used for. Optional.
515
420
- ` expiration ` : An absolute UTC time using [ RFC3339] ( https://datatracker.ietf.org/doc/html/rfc3339 ) specifying when the token
@@ -522,26 +427,7 @@ A bootstrap token Secret has the following keys specified under `data`:
522
427
You can alternatively provide the values in the ` stringData ` field of the Secret
523
428
without base64 encoding them:
524
429
525
- ` ` ` yaml
526
- apiVersion: v1
527
- kind: Secret
528
- metadata:
529
- # Note how the Secret is named
530
- name: bootstrap-token-5emitj
531
- # A bootstrap token Secret usually resides in the kube-system namespace
532
- namespace: kube-system
533
- type: bootstrap.kubernetes.io/token
534
- stringData:
535
- auth-extra-groups: "system:bootstrappers:kubeadm:default-node-token"
536
- expiration: "2020-09-13T04:39:10Z"
537
- # This token ID is used in the name
538
- token-id: "5emitj"
539
- token-secret: "kq4gihvszzgn1p0r"
540
- # This token can be used for authentication
541
- usage-bootstrap-authentication: "true"
542
- # and it can be used for signing
543
- usage-bootstrap-signing: "true"
544
- ` ` `
430
+ {{% code language="yaml" file="secret/bootstrap-token-secret-literal.yaml" %}}
545
431
546
432
{{< note >}}
547
433
The ` stringData ` field for a Secret does not work well with server-side apply.
@@ -576,9 +462,9 @@ precedence.
576
462
577
463
#### Size limit {#restriction-data-size}
578
464
579
- Individual secrets are limited to 1MiB in size. This is to discourage creation
580
- of very large secrets that could exhaust the API server and kubelet memory.
581
- However, creation of many smaller secrets could also exhaust memory. You can
465
+ Individual Secrets are limited to 1MiB in size. This is to discourage creation
466
+ of very large Secrets that could exhaust the API server and kubelet memory.
467
+ However, creation of many smaller Secrets could also exhaust memory. You can
582
468
use a [ resource quota] ( /docs/concepts/policy/resource-quotas/ ) to limit the
583
469
number of Secrets (or other resources) in a namespace.
584
470
@@ -621,25 +507,7 @@ When you reference a Secret in a Pod, you can mark the Secret as _optional_,
621
507
such as in the following example. If an optional Secret doesn't exist,
622
508
Kubernetes ignores it.
623
509
624
- ` ` ` yaml
625
- apiVersion: v1
626
- kind: Pod
627
- metadata:
628
- name: mypod
629
- spec:
630
- containers:
631
- - name: mypod
632
- image: redis
633
- volumeMounts:
634
- - name: foo
635
- mountPath: "/etc/foo"
636
- readOnly: true
637
- volumes:
638
- - name: foo
639
- secret:
640
- secretName: mysecret
641
- optional: true
642
- ` ` `
510
+ {{% code language="yaml" file="secret/optional-secret.yaml" %}}
643
511
644
512
By default, Secrets are required. None of a Pod's containers will start until
645
513
all non-optional Secrets are available.
@@ -716,17 +584,17 @@ LASTSEEN FIRSTSEEN COUNT NAME KIND SUBOBJECT
716
584
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.
717
585
```
718
586
719
- # ## Container image pull secrets {#using-imagepullsecrets}
587
+ ### Container image pull Secrets {#using-imagepullsecrets}
720
588
721
589
If you want to fetch container images from a private repository, you need a way for
722
590
the kubelet on each node to authenticate to that repository. You can configure
723
- _image pull secrets_ to make this possible. These secrets are configured at the Pod
591
+ _ image pull Secrets _ to make this possible. These Secrets are configured at the Pod
724
592
level.
725
593
726
594
#### Using imagePullSecrets
727
595
728
- The `imagePullSecrets` field is a list of references to secrets in the same namespace.
729
- You can use an `imagePullSecrets` to pass a secret that contains a Docker (or other) image registry
596
+ The ` imagePullSecrets ` field is a list of references to Secrets in the same namespace.
597
+ You can use an ` imagePullSecrets ` to pass a Secret that contains a Docker (or other) image registry
730
598
password to the kubelet. The kubelet uses this information to pull a private image on behalf of your Pod.
731
599
See the [ PodSpec API] (/docs/reference/generated/kubernetes-api/{{< param "version" >}}/#podspec-v1-core)
732
600
for more information about the ` imagePullSecrets ` field.
@@ -795,7 +663,7 @@ Secrets it expects to interact with, other apps within the same namespace can
795
663
render those assumptions invalid.
796
664
797
665
A Secret is only sent to a node if a Pod on that node requires it.
798
- For mounting secrets into Pods, the kubelet stores a copy of the data into a `tmpfs`
666
+ For mounting Secrets into Pods, the kubelet stores a copy of the data into a `tmpfs`
799
667
so that the confidential data is not written to durable storage.
800
668
Once the Pod that depends on the Secret is deleted, the kubelet deletes its local copy
801
669
of the confidential data from the Secret.
0 commit comments