명령 치트시트

명령 치트시트 (Command Cheatsheet)

Cilium을 제어하는 CLI 사용법을 빠르게 정리한 문서예요. 자주 쓰는 명령과 출력 형식, 탭 완성 설정까지 예시와 함께 살펴볼게요.

출처: Command Cheatsheet

본문

Cilium은 쉬운 커맨드라인 인터페이스로 제어돼요. 이 CLI는 단일 애플리케이션이며, command reference 가이드에서 찾을 수 있는 서브커맨드를 받아요.

$ cilium
CLI for interacting with the local Cilium Agent

Usage:
  cilium-dbg [command]

Available Commands:
  bpf                      Direct access to local eBPF maps
  cleanup                  Reset the agent state
  completion               Output shell completion code for bash
  config                   Cilium configuration options
  debuginfo                Request available debugging information from agent
  endpoint                 Manage endpoints
  identity                 Manage security identities
  kvstore                  Direct access to the kvstore
  monitor                  Monitoring
  policy                   Manage security policies
  prefilter                Manage XDP CIDR filters
  service                  Manage services & loadbalancers
  status                   Display status of daemon
  version                  Print version information

Flags:
      --config string   config file (default is $HOME/.cilium.yaml)
  -D, --debug           Enable debug messages
  -H, --host string     URI to server-side API

Use "cilium [command] --help" for more information about a command.

모든 명령과 서브커맨드에는 -h 옵션이 있어서, 해당 서브커맨드가 가진 옵션과 인자에 대한 정보를 보여줘요. 명령에 오류가 있으면 Cilium CLI는 0이 아닌 상태(non-zero status)를 반환해요.

명령 유틸리티

JSON 출력

모든 list 명령은 Cilium Daemon에서 가져온 정보를 보기 좋게 출력한 목록을 반환해요. 더 자세한 내용이 필요하면 JSON 출력을 쓸 수 있는데, JSON 출력은 전역 옵션 -o json을 쓰면 돼요.

$ cilium-dbg endpoint list -o json

또한 Cilium은 JSONPath도 지원해서 더 자세한 정보를 추출할 수 있어요. JSONPath 템플릿 참고는 Kubernetes 문서에서 찾을 수 있어요.

$ cilium-dbg endpoint list -o jsonpath='{[*].id}'
29898 38939 56326
$ cilium-dbg endpoint list -o jsonpath='{range [*]}{@.id}{"="}{@.status.policy.spec.policy-enabled}{"\n"}{end}'
29898=none
38939=none
56326=none

셸 탭 완성 (Shell Tab-completion)

bash나 zsh을 쓴다면 Cilium CLI의 서브커맨드에 대한 탭 완성을 사용할 수 있어요. 탭 완성을 설치하려면 터미널에서 다음 명령을 실행하면 돼요.

$ source <(cilium completion)

Cilium 완성이 항상 로드되도록 하려면 다음과 같이 설치해 두면 돼요.

$ echo "source <(cilium completion)" >> ~/.bashrc

명령 예시

기본 (Basics)

에이전트의 상태 확인

$ cilium-dbg status
KVStore:                Ok         Etcd: 172.17.0.3:4001
Kubernetes:             Disabled
Cilium:                 Ok         OK
NodeMonitor:            Listening for events on 2 CPUs with 64x4096 of shared memory
Cilium health daemon:   Ok
Controller Status:      6/6 healthy
Proxy Status:           OK, ip 10.15.28.238, port-range 10000-20000
Cluster health:   1/1 reachable   (2018-04-11T07:33:09Z)
$

에이전트의 상세 상태 확인:

$ cilium-dbg status --all-controllers --all-health --all-redirects
KVStore:                Ok         Etcd: 172.17.0.3:4001
Kubernetes:             Disabled
Cilium:                 Ok         OK
NodeMonitor:            Listening for events on 2 CPUs with 64x4096 of shared memory
Cilium health daemon:   Ok
Controller Status:      6/6 healthy
  Name                                 Last success   Last error   Count   Message
  kvstore-lease-keepalive              2m52s ago      never        0       no error
  ipcache-bpf-garbage-collection       2m50s ago      never        0       no error
  resolve-identity-29898               2m50s ago      never        0       no error
  sync-identity-to-k8s-pod (29898)     50s ago        never        0       no error
  sync-IPv4-identity-mapping (29898)   2m49s ago      never        0       no error
  sync-IPv6-identity-mapping (29898)   2m49s ago      never        0       no error
