튜토리얼: Cilium으로 일반 IP 옵션 모니터링

튜토리얼: Cilium으로 일반 IP 옵션 모니터링 (Monitoring Generic IP Options with Cilium)

이 튜토리얼은 네트워크 패킷에서 임의의 IP Option을 감지·추출·모니터링하도록 Cilium을 구성하는 방법을 보여줘요. 사이드카나 상류 장비가 주입한 네트워크 메타데이터를 관찰하는 데 필수적인 기능입니다.

출처: Tutorial: Monitoring Generic IP Options with Cilium

본문

이 튜토리얼은 네트워크 패킷에서 임의의 IP Options를 감지·추출·모니터링하도록 Cilium을 구성하는 방법을 보여줘요.

Cilium v1.19 이상은 IP Options 패킷 추적을 구현하고 있어요. IP Options 추적은 특정 IP Option(Helm으로 구성)을 읽어서 추출된 데이터를 Cilium Monitor와 Hubble에 표시하는 것을 지원합니다. 이 기능은 사이드카나 상류 어플라이언스가 주입한 네트워크 메타데이터를 관찰하는 데 필수적이에요.

Cilium은 이 메타데이터를 관찰하는 역할만 담당한다는 점을 기억하세요. 애플리케이션, 사이드카, 네트워크 장비가 원하는 IP Options를 트래픽에 주입하도록 구성하는 것은 사용자의 책임입니다.

사전 준비 사항 (Prerequisites)

  • 의존성: kind, helm, docker, Hubble CLI, cilium CLI.

클러스터 설정 (Cluster Setup)

bpf.monitorTraceIPOption 플래그를 활성화한 상태로 kind 클러스터를 만들고 Cilium을 설치하세요.

1. kind 구성

다음 템플릿을 기반으로 kind-config-ip-tracing.yaml 파일을 만드세요. 그러면 2개의 노드(컨트롤 플레인 1개, 워커 1개)가 생성됩니다.

kind: Cluster
apiVersion: kind.x-k8s.io/v1alpha4
nodes:
- role: control-plane
- role: worker
networking:
  disableDefaultCNI: true

2. kind 클러스터 생성

kind create cluster --config=kind-config-ip-tracing.yaml

3. Helm 저장소 설정

아직 하지 않았다면 Cilium Helm 저장소를 추가하세요.

helm repo add cilium https://helm.cilium.io/

4. IP Option 모니터링으로 Cilium 설치

Helm으로 Cilium을 설치하세요. 여기서 핵심 플래그는 --set bpf.monitorTraceIPOption=136이에요. 이 플래그는 Cilium이 IP Option 136 패킷의 데이터를 추출하도록 구성합니다. IP option 136은 "Stream ID"를 나타내며, 이 가이드 뒷부분에서 추적 패킷을 생성하는 데 사용됩니다.

Helm Repository

helm install cilium cilium/cilium --version 1.20.2 \
   --namespace kube-system \
   --set hubble.enabled=true \
   --set hubble.relay.enabled=true \
   --set hubble.ui.enabled=true \
   --set bpf.monitorTraceIPOption=136
kubectl -n kube-system wait --for=condition=ready pod -l k8s-app=cilium --timeout=300s

OCI Registry

helm install cilium oci://quay.io/cilium/charts/cilium 1.20.2 \
   --namespace kube-system \
   --set hubble.enabled=true \
   --set hubble.relay.enabled=true \
   --set hubble.ui.enabled=true \
   --set bpf.monitorTraceIPOption=136
kubectl -n kube-system wait --for=condition=ready pod -l k8s-app=cilium --timeout=300s

수동 검증 (Manual Verification)

기능을 검증하려면 nping을 사용해 알려진 Trace ID를 패킷에 수동으로 주입하세요. 아래 예제는 엄격한 길이 요구사항을 충족하기 위해 4바이트 페이로드를 사용해요.

1. 클라이언트·서버 파드 배포

nginx 서버와 netshoot 클라이언트(nping 포함)를 배포하세요:

apiVersion: apps/v1
kind: Deployment
metadata:
  name: client
  labels:
    app: client
spec:
  replicas: 1
  selector:
    matchLabels:
      app: client
  template:
    metadata:
      labels:
        app: client
    spec:
      containers:
      - name: client
        image: nicolaka/netshoot
        command:
        - sleep
        args:
        - "infinity"
---
apiVersion: apps/v1
kind: Deployment
metadata:
  name: server
  labels:
    app: server
spec:
  replicas: 1
  selector:
    matchLabels:
      app: server
  template:
    metadata:
      labels:
        app: server
    spec:
      containers:
      - name: server
        image: nginx
        ports:
        - containerPort: 80
kubectl apply -f https://raw.githubusercontent.com/cilium/cilium/1.20.2/examples/kubernetes-ip-options/ip-options-pods.yaml

배포가 준비될 때까지 기다리세요.

kubectl rollout status deployment client
kubectl rollout status deployment server

2. 유효한 IP Options로 트래픽 트리거

클라이언트에서 서버로 nping을 실행하면서 IP Option hex 문자열을 수동으로 지정하세요.

# 1. Get the IP of the server pod
server_ip=$(kubectl get pods -l app=server -o jsonpath='{.items[0].status.podIP}')

# 2. Run nping with Option 136 (0x88)
# Format: \x88 (Type 136) \x04 (Data + header length) \x34\x21 (Data/ID)
# The data 0x3421 corresponds to decimal 13345.
# Note: Length must be exactly 2, 4 or 8 bytes of payload. Length 4 for the message indicates 2 bytes of payload
kubectl exec deployment/client -- nping --tcp -p 80 --ip-options '\x88\x04\x34\x21' -c 3 ${server_ip}

Hubble로 관찰하기 (Observing with Hubble)

트래픽이 흐르는 상태에서 Hubble CLI를 사용해 추출된 데이터를 관찰하세요.

1. Hubble 빌드 및 연결

cd hubble
make hubble
cilium hubble port-forward &

2. Trace ID로 필터링

주입된 ID 13345(hex 0x3421)로 구체적으로 필터링하세요:

./hubble observe -f --ip-trace-id 13345

client와 server 파드 사이의 흐름이 일치하는 ID로 나타나는지 확인하세요.

더 알아보기 (Learn more)