Skip to content

Commit 92baacc

Browse files
authored
Merge pull request #42550 from shannonxtreme/secrets-cleanup
Fix Secret capitalization and use code shortcode
2 parents 5e8fd48 + cc62cbf commit 92baacc

10 files changed

+161
-156
lines changed

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

Lines changed: 24 additions & 156 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ content_type: concept
66
feature:
77
title: Secret and configuration management
88
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.
1111
weight: 30
1212
---
1313

@@ -24,7 +24,7 @@ Because Secrets can be created independently of the Pods that use them, there
2424
is less risk of the Secret (and its data) being exposed during the workflow of
2525
creating, viewing, and editing Pods. Kubernetes, and applications that run in
2626
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.
2828

2929
Secrets are similar to {{< glossary_tooltip text="ConfigMaps" term_id="configmap" >}}
3030
but are specifically intended to hold confidential data.
@@ -68,7 +68,7 @@ help automate node registration.
6868
### Use case: dotfiles in a secret volume
6969

7070
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
7272
is mounted into a volume, `secret-volume`, the volume will contain a single file,
7373
called `.secret-file`, and the `dotfile-test-container` will have this file
7474
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`;
7878
you must use `ls -la` to see them when listing directory contents.
7979
{{< /note >}}
8080

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" %}}
11082

11183
### Use case: Secret visible to one container in a Pod
11284

@@ -135,8 +107,8 @@ Here are some of your options:
135107
[ServiceAccount](/docs/reference/access-authn-authz/authentication/#service-account-tokens)
136108
and its tokens to identify your client.
137109
- 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
140112
token).
141113
- For authentication, you can implement a custom signer for X.509 certificates, and use
142114
[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
251223

252224
The following example configuration declares a ServiceAccount token Secret:
253225

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" %}}
266227

267228
After creating the Secret, wait for Kubernetes to populate the `token` key in the `data` field.
268229

@@ -290,16 +251,7 @@ you must use one of the following `type` values for that Secret:
290251

291252
Below is an example for a `kubernetes.io/dockercfg` type of Secret:
292253

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" %}}
303255

304256
{{< note >}}
305257
If you do not want to perform the base64 encoding, you can choose to use the
@@ -369,16 +321,7 @@ Secret manifest.
369321

370322
The following manifest is an example of a basic authentication Secret:
371323

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" %}}
382325

383326
{{< note >}}
384327
The `stringData` field for a Secret does not work well with server-side apply.
@@ -401,17 +344,7 @@ as the SSH credential to use.
401344
The following manifest is an example of a Secret used for SSH public/private
402345
key authentication:
403346

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" %}}
415348

416349
The SSH authentication Secret type is provided only for convenience.
417350
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
444377

445378
The following YAML contains an example config for a TLS Secret:
446379

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" %}}
462381

463382
The TLS Secret type is provided only for convenience.
464383
You can create an `Opaque` type for credentials used for TLS authentication.
@@ -490,26 +409,12 @@ string of the token ID.
490409
As a Kubernetes manifest, a bootstrap token Secret might look like the
491410
following:
492411

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" %}}
508413

509414
A bootstrap token Secret has the following keys specified under `data`:
510415

511416
- `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.
513418
- `description`: A human-readable string that describes what the token is
514419
used for. Optional.
515420
- `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`:
522427
You can alternatively provide the values in the `stringData` field of the Secret
523428
without base64 encoding them:
524429

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" %}}
545431

546432
{{< note >}}
547433
The `stringData` field for a Secret does not work well with server-side apply.
@@ -576,9 +462,9 @@ precedence.
576462

577463
#### Size limit {#restriction-data-size}
578464

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
582468
use a [resource quota](/docs/concepts/policy/resource-quotas/) to limit the
583469
number of Secrets (or other resources) in a namespace.
584470

@@ -621,25 +507,7 @@ When you reference a Secret in a Pod, you can mark the Secret as _optional_,
621507
such as in the following example. If an optional Secret doesn't exist,
622508
Kubernetes ignores it.
623509

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" %}}
643511

