How can I modify the values in a Kubernetes secret
using kubectl
?
I created the secret with kubernetes create secret generic
, but t
In case you prefer a non-interactive update, this is one way of doing it:
kubectl get secret mysecret -o json | jq '.data["foo"]="YmFy"' | kubectl apply -f -
Note that YmFy
is a base64-encoded bar
string. If you want to pass the value as an argument, jq
allows you to do that:
kubectl get secret mysecret -o json | jq --arg foo "$(echo bar | base64)" '.data["foo"]=$foo' | kubectl apply -f -
I'm more comfortable using jq
but yq
should also do the job if you prefer yaml format.