Kubernetes: modify a secret using kubectl?

前端 未结 8 887
被撕碎了的回忆
被撕碎了的回忆 2021-01-31 14:17

How can I modify the values in a Kubernetes secret using kubectl?

I created the secret with kubernetes create secret generic, but t

8条回答
  •  闹比i
    闹比i (楼主)
    2021-01-31 14:50

    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.

提交回复
热议问题