Skip to content

Commit b1f8531

Browse files
authored
Merge pull request #35384 from shannonxtreme/add-edit-secret-file
Add Edit Secret step to Managing Secrets Using a Configuration File
2 parents 81e0c94 + 69ac3e4 commit b1f8531

File tree

1 file changed

+55
-0
lines changed

1 file changed

+55
-0
lines changed

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

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,61 @@ type: Opaque
170170

171171
`YWRtaW5pc3RyYXRvcg==` decodes to `administrator`.
172172

173+
## Edit a Secret {#edit-secret}
174+
175+
To edit the data in the Secret you created using a manifest, modify the `data`
176+
or `stringData` field in your manifest and apply the file to your
177+
cluster. You can edit an existing `Secret` object unless it is
178+
[immutable](/docs/concepts/configuration/secret/#secret-immutable).
179+
180+
For example, if you want to change the password from the previous example to
181+
`birdsarentreal`, do the following:
182+
183+
1. Encode the new password string:
184+
185+
```shell
186+
echo -n 'birdsarentreal' | base64
187+
```
188+
189+
The output is similar to:
190+
191+
```
192+
YmlyZHNhcmVudHJlYWw=
193+
```
194+
195+
1. Update the `data` field with your new password string:
196+
197+
```yaml
198+
apiVersion: v1
199+
kind: Secret
200+
metadata:
201+
name: mysecret
202+
type: Opaque
203+
data:
204+
username: YWRtaW4=
205+
password: YmlyZHNhcmVudHJlYWw=
206+
```
207+
208+
1. Apply the manifest to your cluster:
209+
210+
```shell
211+
kubectl apply -f ./secret.yaml
212+
```
213+
214+
The output is similar to:
215+
216+
```
217+
secret/mysecret configured
218+
```
219+
220+
Kubernetes updates the existing `Secret` object. In detail, the `kubectl` tool
221+
notices that there is an existing `Secret` object with the same name. `kubectl`
222+
fetches the existing object, plans changes to it, and submits the changed
223+
`Secret` object to your cluster control plane.
224+
225+
If you specified `kubectl apply --server-side` instead, `kubectl` uses
226+
[Server Side Apply](/docs/reference/using-api/server-side-apply/) instead.
227+
173228
## Clean up
174229

175230
To delete the Secret you have created:

0 commit comments

Comments
 (0)