@@ -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.
@@ -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,7 +107,7 @@ 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,
110
+ that manage sensitive data . For example, a service that Pods access over HTTPS,
139
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
@@ -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
The basic authentication Secret type is provided only for convenience.
384
327
You can create an ` Opaque ` type for credentials used for basic authentication.
@@ -397,17 +340,7 @@ as the SSH credential to use.
397
340
The following manifest is an example of a Secret used for SSH public/private
398
341
key authentication:
399
342
400
- ` ` ` yaml
401
- apiVersion: v1
402
- kind: Secret
403
- metadata:
404
- name: secret-ssh-auth
405
- type: kubernetes.io/ssh-auth
406
- data:
407
- # the data is abbreviated in this example
408
- ssh-privatekey: |
409
- MIIEpQIBAAKCAQEAulqb/Y ...
410
- ` ` `
343
+ {{% code language="yaml" file="secret/ssh-auth-secret.yaml" %}}
411
344
412
345
The SSH authentication Secret type is provided only for convenience.
413
346
You can create an ` Opaque ` type for credentials used for SSH authentication.
@@ -440,21 +373,7 @@ the base64 encoded certificate and private key. For details, see
440
373
441
374
The following YAML contains an example config for a TLS Secret:
442
375
443
- ` ` ` yaml
444
- apiVersion: v1
445
- kind: Secret
446
- metadata:
447
- name: secret-tls
448
- type: kubernetes.io/tls
449
- stringData:
450
- # the data is abbreviated in this example
451
- tls.crt: |
452
- --------BEGIN CERTIFICATE-----
453
- MIIC2DCCAcCgAwIBAgIBATANBgkqh ...
454
- tls.key: |
455
- -----BEGIN RSA PRIVATE KEY-----
456
- MIIEpgIBAAKCAQEA7yn3bRHQ5FHMQ ...
457
- ` ` `
376
+ {{% code language="yaml" file="secret/tls-auth-secret.yaml" %}}
458
377
459
378
The TLS Secret type is provided only for convenience.
460
379
You can create an ` Opaque ` type for credentials used for TLS authentication.
@@ -486,21 +405,7 @@ string of the token ID.
486
405
As a Kubernetes manifest, a bootstrap token Secret might look like the
487
406
following:
488
407
489
- ` ` ` yaml
490
- apiVersion: v1
491
- kind: Secret
492
- metadata:
493
- name: bootstrap-token-5emitj
494
- namespace: kube-system
495
- type: bootstrap.kubernetes.io/token
496
- data:
497
- auth-extra-groups: c3lzdGVtOmJvb3RzdHJhcHBlcnM6a3ViZWFkbTpkZWZhdWx0LW5vZGUtdG9rZW4=
498
- expiration: MjAyMC0wOS0xM1QwNDozOToxMFo=
499
- token-id: NWVtaXRq
500
- token-secret: a3E0Z2lodnN6emduMXAwcg==
501
- usage-bootstrap-authentication: dHJ1ZQ==
502
- usage-bootstrap-signing: dHJ1ZQ==
503
- ` ` `
408
+ {{% code language="yaml" file="secret/bootstrap-token-secret-base64.yaml" %}}
504
409
505
410
A bootstrap token Secret has the following keys specified under ` data ` :
506
411
@@ -518,26 +423,7 @@ A bootstrap token Secret has the following keys specified under `data`:
518
423
You can alternatively provide the values in the ` stringData ` field of the Secret
519
424
without base64 encoding them:
520
425
521
- ` ` ` yaml
522
- apiVersion: v1
523
- kind: Secret
524
- metadata:
525
- # Note how the Secret is named
526
- name: bootstrap-token-5emitj
527
- # A bootstrap token Secret usually resides in the kube-system namespace
528
- namespace: kube-system
529
- type: bootstrap.kubernetes.io/token
530
- stringData:
531
- auth-extra-groups: "system:bootstrappers:kubeadm:default-node-token"
532
- expiration: "2020-09-13T04:39:10Z"
533
- # This token ID is used in the name
534
- token-id: "5emitj"
535
- token-secret: "kq4gihvszzgn1p0r"
536
- # This token can be used for authentication
537
- usage-bootstrap-authentication: "true"
538
- # and it can be used for signing
539
- usage-bootstrap-signing: "true"
540
- ` ` `
426
+ {{% code language="yaml" file="secret/bootstrap-token-secret-literal.yaml" %}}
541
427
542
428
## Working with Secrets
543
429
@@ -613,25 +499,7 @@ When you reference a Secret in a Pod, you can mark the Secret as _optional_,
613
499
such as in the following example. If an optional Secret doesn't exist,
614
500
Kubernetes ignores it.
615
501
616
- ` ` ` yaml
617
- apiVersion: v1
618
- kind: Pod
619
- metadata:
620
- name: mypod
621
- spec:
622
- containers:
623
- - name: mypod
624
- image: redis
625
- volumeMounts:
626
- - name: foo
627
- mountPath: "/etc/foo"
628
- readOnly: true
629
- volumes:
630
- - name: foo
631
- secret:
632
- secretName: mysecret
633
- optional: true
634
- ` ` `
502
+ {{% code language="yaml" file="secret/optional-secret.yaml" %}}
635
503
636
504
By default, Secrets are required. None of a Pod's containers will start until
637
505
all non-optional Secrets are available.
0 commit comments