Skip to content

Commit bbb9572

Browse files
committed
Move prod-test use case to task page - no content changes
1 parent 5bfb353 commit bbb9572

File tree

2 files changed

+137
-137
lines changed

2 files changed

+137
-137
lines changed

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

Lines changed: 0 additions & 137 deletions
Original file line numberDiff line numberDiff line change
@@ -65,143 +65,6 @@ The Kubernetes control plane also uses Secrets; for example,
6565
[bootstrap token Secrets](#bootstrap-token-secrets) are a mechanism to
6666
help automate node registration.
6767

68-
### Use case: Pods with prod / test credentials
69-
70-
This example illustrates a Pod which consumes a secret containing production credentials and
71-
another Pod which consumes a secret with test environment credentials.
72-
73-
You can create a `kustomization.yaml` with a `secretGenerator` field or run
74-
`kubectl create secret`.
75-
76-
```shell
77-
kubectl create secret generic prod-db-secret --from-literal=username=produser --from-literal=password=Y4nys7f11
78-
```
79-
80-
The output is similar to:
81-
82-
```
83-
secret "prod-db-secret" created
84-
```
85-
86-
You can also create a secret for test environment credentials.
87-
88-
```shell
89-
kubectl create secret generic test-db-secret --from-literal=username=testuser --from-literal=password=iluvtests
90-
```
91-
92-
The output is similar to:
93-
94-
```
95-
secret "test-db-secret" created
96-
```
97-
98-
{{< note >}}
99-
Special characters such as `$`, `\`, `*`, `=`, and `!` will be interpreted by your
100-
[shell](https://en.wikipedia.org/wiki/Shell_(computing)) and require escaping.
101-
102-
In most shells, the easiest way to escape the password is to surround it with single quotes (`'`).
103-
For example, if your actual password is `S!B\*d$zDsb=`, you should execute the command this way:
104-
105-
```shell
106-
kubectl create secret generic dev-db-secret --from-literal=username=devuser --from-literal=password='S!B\*d$zDsb='
107-
```
108-
109-
You do not need to escape special characters in passwords from files (`--from-file`).
110-
{{< /note >}}
111-
112-
Now make the Pods:
113-
114-
```shell
115-
cat <<EOF > pod.yaml
116-
apiVersion: v1
117-
kind: List
118-
items:
119-
- kind: Pod
120-
apiVersion: v1
121-
metadata:
122-
name: prod-db-client-pod
123-
labels:
124-
name: prod-db-client
125-
spec:
126-
volumes:
127-
- name: secret-volume
128-
secret:
129-
secretName: prod-db-secret
130-
containers:
131-
- name: db-client-container
132-
image: myClientImage
133-
volumeMounts:
134-
- name: secret-volume
135-
readOnly: true
136-
mountPath: "/etc/secret-volume"
137-
- kind: Pod
138-
apiVersion: v1
139-
metadata:
140-
name: test-db-client-pod
141-
labels:
142-
name: test-db-client
143-
spec:
144-
volumes:
145-
- name: secret-volume
146-
secret:
147-
secretName: test-db-secret
148-
containers:
149-
- name: db-client-container
150-
image: myClientImage
151-
volumeMounts:
152-
- name: secret-volume
153-
readOnly: true
154-
mountPath: "/etc/secret-volume"
155-
EOF
156-
```
157-
158-
Add the pods to the same `kustomization.yaml`:
159-
160-
```shell
161-
cat <<EOF >> kustomization.yaml
162-
resources:
163-
- pod.yaml
164-
EOF
165-
```
166-
167-
Apply all those objects on the API server by running:
168-
169-
```shell
170-
kubectl apply -k .
171-
```
172-
173-
Both containers will have the following files present on their filesystems with the values
174-
for each container's environment:
175-
176-
```
177-
/etc/secret-volume/username
178-
/etc/secret-volume/password
179-
```
180-
181-
Note how the specs for the two Pods differ only in one field; this facilitates
182-
creating Pods with different capabilities from a common Pod template.
183-
184-
You could further simplify the base Pod specification by using two service accounts:
185-
186-
1. `prod-user` with the `prod-db-secret`
187-
1. `test-user` with the `test-db-secret`
188-
189-
The Pod specification is shortened to:
190-
191-
```yaml
192-
apiVersion: v1
193-
kind: Pod
194-
metadata:
195-
name: prod-db-client-pod
196-
labels:
197-
name: prod-db-client
198-
spec:
199-
serviceAccount: prod-db-client
200-
containers:
201-
- name: db-client-container
202-
image: myClientImage
203-
```
204-
20568
### Use case: dotfiles in a secret volume
20669

20770
You can make your data "hidden" by defining a key that begins with a dot.

content/en/docs/tasks/inject-data-application/distribute-credentials-secure.md

Lines changed: 137 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -335,6 +335,143 @@ This functionality is available in Kubernetes v1.6 and later.
335335
password: 39528$vdg7Jb
336336
```
337337

338+
### Use case: Pods with prod / test credentials
339+
340+
This example illustrates a Pod which consumes a secret containing production credentials and
341+
another Pod which consumes a secret with test environment credentials.
342+
343+
You can create a `kustomization.yaml` with a `secretGenerator` field or run
344+
`kubectl create secret`.
345+
346+
```shell
347+
kubectl create secret generic prod-db-secret --from-literal=username=produser --from-literal=password=Y4nys7f11
348+
```
349+
350+
The output is similar to:
351+
352+
```
353+
secret "prod-db-secret" created
354+
```
355+
356+
You can also create a secret for test environment credentials.
357+
358+
```shell
359+
kubectl create secret generic test-db-secret --from-literal=username=testuser --from-literal=password=iluvtests
360+
```
361+
362+
The output is similar to:
363+
364+
```
365+
secret "test-db-secret" created
366+
```
367+
368+
{{< note >}}
369+
Special characters such as `$`, `\`, `*`, `=`, and `!` will be interpreted by your
370+
[shell](https://en.wikipedia.org/wiki/Shell_(computing)) and require escaping.
371+
372+
In most shells, the easiest way to escape the password is to surround it with single quotes (`'`).
373+
For example, if your actual password is `S!B\*d$zDsb=`, you should execute the command this way:
374+
375+
```shell
376+
kubectl create secret generic dev-db-secret --from-literal=username=devuser --from-literal=password='S!B\*d$zDsb='
377+
```
378+
379+
You do not need to escape special characters in passwords from files (`--from-file`).
380+
{{< /note >}}
381+
382+
Now make the Pods:
383+
384+
```shell
385+
cat <<EOF > pod.yaml
386+
apiVersion: v1
387+
kind: List
388+
items:
389+
- kind: Pod
390+
apiVersion: v1
391+
metadata:
392+
name: prod-db-client-pod
393+
labels:
394+
name: prod-db-client
395+
spec:
396+
volumes:
397+
- name: secret-volume
398+
secret:
399+
secretName: prod-db-secret
400+
containers:
401+
- name: db-client-container
402+
image: myClientImage
403+
volumeMounts:
404+
- name: secret-volume
405+
readOnly: true
406+
mountPath: "/etc/secret-volume"
407+
- kind: Pod
408+
apiVersion: v1
409+
metadata:
410+
name: test-db-client-pod
411+
labels:
412+
name: test-db-client
413+
spec:
414+
volumes:
415+
- name: secret-volume
416+
secret:
417+
secretName: test-db-secret
418+
containers:
419+
- name: db-client-container
420+
image: myClientImage
421+
volumeMounts:
422+
- name: secret-volume
423+
readOnly: true
424+
mountPath: "/etc/secret-volume"
425+
EOF
426+
```
427+
428+
Add the pods to the same `kustomization.yaml`:
429+
430+
```shell
431+
cat <<EOF >> kustomization.yaml
432+
resources:
433+
- pod.yaml
434+
EOF
435+
```
436+
437+
Apply all those objects on the API server by running:
438+
439+
```shell
440+
kubectl apply -k .
441+
```
442+
443+
Both containers will have the following files present on their filesystems with the values
444+
for each container's environment:
445+
446+
```
447+
/etc/secret-volume/username
448+
/etc/secret-volume/password
449+
```
450+
451+
Note how the specs for the two Pods differ only in one field; this facilitates
452+
creating Pods with different capabilities from a common Pod template.
453+
454+
You could further simplify the base Pod specification by using two service accounts:
455+
456+
1. `prod-user` with the `prod-db-secret`
457+
1. `test-user` with the `test-db-secret`
458+
459+
The Pod specification is shortened to:
460+
461+
```yaml
462+
apiVersion: v1
463+
kind: Pod
464+
metadata:
465+
name: prod-db-client-pod
466+
labels:
467+
name: prod-db-client
468+
spec:
469+
serviceAccount: prod-db-client
470+
containers:
471+
- name: db-client-container
472+
image: myClientImage
473+
```
474+
338475
### References
339476

340477
- [Secret](/docs/reference/generated/kubernetes-api/{{< param "version" >}}/#secret-v1-core)

0 commit comments

Comments
 (0)