본문으로 바로가기 본문 바로가기
WIKI 기술 지식 베이스

calicoctl get

원문 보기 위키 갱신

이 섹션은 calicoctl get 명령을 설명해요. 리소스를 조회하는 가장 기본이 되는 명령이라, 옵션과 출력 형식을 알아두면 어디서든 써먹을 수 있어요.

출처: 문서

본문

calicoctl 명령 전체 목록은 calicoctl command line interface user reference를 읽어 보세요.

SECONDARY: 특정 리소스 타입에서 사용할 수 있는 액션은 Calico Enterprise가 사용하는 데이터스토어(Kubernetes API)에 따라 제한될 수 있어요. 각 리소스 타입의 세부 사항은 Resources 섹션을 참고해요.

Displaying the help text for 'calicoctl get' command

calicoctl get --help를 실행하면 이 명령의 도움말 메뉴가 아래와 같이 표시돼요.

Usage:
  calicoctl get ( (<KIND> [<NAME...>]) |
                --filename=<FILENAME>) [--recursive] [--skip-empty]
                [--output=<OUTPUT>] [--config=<CONFIG>] [--namespace=<NS>] [--all-namespaces]
                [--show-policy-activities]

Examples:
  # List all policy in default output format.
  calicoctl get policy

  # List specific policies in YAML format
  calicoctl get -o yaml policy my-policy-1 my-policy-2

Options:
  -h --help                    Show this screen.
  -f --filename=<FILENAME>     Filename to use to get the resource.  If set to
                               "-" loads from stdin. If filename is a directory, this command is
                               invoked for each .json .yaml and .yml file within that directory,
                               terminating after the first failure.
  -R --recursive               Process the filename specified in -f or --filename recursively.
     --skip-empty              Do not error if any files or directory specified using -f or --filename contain no
                               data.
  -o --output=<OUTPUT FORMAT>  Output format.  One of: yaml, json, ps, wide,
                               custom-columns=..., go-template=...,
                               go-template-file=...   [Default: ps]
  -c --config=<CONFIG>         Path to the file containing connection
                               configuration in YAML or JSON format.
                               [default: /etc/calico/calicoctl.cfg]
  -n --namespace=<NS>          Namespace of the resource.
                               Only applicable to NetworkPolicy, NetworkSet, and WorkloadEndpoint.
                               Uses the default namespace if not specified.
  -A --all-namespaces          If present, list the requested object(s) across
                               all namespaces.
  --export                     If present, returns the requested object(s) stripped of
                               cluster-specific information. This flag will be ignored
                               if <NAME> is not specified.
  --context=<context>          The name of the kubeconfig context to use.
  --show-policy-activities     Show policy activity timestamps (only for policy
                               resources, table output).

Description:
  The get command is used to display a set of resources by filename or stdin,
  or by type and identifiers.  JSON and YAML formats are accepted for file and
  stdin format.

  Valid resource types are:

    - bfdconfiguration
    - bgpconfiguration
    - bgpfilter
    - bgppeer
    - clusterinformation
    - egressgatewaypolicy
    - externalnetwork
    - felixconfiguration
    - globalnetworkpolicy
    - globalnetworkset
    - globalthreatfeed
    - hostendpoint
    - ippool
    - ipreservation
    - kubecontrollersconfiguration
    - licensekey
    - networkpolicy
    - networkset
    - node
    - packetcapture
    - profile
    - remoteclusterconfiguration
    - stagedglobalnetworkpolicy
    - stagedkubernetesnetworkpolicy
    - stagednetworkpolicy
    - tier
    - uisettingsgroup
    - workloadendpoint

  The resource type is case-insensitive and may be pluralized.

  Attempting to get resources that do not exist will simply return no results.

  When getting resources by type, only a single type may be specified at a
  time.  The name and other identifiers (hostname, scope) are optional, and are
  wildcarded when omitted. Thus if you specify no identifiers at all (other
  than type), then all configured resources of the requested type will be
  returned.

  By default the results are output in a ps-style table output.  There are
  alternative ways to display the data using the --output option:

    ps                    Display the results in ps-style output.
    wide                  As per the ps option, but includes more headings.
    custom-columns        As per the ps option, but only display the columns
                          that are requested in the comma-separated list.
    golang-template       Display the results using the specified golang
                          template.  This can be used to filter results, for
                          example to return a specific value.
    golang-template-file  Display the results using the golang template that is
                          contained in the specified file.
    yaml                  Display the results in YAML output format.
    json                  Display the results in JSON output format.

  Note that the data output using YAML or JSON format is always valid to use as
  input to all of the resource management commands (create, apply, replace,
  delete, get).

  Please refer to the docs at https://projectcalico.docs.tigera.io for more details on
  the output formats, including example outputs, resource structure (required
  for the golang template definitions) and the valid column names (required for
  the custom-columns option).

Options

-h --help                    Show this screen.
-f --filename=<FILENAME>     Filename to use to get the resource.  If set to
                             "-" loads from stdin.
-o --output=<OUTPUT FORMAT>  Output format.  One of: yaml, json, ps, wide,
                             custom-columns=..., go-template=...,
                             go-template-file=...   [Default: ps]
