How to delete a node label by command and api?

后端 未结 11 2203
被撕碎了的回忆
被撕碎了的回忆 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:48

    To remove the label you can use

    kubectl label nodes 10.xx.xx.xx key1-

    0 讨论(0)
  • 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)
    
    0 讨论(0)
  • 2021-02-01 00:51

    From kubectl label -h:

    Update pod 'foo' by removing a label named 'bar' if it exists.
    Does not require the --overwrite flag.
    $ kubectl label pods foo bar-

    The same works for nodes.

    0 讨论(0)
  • 2021-02-01 00:55

    You can remove label this way

    kubectl label nodes <node_name> key1- key2-
    
    eg: kubectl label nodes ip-172-20-22-247 key1- key2-
    
    0 讨论(0)
  • 2021-02-01 00:59
    1. If you want to see existing labels for the nodes kubectl get nodes --show-labels
    2. Then, list the key_name and node_name you want to modify
    3. Then, kubectl label node node_name key_name-
    0 讨论(0)
  • 2021-02-01 01:00

    Below command worked for me to remove label:

    kubectl label node <nodename> <label>-
    

    Note: The syntax is a minus sign directly after the key. For example, if the node name is worker1 and the label is system=workernode, you can remove a label with the following command.

    kubectl label node worker1 system-
    
    0 讨论(0)
提交回复
热议问题