Manage node labels K8S

Manage Kubernetes node labels

5

Votes

from pprint import pprint

from kubernetes import client, config


def main():
    """
    Change labels of the "minikube" node:
     - Add label "foo" with value "bar". This will overwrite the "foo" label
       if it already exists.
     - Remove the label "baz" from the node.
    """

    config.load_kube_config()

    api_instance = client.CoreV1Api()

    body = {
        "metadata": {
            "labels": {
                "foo": "bar",
                "baz": None}
        }
    }

    api_response = api_instance.patch_node("minikube", body)

    pprint(api_response)


if __name__ == '__main__':
    main()

Vote Here

You must earn at least 1 vote on your snippets to be allowed to vote

Terms Of Use

Privacy Policy

Featured snippets are MIT license

Gears & Masters

Advertise

DevOpsnipp.com © 2020

medium.png