calicoctl label

This section describes the calicoctl label command.

Read the calicoctl command line interface user reference for a full list of calicoctl commands.

calicoctl label - 图1note

The available actions for a specific resource type may be limited based on the datastore used for Calico (etcdv3 / Kubernetes API). Please refer to the Resources section for details about each resource type.

Displaying the help text for ‘calicoctl label’ command

Run calicoctl label --help to display the following help menu for the command.

  1. Usage:
  2. calicoctl label (<KIND> <NAME>
  3. ( <key>=<value> [--overwrite] |
  4. <key> --remove )
  5. [--config=<CONFIG>] [--namespace=<NS>])
  6. Examples:
  7. # Label a workload endpoint
  8. calicoctl label workloadendpoints nginx --namespace=default app=web
  9. # Label a node and overwrite the original value of key 'cluster'
  10. calicoctl label nodes node1 cluster=frontend --overwrite
  11. # Remove label with key 'cluster' of the node
  12. calicoctl label nodes node1 cluster --remove
  13. Options:
  14. -h --help Show this screen.
  15. -c --config=<CONFIG> Path to the file containing connection
  16. configuration in YAML or JSON format.
  17. [default: /etc/calico/calicoctl.cfg]
  18. -n --namespace=<NS> Namespace of the resource.
  19. Only applicable to NetworkPolicy, NetworkSet, and WorkloadEndpoint.
  20. Uses the default namespace if not specified.
  21. --overwrite If true, overwrite the value when the key is already
  22. present in labels. Otherwise reports error when the
  23. labeled resource already have the key in its labels.
  24. Can not be used with --remove.
  25. --remove If true, remove the specified key in labels of the
  26. resource. Reports error when specified key does not
  27. exist. Can not be used with --overwrite.
  28. --context=<context> The name of the kubeconfig context to use.
  29. Description:
  30. The label command is used to add or update a label on a resource. Resource types
  31. that can be labeled are:
  32. * bgpConfiguration
  33. * bgpPeer
  34. * felixConfiguration
  35. * globalNetworkPolicy
  36. * globalNetworkSet
  37. * hostEndpoint
  38. * ipPool
  39. * networkPolicy
  40. * networkSet
  41. * node
  42. * profile
  43. * workloadEndpoint
  44. The resource type is case insensitive and may be pluralized.
  45. Attempting to label resources that do not exist will get an error.
  46. Attempting to remove a label that does not exist in the resource will get an error.
  47. When labeling a resource on an existing key:
  48. - gets an error if option --overwrite is not provided.
  49. - value of the key updates to specified value if option --overwrite is provided.

Examples

  1. Label a node.

    1. calicoctl label nodes node1 cluster=backend

    Results indicate that label was successfully applied.

    1. Successfully set label cluster on nodes node1
  2. Label a node and overwrite the original value of key cluster.

    1. calicoctl label nodes node1 cluster=frontend --overwrite

    Results indicate that label was successfully overwritten.

    1. Successfully updated label cluster on nodes node1
  3. Remove label with key cluster from the node.

    1. calicoctl label nodes node1 cluster --remove

    Results indicate that the label was successfully removed.

    1. Successfully removed label cluster from nodes node1.

Options

  1. -n --namespace=<NS> Namespace of the resource.
  2. Only applicable to NetworkPolicy and WorkloadEndpoint.
  3. Uses the default namespace if not specified.
  4. --overwrite If true, overwrite the value when the key is already
  5. present in labels. Otherwise reports error when the
  6. labeled resource already have the key in its labels.
  7. Can not be used with --remove.
  8. --remove If true, remove the specified key in labels of the
  9. resource. Reports error when specified key does not
  10. exist. Can not be used with --overwrite.

General options

  1. -c --config=<CONFIG> Path to the file containing connection
  2. configuration in YAML or JSON format.
  3. [default: /etc/calico/calicoctl.cfg]

See also