1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

kubectl patchのJSON KEYに"/"スラッシュが入っているのはなし

Last updated at Posted at 2019-06-29

kubectl patchコマンドでPodのAnnotationsを修正したいですが、Keyが流行っているabc.com/defの形にして、エラーとなりました。

$ kubectl patch pod simple-pod --type='json' -p='[{"op": "add", "path": "/metadata/annotations/abc.com/my-key", "value": "abcde" }]'
The  "" is invalid

エラーメッセージはいい加減で、それは当然だ、KeyにJSON PATHの区切る符号が入ってるからじゃないかと思っていました。。

エスケープしようとして、バックスラッシュはだめでした。調べたどころ、/~1しなければなりません。

$ kubectl patch pod simple-pod --type='json' -p='[{"op": "add", "path": "/metadata/annotations/abc.com~1my-key", "value": "abcde" }]'
pod "simple-pod" patched

結果OKです。

$ kubectl get pods -o yaml   

apiVersion: v1
items:
- apiVersion: v1
  kind: Pod
  metadata:
    annotations:
      abc.com/my-key: abcde
1
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?