Proxy Status:   OK, ip 10.15.28.238, port-range 10000-20000
Cluster health:         1/1 reachable   (2018-04-11T07:32:09Z)
  Name                  IP              Reachable   Endpoints reachable
  runtime (localhost)   10.0.2.15       true        false
$

현재 에이전트 구성 가져오기

cilium-dbg config

가져온 정책 규칙 전체 목록 가져오기

cilium-dbg policy get

모니터링 (Monitoring)

cilium-dbg 데이터패스 알림 모니터링

cilium-dbg monitor

상세 출력 (활성화되면 디버그 포함)

cilium-dbg monitor -v

더 상세한 출력 (패킷 분해 포함)

cilium-dbg monitor -v -v

엔드포인트와 관련된 이벤트만 필터링

cilium-dbg monitor --related-to=<id>

Layer 7 이벤트만 필터링

cilium-dbg monitor -t L7

드롭된 패킷 이벤트만 알림 표시

cilium-dbg monitor --type drop

패킷 페이로드를 분해하지 않고, 페이로드를 hex 정보로 표시

cilium-dbg monitor -v -v --hex

연결성 (Connectivity)

클러스터 연결성 확인

cilium-health status

이 도구와 관련된 블로그 포스트도 있어요.

엔드포인트 (Endpoints)

모든 로컬 엔드포인트 목록 가져오기

cilium-dbg endpoint list

엔드포인트 속성과 상태의 상세 보기

cilium-dbg endpoint get <id>

최근 엔드포인트 로그 항목 표시

cilium-dbg endpoint log <id>

이 엔드포인트에 대한 cilium-dbg 모니터 디버그 출력 활성화

cilium-dbg endpoint config <id> Debug=true

로드밸런싱 (Loadbalancing)

로드밸런서 서비스 목록 가져오기

cilium-dbg service list

또는 bpf list를 사용해 로드밸런서 정보를 얻을 수도 있어요.

cilium-dbg bpf lb list

eBPF

verifier 이슈 로그 확인

journalctl -u cilium-dbg | grep -B20 -F10 Verifier

연결 추적(connection tracking) 항목 목록:

sudo cilium-dbg bpf ct list

연결 추적 항목 플러시:

sudo cilium-dbg bpf ct flush

Kubernetes 예시

Kubernetes 위에서 Cilium을 실행 중이라면, 단일 kubectl 명령으로 모든 cilium 엔드포인트나 정책을 나열하고 싶을 거예요. Cilium은 Kubernetes Resource Definitions를 사용해 이 모든 정보를 사용자에게 제공해요.

정책 (Policies)

Kubernetes에서는 두 종류의 정책을 사용할 수 있어요: Kubernetes Network Policy 또는 Cilium Network Policy. 둘 다 kubectl 명령으로 가져올 수 있어요.

Kubernetes Network Policy

 kubectl get netpol

Kubernetes Cilium Policy

 $ kubectl get cnp
 NAME      AGE
 rule1     3m
 $ kubectl get cnp rule1
 NAME      AGE
 rule1     3m
 $ kubectl get cnp rule1 -o json

엔드포인트 (Endpoints)

cilium이 관리하는 모든 엔드포인트 목록을 가져오려면 Cilium Endpoint 리소스를 사용하면 돼요.

$ kubectl get cep
NAME                AGE
34e299f0-b25c2fef   41s
34e299f0-dd86986c   42s
4d088f48-83e4f98d   2m
4d088f48-d04ab55f   2m
5c6211b5-9217a4d1   1m
5c6211b5-dccc3d24   1m
700e0976-6cb50b02   3m
700e0976-afd3a30c   3m
78092a35-4874ed16   1m
78092a35-4b08b92b   1m
9b74f61f-14571299   7s
9b74f61f-f9a96f4a   7s

$ kubectl get cep 700e0976-6cb50b02 -o json

$ kubectl get cep -o jsonpath='{range .items[*]}{@.status.id}{"="}{@.status.status.policy.spec.policy-enabled}{"\n"}{end}'
30391=ingress
5766=ingress
51796=none
40355=none

더 알아보기 (Learn more)