1"use strict";(self.webpackChunktigera_docs=self.webpackChunktigera_docs||[]).push([["18124"],{98071:function(e,t,n){n.r(t),n.d(t,{frontMatter:()=>l,default:()=>p,toc:()=>r,metadata:()=>o,assets:()=>a,contentTitle:()=>c});var o=JSON.parse('{"id":"reference/calicoctl/get","title":"calicoctl get","description":"Command to list policies in the default output format.","source":"@site/calico_versioned_docs/version-3.30/reference/calicoctl/get.mdx","sourceDirName":"reference/calicoctl","slug":"/reference/calicoctl/get","permalink":"/calico/latest/reference/calicoctl/get","draft":false,"unlisted":false,"editUrl":"https://github.com/tigera/docs/edit/main/calico_versioned_docs/version-3.30/reference/calicoctl/get.mdx","tags":[],"version":"3.30","frontMatter":{"description":"Command to list policies in the default output format."},"sidebar":"calicoSidebar","previous":{"title":"calicoctl delete","permalink":"/calico/latest/reference/calicoctl/delete"},"next":{"title":"calicoctl patch","permalink":"/calico/latest/reference/calicoctl/patch"}}'),i=n(72459),s=n(36870);let l={description:"Command to list policies in the default output format."},c="calicoctl get",a={},r=[{value:"Displaying the help text for 'calicoctl get' command",id:"displaying-the-help-text-for-calicoctl-get-command",level:2},{value:"Options",id:"options",level:3},{value:"General options",id:"general-options",level:3},{value:"Output options",id:"output-options",level:3},{value:"<code>ps</code>",id:"ps",level:4},{value:"<code>wide</code>",id:"wide",level:4},{value:"<code>custom-columns</code>",id:"custom-columns",level:4},{value:"<code>yaml / json</code>",id:"yaml--json",level:4},{value:"<code>go-template / go-template-file</code>",id:"go-template--go-template-file",level:4},{value:"See also",id:"see-also",level:2}];function d(e){let t={a:"a",admonition:"admonition",code:"code",h1:"h1",h2:"h2",h3:"h3",h4:"h4",header:"header",li:"li",p:"p",pre:"pre",ul:"ul",...(0,s.a)(),...e.components};return(0,i.jsxs)(i.Fragment,{children:[(0,i.jsx)(t.header,{children:(0,i.jsx)(t.h1,{id:"calicoctl-get",children:"calicoctl get"})}),"\n",(0,i.jsxs)(t.p,{children:["This sections describes the ",(0,i.jsx)(t.code,{children:"calicoctl get"})," command."]}),"\n",(0,i.jsxs)(t.p,{children:["Read the ",(0,i.jsx)(t.a,{href:"/calico/latest/reference/calicoctl/overview",children:"calicoctl command line interface user reference"}),"\nfor a full list of calicoctl commands."]}),"\n",(0,i.jsx)(t.admonition,{type:"note",children:(0,i.jsxs)(t.p,{children:["The available actions for a specific resource type may be\nlimited based on the datastore used for Calico (etcdv3 / Kubernetes API).\nPlease refer to the\n",(0,i.jsx)(t.a,{href:"/calico/latest/reference/resources/overview",children:"Resources section"}),"\nfor details about each resource type."]})}),"\n",(0,i.jsx)(t.h2,{id:"displaying-the-help-text-for-calicoctl-get-command",children:"Displaying the help text for 'calicoctl get' command"}),"\n",(0,i.jsxs)(t.p,{children:["Run ",(0,i.jsx)(t.code,{children:"calicoctl get --help"})," to display the following help menu for the\ncommand."]}),"\n",(0,i.jsx)(t.pre,{children:(0,i.jsx)(t.code,{children:'Usage:\n calicoctl get ( (<KIND> [<NAME...>]) |\n --filename=<FILENAME>) [--recursive] [--skip-empty]\n [--output=<OUTPUT>] [--config=<CONFIG>] [--namespace=<NS>] [--all-namespaces]\n\nExamples:\n # List all policy in default output format.\n calicoctl get policy\n\n # List specific policies in YAML format\n calicoctl get -o yaml policy my-policy-1 my-policy-2\n\nOptions:\n -h --help Show this screen.\n -f --filename=<FILENAME> Filename to use to get the resource. If set to\n "-" loads from stdin. If filename is a directory, this command is\n invoked for each .json .yaml and .yml file within that directory,\n terminating after the first failure.\n -R --recursive Process the filename specified in -f or --filename recursively.\n --skip-empty Do not error if any files or directory specified using -f or --filename contain no\n data.\n -o --output=<OUTPUT FORMAT> Output format. One of: yaml, json, ps, wide,\n custom-columns=..., go-template=...,\n go-template-file=... [Default: ps]\n -c --config=<CONFIG> Path to the file containing connection\n configuration in YAML or JSON format.\n [default: /etc/calico/calicoctl.cfg]\n -n --namespace=<NS> Namespace of the resource.\n Only applicable to NetworkPolicy and WorkloadEndpoint.\n Uses the default namespace if not specified.\n -A --all-namespaces If present, list the requested object(s) across\n all namespaces.\n --export If present, returns the requested object(s) stripped of\n cluster-specific information. This flag will be ignored\n if <NAME> is not specified.\n --context=<context> The name of the kubeconfig context to use.\n\nDescription:\n The get command is used to display a set of resources by filename or stdin,\n or by type and identifiers. JSON and YAML formats are accepted for file and\n stdin format.\n\n Valid resource types are:\n\n - bgpconfiguration\n - bgpfilter\n - bgppeer\n - clusterinformation\n - felixconfiguration\n - globalnetworkpolicy\n - globalnetworkset\n - hostendpoint\n - ippool\n - ipreservation\n - kubecontrollersconfiguration\n - networkpolicy\n - networkset\n - node\n - profile\n - tier\n - workloadendpoint\n\n The resource type is case-insensitive and may be pluralized.\n\n Attempting to get resources that do not exist will simply return no results.\n\n When getting resources by type, only a single type may be specified at a\n time. The name and other identifiers (hostname, scope) are optional, and are\n wildcarded when omitted. Thus if you specify no identifiers at all (other\n than type), then all configured resources of the requested type will be\n returned.\n\n By default the results are output in a ps-style table output. There are\n alternative ways to display the data using the --output option:\n\n ps Display the results in ps-style output.\n wide As per the ps option, but includes more headings.\n custom-columns As per the ps option, but only display the columns\n that are requested in the comma-separated list.\n golang-template Display the results using the specified golang\n template. This can be used to filter results, for\n example to return a specific value.\n golang-template-file Display the results using the golang template that is\n contained in the specified file.\n yaml Display the results in YAML output format.\n json Display the results in JSON output format.\n\n Note that the data output using YAML or JSON format is always valid to use as\n input to all of the resource management commands (create, apply, replace,\n delete, get).\n\n Please refer to the docs at https://projectcalico.docs.tigera.io for more details on\n the output formats, including example outputs, resource structure (required\n for the golang template definitions) and the valid column names (required for\n the custom-columns o
1ption).\n'})}),"\n",(0,i.jsx)(t.h3,{id:"options",children:"Options"}),"\n",(0,i.jsx)(t.pre,{children:(0,i.jsx)(t.code,{children:'-h --help Show this screen.\n-f --filename=<FILENAME> Filename to use to get the resource. If set to\n "-" loads from stdin.\n-o --output=<OUTPUT FORMAT> Output format. One of: yaml, json, ps, wide,\n custom-columns=..., go-template=...,\n go-template-file=... [Default: ps]\n-n --namespace=<NS> Namespace of the resource.\n Only applicable to NetworkPolicy, NetworkSet, and WorkloadEndpoint.\n Uses the default namespace if not specified.\n-A --all-namespaces If present, list the requested object(s) across\n all namespaces.\n--export If present, returns the requested object(s) stripped of\n cluster-specific information. This flag will be ignored\n if the resource name is not specified.\n'})}),"\n",(0,i.jsx)(t.h3,{id:"general-options",children:"General options"}),"\n",(0,i.jsx)(t.pre,{children:(0,i.jsx)(t.code,{children:"-c --config=<CONFIG> Path to the file containing connection\n configuration in YAML or JSON format.\n [default: /etc/calico/calicoctl.cfg]\n"})}),"\n",(0,i.jsx)(t.h3,{id:"output-options",children:"Output options"}),"\n",(0,i.jsx)(t.h4,{id:"ps",children:(0,i.jsx)(t.code,{children:"ps"})}),"\n",(0,i.jsx)(t.p,{children:"This is the default output format. It displays output in ps-style table output with sufficient columns to\nuniquely identify the resource."}),"\n",(0,i.jsxs)(t.p,{children:["The headings displayed for each resource type is fixed. However, we ",(0,i.jsx)(t.code,{children:"wide"})," option for displaying additional\ncolumns, and ",(0,i.jsx)(t.code,{children:"custom-columns"})," for selecting which columns to display."]}),"\n",(0,i.jsx)(t.p,{children:"Example:"}),"\n",(0,i.jsx)(t.pre,{children:(0,i.jsx)(t.code,{className:"language-bash",children:"calicoctl get hostEndpoint\n"})}),"\n",(0,i.jsx)(t.p,{children:"Response:"}),"\n",(0,i.jsx)(t.pre,{children:(0,i.jsx)(t.code,{children:"NAME NODE\nendpoint1 host1\nmyhost-eth0 myhost\n"})}),"\n",(0,i.jsx)(t.h4,{id:"wide",children:(0,i.jsx)(t.code,{children:"wide"})}),"\n",(0,i.jsxs)(t.p,{children:["Similar to the ",(0,i.jsx)(t.code,{children:"ps"})," format, the ",(0,i.jsx)(t.code,{children:"wide"})," option displays output in ps-style table output but with additional columns."]}),"\n",(0,i.jsxs)(t.p,{children:["The headings displayed for each resource type is fixed. See ",(0,i.jsx)(t.code,{children:"custom-columns"})," for selecting which columns to display."]}),"\n",(0,i.jsx)(t.p,{children:"Example:"}),"\n",(0,i.jsx)(t.pre,{children:(0,i.jsx)(t.code,{className:"language-bash",children:"calicoctl get hostEndpoint --output=wide\n"})}),"\n",(0,i.jsx)(t.p,{children:"Response:"}),"\n",(0,i.jsx)(t.pre,{children:(0,i.jsx)(t.code,{children:"NAME NODE INTERFACE IPS PROFILES\nendpoint1 host1 1.2.3.4,0:bb::aa prof1,prof2\nmyhost-eth0 myhost profile1\n"})}),"\n",(0,i.jsx)(t.h4,{id:"custom-columns",children:(0,i.jsx)(t.code,{children:"custom-columns"})}),"\n",(0,i.jsxs)(t.p,{children:["Similar to the ",(0,i.jsx)(t.code,{children:"ps"})," format, the ",(0,i.jsx)(t.code,{children:"custom-columns"})," option displays output in ps-style table output but allows the user\nto specify and ordered, comma-separated list of columns to display in the output. The valid heading names for each\nresource type is documented in the ",(0,i.jsx)(t.a,{href:"/calico/latest/reference/resources/overview",children:"Resources"})," guide."]}),"\n",(0,i.jsx)(t.p,{children:"Example:"}),"\n",(0,i.jsx)(t.pre,{children:(0,i.jsx)(t.code,{children:"calicoctl get hostEndpoint --output=custom-columns=NAME,IPS\n"})}),"\n",(0,i.jsx)(t.p,{children:"Response:"}),"\n",(0,i.jsx)(t.pre,{children:(0,i.jsx)(t.code,{children:"NAME IPS\nendpoint1 1.2.3.4,0:bb::aa\nmyhost-eth0\n"})}),"\n",(0,i.jsx)(t.h4,{id:"yaml--json",children:(0,i.jsx)(t.code,{children:"yaml / json"})}),"\n",(0,i.jsxs)(t.p,{children:["The ",(0,i.jsx)(t.code,{children:"yaml"})," and ",(0,i.jsx)(t.code,{children:"json"})," options display the output as a list of YAML documents or JSON dictionaries. The fields for\nresource type are documented in the ",(0,i.jsx)(t.a,{href:"/calico/latest/reference/resources/overview",children:"Resources"})," guide."]}),"\n",(0,i.jsx)(t.p,{children:"The output from either of these formats may be used as input for all of the resource management commands."}),"\n",(0,i.jsx)(t.p,{children:"Example:"}),"\n",(0,i.jsx)(t.pre,{children:(0,i.jsx)(t.code,{className:"language-bash",children:"calicoctl get hostEndpoint --output=yaml\n"})}),"\n",(0,i.jsx)(t.p,{children:"Response:"}),"\n",(0,i.jsx)(t.pre,{children:(0,i.jsx)(t.code,{className:"language-yaml",children:"- apiVersion: projectcalico.org/v3\n kind: HostEndpoint\n metadata:\n labels:\n type: database\n name: endpoint1\n spec:\n node: host1\n expectedIPs:\n - 1.2.3.4\n - 0:bb::aa\n profiles:\n - prof1\n - prof2\n- apiVersion: projectcalico.org/v3\n kind: HostEndpoint\n metadata:\n name: myhost-eth0\n spec:\n node: myhost\n profiles:\n - profile1\n"})}),"\n",(0,i.jsx)(t.h4,{id:"go-template--go-template-file",children:(0,i.jsx)(t.code,{children:"go-template / go-template-file"})}),"\n",(0,i.jsxs)(t.p,{children:["The ",(0,i.jsx)(t.code,{children:"go-template"})," and ",(0,i.jsx)(t.code,{children:"go-template-file"})," options display the output using a golang template specified as a string\non the CLI, or defined in a separate file.\nWhen writing a template, be aware that the data passed to the template is a golang slice of resource-lists. The\nresource-lists are defined in the ",(0,i.jsx)(t.a,{href:"/calico/latest/reference/resources/overview",children:"libcalico API"}),' and there is a resource-list defined for\neach resource type. A resource-list contains an Items field which is itself a slice of resources. Thus, to output\nthe "Name" field from the supplied data, it is necessary to enumerate over the slice of resource-lists and the items\nwithin that list.']}),"\n",(0,i.jsx)(t.p,{children:"Example:"}),"\n",(0,i.jsx)(t.pre,{children:(0,i.jsx)(t.code,{className:"language-bash",children:'bin/calicoctl get hostEndpoint --output=go-template="{{range .}}{{range .Items}}{{.ObjectMeta.Name}},{{end}}{{end}}"\nendpoint1,eth0,\n'})}),"\n",(0,i.jsx)(t.h2,{id:"see-also",children:"See also"}),"\n",(0,i.jsxs)(t.ul,{children:["\n",(0,i.jsxs)(t.li,{children:[(0,i.jsx)(t.a,{href:"/calico/latest/operations/calicoctl/install",children:"Installing calicoctl"}),"."]}),"\n",(0,i.jsxs)(t.li,{children:[(0,i.jsx)(t.a,{href:"/calico/latest/reference/resources/overview",children:"Resources"})," for details on all valid resources, including file format\nand schema"]}),"\n",(0,i.jsxs)(t.li,{children:[(0,i.jsx)(t.a,{href:"/calico/latest/reference/resources/networkpolicy",children:"NetworkPolicy"})," for details on the Calico selector-based policy model"]}),"\n"]})]})}function p(e={}){let{wrapper:t}={...(0,s.a)(),...e.components};return t?(0,i.jsx)(t,{...e,children:(0,i.jsx)(d,{...e})}):d(e)}},36870:function(e,t,n){n.d(t,{Z:()=>c,a:()=>l});var o=n(84449);let i={},s=o.createContext(i);function l(e){let t=o.useContext(s);return o.useMemo(function(){return"function"==typeof e?e(t):{...t,...e}},[t,e])}function c(e){let t;return t=e.disableParentContext?"function"==typeof e.components?e.components(i):e.components||i:l(e.components),o.createElement(s.Provider,{value:t},e.children)}}}]);
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.