How to delete a node label by command and api?

后端 未结 11 2306
被撕碎了的回忆
被撕碎了的回忆 2021-02-01 00:31

Add label to nodes:

$ kubectl label nodes 10.xx.xx.xx key1=val1 

If I want to delete label(key1=val1) on node(10.xx.xx.xx), how

11条回答
  •  不要未来只要你来
    2021-02-01 00:51

    As already mentioned, correct kubectl example to delete label, but there is no mention of removing labels using API clients. if you want to remove label using the API, then you need to provide a new body with the labelname: None and then patch that body to the node or pod. I am using the kubernetes python client API for example purpose

    from pprint import pprint
    from kubernetes import client, config
    
    config.load_kube_config()
    client.configuration.debug = True
    
    api_instance = client.CoreV1Api()
    
    body = {
        "metadata": {
            "labels": {
                "label-name": None}
            }
    }
    
    api_response = api_instance.patch_node("minikube", body)
    
    print(api_response)
    

提交回复
热议问题