calicoctl get

This sections describes the calicoctl get command.

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

calicoctl get - 图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 get’ command

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

  1. Usage:
  2. calicoctl get ( (<KIND> [<NAME...>]) |
  3. --filename=<FILENAME>) [--recursive] [--skip-empty]
  4. [--output=<OUTPUT>] [--config=<CONFIG>] [--namespace=<NS>] [--all-namespaces]
  5. Examples:
  6. # List all policy in default output format.
  7. calicoctl get policy
  8. # List specific policies in YAML format
  9. calicoctl get -o yaml policy my-policy-1 my-policy-2
  10. Options:
  11. -h --help Show this screen.
  12. -f --filename=<FILENAME> Filename to use to get the resource. If set to
  13. "-" loads from stdin. If filename is a directory, this command is
  14. invoked for each .json .yaml and .yml file within that directory,
  15. terminating after the first failure.
  16. -R --recursive Process the filename specified in -f or --filename recursively.
  17. --skip-empty Do not error if any files or directory specified using -f or --filename contain no
  18. data.
  19. -o --output=<OUTPUT FORMAT> Output format. One of: yaml, json, ps, wide,
  20. custom-columns=..., go-template=...,
  21. go-template-file=... [Default: ps]
  22. -c --config=<CONFIG> Path to the file containing connection
  23. configuration in YAML or JSON format.
  24. [default: /etc/calico/calicoctl.cfg]
  25. -n --namespace=<NS> Namespace of the resource.
  26. Only applicable to NetworkPolicy and WorkloadEndpoint.
  27. Uses the default namespace if not specified.
  28. -A --all-namespaces If present, list the requested object(s) across
  29. all namespaces.
  30. --export If present, returns the requested object(s) stripped of
  31. cluster-specific information. This flag will be ignored
  32. if <NAME> is not specified.
  33. --context=<context> The name of the kubeconfig context to use.
  34. Description:
  35. The get command is used to display a set of resources by filename or stdin,
  36. or by type and identifiers. JSON and YAML formats are accepted for file and
  37. stdin format.
  38. Valid resource types are:
  39. * bgpConfiguration
  40. * bgpPeer
  41. * felixConfiguration
  42. * globalNetworkPolicy
  43. * hostEndpoint
  44. * ipPool
  45. * networkPolicy
  46. * networkSet
  47. * node
  48. * profile
  49. * workloadEndpoint
  50. The resource type is case insensitive and may be pluralized.
  51. Attempting to get resources that do not exist will simply return no results.
  52. When getting resources by type, only a single type may be specified at a
  53. time. The name and other identifiers (hostname, scope) are optional, and are
  54. wildcarded when omitted. Thus if you specify no identifiers at all (other
  55. than type), then all configured resources of the requested type will be
  56. returned.
  57. By default the results are output in a ps-style table output. There are
  58. alternative ways to display the data using the --output option:
  59. ps Display the results in ps-style output.
  60. wide As per the ps option, but includes more headings.
  61. custom-columns As per the ps option, but only display the columns
  62. that are requested in the comma-separated list.
  63. golang-template Display the results using the specified golang
  64. template. This can be used to filter results, for
  65. example to return a specific value.
  66. golang-template-file Display the results using the golang template that is
  67. contained in the specified file.
  68. yaml Display the results in YAML output format.
  69. json Display the results in JSON output format.
  70. Note that the data output using YAML or JSON format is always valid to use as
  71. input to all of the resource management commands (create, apply, replace,
  72. delete, get).
  73. Please refer to the docs at https://projectcalico.docs.tigera.io for more details on
  74. the output formats, including example outputs, resource structure (required
  75. for the golang template definitions) and the valid column names (required for
  76. the custom-columns option).

Options

  1. -h --help Show this screen.
  2. -f --filename=<FILENAME> Filename to use to get the resource. If set to
  3. "-" loads from stdin.
  4. -o --output=<OUTPUT FORMAT> Output format. One of: yaml, json, ps, wide,
  5. custom-columns=..., go-template=...,
  6. go-template-file=... [Default: ps]
  7. -n --namespace=<NS> Namespace of the resource.
  8. Only applicable to NetworkPolicy, NetworkSet, and WorkloadEndpoint.
  9. Uses the default namespace if not specified.
  10. -A --all-namespaces If present, list the requested object(s) across
  11. all namespaces.
  12. --export If present, returns the requested object(s) stripped of
  13. cluster-specific information. This flag will be ignored
  14. if the resource name is not specified.

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]

Output options

ps

This is the default output format. It displays output in ps-style table output with sufficient columns to uniquely identify the resource.

The headings displayed for each resource type is fixed. However, we wide option for displaying additional columns, and custom-columns for selecting which columns to display.

Example:

  1. calicoctl get hostEndpoint

Response:

  1. NAME NODE
  2. endpoint1 host1
  3. myhost-eth0 myhost

wide

Similar to the ps format, the wide option displays output in ps-style table output but with additional columns.

The headings displayed for each resource type is fixed. See custom-columns for selecting which columns to display.

Example:

  1. calicoctl get hostEndpoint --output=wide

Response:

  1. NAME NODE INTERFACE IPS PROFILES
  2. endpoint1 host1 1.2.3.4,0:bb::aa prof1,prof2
  3. myhost-eth0 myhost profile1

custom-columns

Similar to the ps format, the custom-columns option displays output in ps-style table output but allows the user to specify and ordered, comma-separated list of columns to display in the output. The valid heading names for each resource type is documented in the Resources guide.

Example:

  1. calicoctl get hostEndpoint --output=custom-columns=NAME,IPS

Response:

  1. NAME IPS
  2. endpoint1 1.2.3.4,0:bb::aa
  3. myhost-eth0

yaml / json

The yaml and json options display the output as a list of YAML documents or JSON dictionaries. The fields for resource type are documented in the Resources guide.

The output from either of these formats may be used as input for all of the resource management commands.

Example:

  1. calicoctl get hostEndpoint --output=yaml

Response:

  1. - apiVersion: projectcalico.org/v3
  2. kind: HostEndpoint
  3. metadata:
  4. labels:
  5. type: database
  6. name: endpoint1
  7. spec:
  8. node: host1
  9. expectedIPs:
  10. - 1.2.3.4
  11. - 0:bb::aa
  12. profiles:
  13. - prof1
  14. - prof2
  15. - apiVersion: projectcalico.org/v3
  16. kind: HostEndpoint
  17. metadata:
  18. name: myhost-eth0
  19. spec:
  20. node: myhost
  21. profiles:
  22. - profile1

go-template / go-template-file

The go-template and go-template-file options display the output using a golang template specified as a string on the CLI, or defined in a separate file. When writing a template, be aware that the data passed to the template is a golang slice of resource-lists. The resource-lists are defined in the libcalico API and there is a resource-list defined for each resource type. A resource-list contains an Items field which is itself a slice of resources. Thus, to output the “Name” field from the supplied data, it is necessary to enumerate over the slice of resource-lists and the items within that list.

Example:

  1. bin/calicoctl get hostEndpoint --output=go-template="{{range .}}{{range .Items}}{{.ObjectMeta.Name}},{{end}}{{end}}"
  2. endpoint1,eth0,

See also