-n --namespace=<NS>          Namespace of the resource.
                             Only applicable to NetworkPolicy, NetworkSet, and WorkloadEndpoint.
                             Uses the default namespace if not specified.
-A --all-namespaces          If present, list the requested object(s) across
                             all namespaces.
--export                     If present, returns the requested object(s) stripped of
                             cluster-specific information. This flag will be ignored
                             if the resource name is not specified.
--show-policy-activities     Show policy activity timestamps (only for policy
                             resources, table output).

Showing policy activity

--show-policy-activities 플래그를 넘기면 테이블 출력에 policy-activity 타임스탬프가 덧붙여져요. 나열된 각 정책에 대해 calicoctl은 세 개의 컬럼을 추가해요:

  • LAST EVALUATED — 정책의 현재 세대(generation)가 라이브 트래픽에 마지막으로 평가된 시각이에요.
  • LAST EVALUATED (ANY GEN) — 정책의 어떤 세대(현재 또는 이전)든 마지막으로 평가된 시각이에요.
  • LAST EVALUATED GEN — LAST EVALUATED (ANY GEN) 타임스탬프가 가리키는 세대예요.

스테이지된 정책이나 시행 중인 정책이 실제 트래픽에 의해 실제로 쓰이고 있는지, 승격(promote)하거나 정리하기 전에 확인할 때 유용해요.

이 플래그는:

  • policy 종류에서만 지원돼요: globalnetworkpolicy, networkpolicy, stagedglobalnetworkpolicy, stagednetworkpolicy.
  • ps(기본값)와 wide 테이블 출력 형식에서만 지원돼요. yaml, json, custom-columns, go-template 출력에서는 지원하지 않아요.

예시 — 모든 staged global network policy의 활동 보기:

calicoctl get stagedglobalnetworkpolicies --show-policy-activities

SECONDARY: calicoctl get은 -l / --selector를 지원하지 않아요. 출력을 특정 tier나 라벨 집합으로 좁히려면, 테이블 컬럼을 보고 결과를 필터링하거나, kubectl get ... -o name으로 매칭되는 리소스 이름을 찾은 뒤 각각에 대해 calicoctl get을 호출해요.

General options

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

Output options

ps

기본 출력 형식이에요. 리소스를 고유하게 식별할 수 있을 만큼의 컬럼을 갖춘 ps 스타일 테이블로 출력해요.

각 리소스 타입에 표시되는 헤딩은 고정돼요. 대신 추가 컬럼을 보여주는 wide 옵션과, 보여줄 컬럼을 고르는 custom-columns를 사용할 수 있어요.

예시:

calicoctl get hostEndpoint

응답:

NAME          NODE
endpoint1     host1
myhost-eth0   myhost

wide

ps 형식과 비슷하지만, wide 옵션은 추가 컬럼을 포함한 ps 스타일 테이블 출력을 보여줘요.

각 리소스 타입에 표시되는 헤딩은 고정돼요. 보여줄 컬럼을 고르려면 custom-columns를 참고해요.

예시:

calicoctl get hostEndpoint --output=wide

응답:

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

custom-columns

ps 형식과 비슷하지만, custom-columns 옵션은 ps 스타일 테이블 출력을 보여주면서 출력에 표시할 컬럼의 순서 있는 쉼표 구분 목록을 사용자가 지정할 수 있게 해줘요. 각 리소스 타입의 유효한 헤딩 이름은 Resources 가이드에 문서화돼 있어요.

예시:

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

응답:

NAME        IPS
endpoint1   1.2.3.4,0:bb::aa
myhost-eth0

yaml / json

yaml과 json 옵션은 출력을 YAML 문서 목록 또는 JSON 딕셔너리로 보여줘요. 리소스 타입의 필드는 Resources 가이드에 문서화돼 있어요.

두 형식 중 무엇이든 출력 결과는 모든 리소스 관리 명령의 입력으로 쓸 수 있어요.

예시:

calicoctl get hostEndpoint --output=yaml

응답:

- apiVersion: projectcalico.org/v3
  kind: HostEndpoint
  metadata:
    labels:
      type: database
    name: endpoint1
  spec:
    node: host1
    expectedIPs:
      - 1.2.3.4
      - 0:bb::aa
    profiles:
      - prof1
      - prof2
- apiVersion: projectcalico.org/v3
  kind: HostEndpoint
  metadata:
    name: myhost-eth0
  spec:
    node: myhost
    profiles:
      - profile1

go-template / go-template-file

go-template와 go-template-file 옵션은 CLI에 문자열로 지정하거나 별도 파일에 정의한 golang 템플릿으로 출력을 보여줘요. 템플릿을 작성할 때는 템플릿에 전달되는 데이터가 resource-list의 golang 슬라이스라는 점을 유의해요. resource-list는 libcalico API에 정의되어 있고, 각 리소스 타입마다 resource-list가 하나씩 정의돼 있어요. resource-list는 그 자체가 리소스 슬라이스인 Items 필드를 갖고 있어요. 따라서 제공된 데이터에서 "Name" 필드를 출력하려면 resource-list 슬라이스와 그 안의 items를 순회해야 해요.

예시:

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

See also

더 알아보기 (Learn more)