Skip to content

Commit 9a6cc40

Browse files
authored
Merge pull request #39230 from Zhuzhenghao/remove-spaces
Make layout prettier in managing-secret-using-kubectl.md
2 parents 80415a5 + 3a9c759 commit 9a6cc40

File tree

1 file changed

+55
-53
lines changed

1 file changed

+55
-53
lines changed

content/en/docs/tasks/configmap-secret/managing-secret-using-kubectl.md

Lines changed: 55 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -42,33 +42,35 @@ characters.
4242

4343
### Use source files
4444

45-
1. Store the credentials in files:
46-
47-
```shell
48-
echo -n 'admin' > ./username.txt
49-
echo -n 'S!B\*d$zDsb=' > ./password.txt
50-
```
51-
The `-n` flag ensures that the generated files do not have an extra newline
52-
character at the end of the text. This is important because when `kubectl`
53-
reads a file and encodes the content into a base64 string, the extra
54-
newline character gets encoded too. You do not need to escape special
55-
characters in strings that you include in a file.
56-
57-
1. Pass the file paths in the `kubectl` command:
58-
59-
```shell
60-
kubectl create secret generic db-user-pass \
61-
--from-file=./username.txt \
62-
--from-file=./password.txt
63-
```
64-
The default key name is the file name. You can optionally set the key name
65-
using `--from-file=[key=]source`. For example:
66-
67-
```shell
68-
kubectl create secret generic db-user-pass \
69-
--from-file=username=./username.txt \
70-
--from-file=password=./password.txt
71-
```
45+
1. Store the credentials in files:
46+
47+
```shell
48+
echo -n 'admin' > ./username.txt
49+
echo -n 'S!B\*d$zDsb=' > ./password.txt
50+
```
51+
52+
The `-n` flag ensures that the generated files do not have an extra newline
53+
character at the end of the text. This is important because when `kubectl`
54+
reads a file and encodes the content into a base64 string, the extra
55+
newline character gets encoded too. You do not need to escape special
56+
characters in strings that you include in a file.
57+
58+
1. Pass the file paths in the `kubectl` command:
59+
60+
```shell
61+
kubectl create secret generic db-user-pass \
62+
--from-file=./username.txt \
63+
--from-file=./password.txt
64+
```
65+
66+
The default key name is the file name. You can optionally set the key name
67+
using `--from-file=[key=]source`. For example:
68+
69+
```shell
70+
kubectl create secret generic db-user-pass \
71+
--from-file=username=./username.txt \
72+
--from-file=password=./password.txt
73+
```
7274

7375
With either method, the output is similar to:
7476

@@ -119,41 +121,41 @@ accidentally, or from being stored in a terminal log.
119121

120122
### Decode the Secret {#decoding-secret}
121123

122-
1. View the contents of the Secret you created:
124+
1. View the contents of the Secret you created:
123125

124-
```shell
125-
kubectl get secret db-user-pass -o jsonpath='{.data}'
126-
```
126+
```shell
127+
kubectl get secret db-user-pass -o jsonpath='{.data}'
128+
```
127129

128-
The output is similar to:
130+
The output is similar to:
129131

130-
```json
131-
{"password":"UyFCXCpkJHpEc2I9","username":"YWRtaW4="}
132-
```
132+
```json
133+
{ "password": "UyFCXCpkJHpEc2I9", "username": "YWRtaW4=" }
134+
```
133135

134-
1. Decode the `password` data:
136+
1. Decode the `password` data:
135137

136-
```shell
137-
echo 'UyFCXCpkJHpEc2I9' | base64 --decode
138-
```
138+
```shell
139+
echo 'UyFCXCpkJHpEc2I9' | base64 --decode
140+
```
139141

140-
The output is similar to:
142+
The output is similar to:
141143

142-
```
143-
S!B\*d$zDsb=
144-
```
144+
```
145+
S!B\*d$zDsb=
146+
```
145147

146-
{{< caution >}}
147-
This is an example for documentation purposes. In practice,
148-
this method could cause the command with the encoded data to be stored in
149-
your shell history. Anyone with access to your computer could find the
150-
command and decode the secret. A better approach is to combine the view and
151-
decode commands.
152-
{{< /caution >}}
148+
{{< caution >}}
149+
This is an example for documentation purposes. In practice,
150+
this method could cause the command with the encoded data to be stored in
151+
your shell history. Anyone with access to your computer could find the
152+
command and decode the secret. A better approach is to combine the view and
153+
decode commands.
154+
{{< /caution >}}
153155

154-
```shell
155-
kubectl get secret db-user-pass -o jsonpath='{.data.password}' | base64 --decode
156-
```
156+
```shell
157+
kubectl get secret db-user-pass -o jsonpath='{.data.password}' | base64 --decode
158+
```
157159

158160
## Edit a Secret {#edit-secret}
159161

0 commit comments

Comments
 (0)