644512
By default, Secrets are required. None of a Pod's containers will start until
645513
all non-optional Secrets are available.
@@ -716,17 +584,17 @@ LASTSEEN FIRSTSEEN COUNT NAME KIND SUBOBJECT
716584
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.
717585
```
718586

719-
### Container image pull secrets {#using-imagepullsecrets}
587+
### Container image pull Secrets {#using-imagepullsecrets}
720588

721589
If you want to fetch container images from a private repository, you need a way for
722590
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
724592
level.
725593

726594
#### Using imagePullSecrets
727595

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
730598
password to the kubelet. The kubelet uses this information to pull a private image on behalf of your Pod.
731599
See the [PodSpec API](/docs/reference/generated/kubernetes-api/{{< param "version" >}}/#podspec-v1-core)
732600
for more information about the `imagePullSecrets` field.
@@ -795,7 +663,7 @@ Secrets it expects to interact with, other apps within the same namespace can
795663
render those assumptions invalid.
796664

797665
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`
799667
so that the confidential data is not written to durable storage.
800668
Once the Pod that depends on the Secret is deleted, the kubelet deletes its local copy
801669
of the confidential data from the Secret.
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
apiVersion: v1
2+
kind: Secret
3+
metadata:
4+
name: secret-basic-auth
5+
type: kubernetes.io/basic-auth
6+
stringData:
7+
username: admin # required field for kubernetes.io/basic-auth
8+
password: t0p-Secret # required field for kubernetes.io/basic-auth
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
apiVersion: v1
2+
kind: Secret
3+
metadata:
4+
name: bootstrap-token-5emitj
5+
namespace: kube-system
6+
type: bootstrap.kubernetes.io/token
7+
data:
8+
auth-extra-groups: c3lzdGVtOmJvb3RzdHJhcHBlcnM6a3ViZWFkbTpkZWZhdWx0LW5vZGUtdG9rZW4=
9+
expiration: MjAyMC0wOS0xM1QwNDozOToxMFo=
10+
token-id: NWVtaXRq
11+
token-secret: a3E0Z2lodnN6emduMXAwcg==
12+
usage-bootstrap-authentication: dHJ1ZQ==
13+
usage-bootstrap-signing: dHJ1ZQ==
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
apiVersion: v1
2+
kind: Secret
3+
metadata:
4+
# Note how the Secret is named
5+
name: bootstrap-token-5emitj
6+
# A bootstrap token Secret usually resides in the kube-system namespace
7+
namespace: kube-system
8+
type: bootstrap.kubernetes.io/token
9+
stringData:
10+
auth-extra-groups: "system:bootstrappers:kubeadm:default-node-token"
11+
expiration: "2020-09-13T04:39:10Z"
12+
# This token ID is used in the name
13+
token-id: "5emitj"
14+
token-secret: "kq4gihvszzgn1p0r"
15+
# This token can be used for authentication
16+
usage-bootstrap-authentication: "true"
17+
# and it can be used for signing
18+
usage-bootstrap-signing: "true"
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
apiVersion: v1
2+
kind: Secret
3+
metadata:
4+
name: secret-dockercfg
5+
type: kubernetes.io/dockercfg
6+
data:
7+
.dockercfg: |
8+
eyJhdXRocyI6eyJodHRwczovL2V4YW1wbGUvdjEvIjp7ImF1dGgiOiJvcGVuc2VzYW1lIn19fQo=
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
apiVersion: v1
2+
kind: Secret
3+
metadata:
4+
name: dotfile-secret
5+
data:
6+
.secret-file: dmFsdWUtMg0KDQo=
7+
---
8+
apiVersion: v1
9+
kind: Pod
10+
metadata:
11+
name: secret-dotfiles-pod
12+
spec:
13+
volumes:
14+
- name: secret-volume
15+
secret:
16+
secretName: dotfile-secret
17+
containers:
18+
- name: dotfile-test-container
19+
image: registry.k8s.io/busybox
20+
command:
21+
- ls
22+
- "-l"
23+
- "/etc/secret-volume"
24+
volumeMounts:
25+
- name: secret-volume
26+
readOnly: true
27+
mountPath: "/etc/secret-volume"

0 commit comments

Comments
 (0)