我想使用战略合并补丁从节点删除标签。 这是我用来删除标签的内容:
kubectl patch node xxx --type='strategic' -p '{"metadata":{"labels":{"$patch": "delete", "node-role.kubernetes.io/master":""}}}'
xxx patched
成功,但是这里有两个问题:
kubectl patch node xxx --type='strategic' -p '{"metadata":{"labels":{"$patch": "delete", "node-role.kubernetes.io/master":""}}}'
The Node "xxx" is invalid: metadata.labels: Invalid value: "$patch": name part must consist of alphanumeric characters, '-', '_' or '.', and must start and end with an alphanumeric character (e.g. 'MyName', or 'my.name', or '123-abc', regex used for validation is '([A-Za-z0-9][-A-Za-z0-9_.]*)?[A-Za-z0-9]')
如何只删除我指定的一个标签? 具有删除操作的补丁不是幂等的吗?我不太了解重新尝试删除标签时报告的错误。
答案 0 :(得分:2)
检查kubectl内部调用的REST API,以从节点中删除标签
kubectl label nodes kind-control-plane abc- -v=10
I0602 09:21:04.717687 37243 request.go:1068] Request Body: {"metadata":{"labels":{"abc":null}}}
I0602 09:21:04.717784 37243 round_trippers.go:423] curl -k -v -XPATCH -H "User-Agent: kubectl/v1.18.0 (darwin/amd64) kubernetes/9e99141" -H "Accept: application/json" -H "Content-Type: application/merge-patch+json" 'https://127.0.0.1:32768/api/v1/nodes/kind-control-plane'
然后从客户端库调用相同的API