@@ -42,33 +42,35 @@ characters.
42
42
43
43
### Use source files
44
44
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
+ ```
72
74
73
75
With either method, the output is similar to:
74
76
@@ -119,41 +121,41 @@ accidentally, or from being stored in a terminal log.
119
121
120
122
### Decode the Secret {#decoding-secret}
121
123
122
- 1 . View the contents of the Secret you created:
124
+ 1 . View the contents of the Secret you created:
123
125
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
+ ```
127
129
128
- The output is similar to:
130
+ The output is similar to:
129
131
130
- ` ` ` json
131
- { " password" :" UyFCXCpkJHpEc2I9" ," username" :" YWRtaW4=" }
132
- ` ` `
132
+ ``` json
133
+ { "password" : " UyFCXCpkJHpEc2I9" , "username" : " YWRtaW4=" }
134
+ ```
133
135
134
- 1. Decode the ` password` data:
136
+ 1 . Decode the ` password ` data:
135
137
136
- ` ` ` shell
137
- echo ' UyFCXCpkJHpEc2I9' | base64 --decode
138
- ` ` `
138
+ ``` shell
139
+ echo ' UyFCXCpkJHpEc2I9' | base64 --decode
140
+ ```
139
141
140
- The output is similar to:
142
+ The output is similar to:
141
143
142
- ```
143
- S! B\* d$zDsb =
144
- ```
144
+ ```
145
+ S!B\*d$zDsb=
146
+ ```
145
147
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 >}}
153
155
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
+ ```
157
159
158
160
## Edit a Secret {#edit-secret}
159
161
0 commit comments