I'm trying to update a secret with new key. The issue is that when i call again this secret object, it don't reflect this change.
I get the secret data:
kubectl get secret mysecret --context dev -n dev-test -o jsonpath=\{$.data\} | jq
{
"example1": "Rlc3QuY29taW5hZG1pbn",
"example2": "NYXBiN3c3c1U3NFd",
"example3": "aW5hZG1pbnRlc3QsZGM9Y29tZGM9YWQsZGM9",
"example4": "jMDEuYWQuaW5hZG1pbnRlbGRhcDovL2luYmRc3QuY29tOjMyNjg=",
"example5": "YWxmcmVzY28YWRtaW50ZXN0LmNvbQ==uaW1wb3J0QGlu"
}
I aply the add command with jq :
kubectl get secret mysecret --context dev -n dev-test -o jsonpath=\{$.data\} | jq ' .test = "tests" '
{
"example1": "Rlc3QuY29taW5hZG1pbn",
"example2": "NYXBiN3c3c1U3NFd",
"example3": "aW5hZG1pbnRlc3QsZGM9Y29tZGM9YWQsZGM9",
"example4": "jMDEuYWQuaW5hZG1pbnRlbGRhcDovL2luYmRc3QuY29tOjMyNjg=",
"example5": "YWxmcmVzY28YWRtaW50ZXN0LmNvbQ==uaW1wb3J0QGlu",
"test": "tests"
}
Now, when i call the secret again, the output is like the original and not with the adding key
kubectl get secret mysecret --context dev -n dev-test -o jsonpath=\{$.data\} | jq
{
"example1": "Rlc3QuY29taW5hZG1pbn",
"example2": "NYXBiN3c3c1U3NFd",
"example3": "aW5hZG1pbnRlc3QsZGM9Y29tZGM9YWQsZGM9",
"example4": "jMDEuYWQuaW5hZG1pbnRlbGRhcDovL2luYmRc3QuY29tOjMyNjg=",
"example5": "YWxmcmVzY28YWRtaW50ZXN0LmNvbQ==uaW1wb3J0QGlu"
}
How can i set this new key ? Obs: I'm not usin any yaml file.
CodePudding user response:
Try
kubectl get secret mysecret -o json | jq --arg secret_base64 "$(echo -n tests | base64)" '.data.test=$secret_base64' | kubectl apply -f -
You can do it with kubectl edit secret mysecret
and add a new secret key
test: dGVzdHM= # echo -n tests | base64