まえがき
- Kubernetes実践で勉強しているとき発生した事象について書いています。
- Secretオブジェクトをtypoして登録しまい、どうやって修正したら良いかを調べていたらバルゴさん(@go_vargo)に助言頂いて解決できたのでまとめた記事になります。
editやpatchで修正できなければ作り直しな気がしますね…
— バルゴ@技術書典「う44」Helm本 (@go_vargo) March 30, 2019
スコープ
- 作成済みのSecretの値を編集する方法
スコープ外
- 以下は厳密に検証しておりません。
- 修正後の反映タイミング
- Podの動き
- こちらの方のブログが詳しいと思います。
- ConfigMapの修正
概要
- Secretオブジェクト作成
- kubectlで編集
Secretオブジェクト作成
- パスワードを表すキーがパッソワルドになってしまった!(マジでやったやつ)
$ kubectl create secret generic test-secret --from-literal=user=dbuser --from-literal=passowrd=dbpass
- 確認
$ kubectl get secret test-secret -o yaml apiVersion: v1 data: passowrd: ZGJwYXNz user: ZGJ1c2Vy kind: Secret metadata: creationTimestamp: "2019-03-30T03:49:58Z" name: test-secret namespace: default resourceVersion: "48786" selfLink: /api/v1/namespaces/default/secrets/test-secret uid: e39397ca-529e-11e9-8815-025000000001 type: Opaque
修正する
kubectl edit
で登録済みのyamlを直接編集する
$ kubectl edit secret test-secret 1 # Please edit the object below. Lines beginning with a '#' will be ignored, 2 # and an empty file will abort the edit. If an error occurs while saving this file will be 3 # reopened with the relevant failures. 4 # 5 apiVersion: v1 6 data: 7 passowrd: ZGJwYXNz 8 user: ZGJ1c2Vy 9 kind: Secret 10 metadata: 11 creationTimestamp: "2019-03-30T03:49:58Z" 12 name: test-secret 13 namespace: default 14 resourceVersion: "48786" 15 selfLink: /api/v1/namespaces/default/secrets/test-secret 16 uid: e39397ca-529e-11e9-8815-025000000001 17 type: Opaque
passowrd
→password
修正して保存(:wq)kubectl get secret test-secret -o yaml
で治ってることを確認する
まとめ
kubectl edit
でSecretオブジェクトの直接編集ができる。- が、手で変更をした場合の変更管理とかは気をつけないといけなさそう。
- 実際の運用では、直接直してしまうよりyamlを使って暗号化して管理、の方が良いかもしれない。