Kubernetes: modify a secret using kubectl?

前端 未结 8 899
被撕碎了的回忆
被撕碎了的回忆 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条回答
  •  天涯浪人
    2021-01-31 14:48

    As I found myself in the need of modifying a secret, I landed up here.

    Here is the most convenient way I found for editing a (one-line) secret.

    This elaborates on kubectl edit secret of Timo Reimann above.

    kubectl edit secret will (in my case) invoke vi.

    Now I move the cursor to the space after the colon of the secret I want to edit.

    Then I press r and [enter] which will put the base64 encoded value onto a line of its own.

    Now I enter :. ! base64 -D which will decode the current line.

    After making my changes to the value, I enter :. ! base64 which will encode the changed value.

    Pressing k [shift]J will rejoin the secret name and its new value.

    :wq will write the new secretfile and quit vi.

    P.S. If the secret has a multi-line value, switch on line numbers (:set nu) and, after changing the decoded value, use A,B ! base64 where A and B are the line numbers of the first and last line of the value.

    P.P.S I just learned the hard way that base64 will receive the text to encode with an appended newline :( If this is no issue for your values - fine. Otherwise my current solution is to filter this out with: .!perl -pe chomp | base64

提交回复
热议问题