Skip to content

Commit cc62cbf

Browse files
committed
Move YAML snippets to examples directory and include with code shortcode
1 parent f2cfc91 commit cc62cbf

10 files changed

+148
-143
lines changed

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

Lines changed: 11 additions & 143 deletions
Original file line numberDiff line numberDiff line change
@@ -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.
@@ -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,7 +107,7 @@ 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,
110+
that manage sensitive data. For example, a service that Pods access over HTTPS,
139111
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
@@ -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
The basic authentication Secret type is provided only for convenience.
384327
You can create an `Opaque` type for credentials used for basic authentication.
@@ -397,17 +340,7 @@ as the SSH credential to use.
397340
The following manifest is an example of a Secret used for SSH public/private
398341
key authentication:
399342

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

412345
The SSH authentication Secret type is provided only for convenience.
413346
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
440373

441374
The following YAML contains an example config for a TLS Secret:
442375

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

459378
The TLS Secret type is provided only for convenience.
460379
You can create an `Opaque` type for credentials used for TLS authentication.
@@ -486,21 +405,7 @@ string of the token ID.
486405
As a Kubernetes manifest, a bootstrap token Secret might look like the
487406
following:
488407

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

505410
A bootstrap token Secret has the following keys specified under `data`:
506411

@@ -518,26 +423,7 @@ A bootstrap token Secret has the following keys specified under `data`:
518423
You can alternatively provide the values in the `stringData` field of the Secret
519424
without base64 encoding them:
520425

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

542428
## Working with Secrets
543429

@@ -613,25 +499,7 @@ When you reference a Secret in a Pod, you can mark the Secret as _optional_,
613499
such as in the following example. If an optional Secret doesn't exist,
614500
Kubernetes ignores it.
615501

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

636504
By default, Secrets are required. None of a Pod's containers will start until
637505
all non-optional Secrets are available.
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"
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
apiVersion: v1
2+
kind: Pod
3+
metadata:
4+
name: mypod
5+
spec:
6+
containers:
7+
- name: mypod
8+
image: redis
9+
volumeMounts:
10+
- name: foo
11+
mountPath: "/etc/foo"
12+
readOnly: true
13+
volumes:
14+
- name: foo
15+
secret:
16+
secretName: mysecret
17+
optional: true
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
apiVersion: v1
2+
kind: Secret
3+
metadata:
4+
name: secret-sa-sample
5+
annotations:
6+
kubernetes.io/service-account.name: "sa-name"
7+
type: kubernetes.io/service-account-token
8+
data:
9+
extra: YmFyCg==
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
apiVersion: v1
2+
kind: Secret
3+
metadata:
4+
name: secret-ssh-auth
5+
type: kubernetes.io/ssh-auth
6+
data:
7+
# the data is abbreviated in this example
8+
ssh-privatekey: |
9+
UG91cmluZzYlRW1vdGljb24lU2N1YmE=
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
apiVersion: v1
2+
kind: Secret
3+
metadata:
4+
name: secret-tls
5+
type: kubernetes.io/tls
6+
data:
7+
# values are base64 encoded, which obscures them but does NOT provide
8+
# any useful level of confidentiality
9+
tls.crt: |
10+
LS0tLS1CRUdJTiBDRVJUSUZJQ0FURS0tLS0tCk1JSUNVakNDQWJzQ0FnMytNQTBHQ1NxR1NJYjNE
11+
UUVCQlFV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kb3YrcE0vNCs5a1h5aDhSUEkzZXZ6OS9NQT09Ci0tLS0tRU5EIENFUlRJ
25+
RklDQVRFLS0tLS0K
26+
# In this example, the key data is not a real PEM-encoded private key
27+
tls.key: |
28+
RXhhbXBsZSBkYXRhIGZvciB0aGUgVExTIGNydCBmaWVsZA==

0 commit comments

Comments
 (0)