본문 바로가기
네트워크 (LAN,WAN)

Cilium & eBPF 기반 차세대 Kubernetes 고성능 네트워킹과 보안 플랫폼

by 날으는물고기 2025. 6. 23.

Cilium & eBPF 기반 차세대 Kubernetes 고성능 네트워킹과 보안 플랫폼

728x90

Cilium은 eBPF(extended Berkeley Packet Filter) 기반의 데이터플레인을 사용하는 오픈소스 네트워킹, 관찰성, 보안 솔루션입니다. 쿠버네티스와 같은 컨테이너 오케스트레이션 플랫폼에서 네트워크 연결성, 보안, 로드 밸런싱을 제공하며, CNCF(Cloud Native Computing Foundation)의 Graduated 프로젝트로 인정받은 성숙한 기술입니다.

Cilium의 특징

1. 고성능 네트워킹

  • eBPF를 활용한 커널 레벨 패킷 처리
  • kube-proxy를 완전히 대체 가능
  • 거의 무제한의 확장성

2. 강력한 보안

  • L3-L7 계층의 세밀한 네트워크 정책
  • 신원 기반 보안 모델
  • API 레벨 보안 제어

3. 뛰어난 관찰성

  • Hubble을 통한 실시간 네트워크 가시성
  • 서비스 의존성 맵
  • 상세한 메트릭과 로그
300x250

핵심 기술: eBPF

eBPF는 Cilium의 핵심 기술로, Linux 커널 내에서 안전하게 프로그램을 실행할 수 있게 해주는 혁신적인 기술입니다.

eBPF의 장점

# eBPF의 주요 이점
성능:
  - 커널 레벨에서 직접 실행
  - 사용자 공간과 커널 공간 간 컨텍스트 스위칭 최소화
  - XDP(eXpress Data Path) 지원으로 초고속 패킷 처리

유연성:
  - 런타임에 동적으로 프로그램 삽입/제거
  - 커널 재컴파일 불필요
  - 다양한 후크 포인트 제공

안정성:
  - 커널 검증기를 통한 안전성 보장
  - 격리된 실행 환경
  - 시스템 크래시 방지

eBPF 프로그램 예시

// 간단한 eBPF 프로그램 예시
#include <linux/bpf.h>
#include <linux/if_ether.h>
#include <linux/ip.h>

SEC("xdp")
int xdp_drop_tcp_port_80(struct xdp_md *ctx) {
    void *data_end = (void *)(long)ctx->data_end;
    void *data = (void *)(long)ctx->data;

    // 이더넷 헤더 파싱
    struct ethhdr *eth = data;
    if ((void *)(eth + 1) > data_end)
        return XDP_PASS;

    // IP 헤더 체크
    if (eth->h_proto != htons(ETH_P_IP))
        return XDP_PASS;

    // TCP 포트 80 트래픽 드롭
    // ... (상세 구현)

    return XDP_DROP;
}

네트워킹 모델

Cilium은 두 가지 주요 네트워킹 모델을 지원합니다.

Overlay 모드

# cilium-config.yaml
apiVersion: v1
kind: ConfigMap
metadata:
  name: cilium-config
  namespace: kube-system
data:
  tunnel: "vxlan"  # 또는 "geneve"
  enable-ipv4: "true"
  enable-ipv6: "false"

장점

  • 최소한의 인프라 요구사항
  • 거의 모든 네트워크 환경에서 작동
  • 간단한 설정

사용 시나리오

  • 클라우드 환경에서 제한된 네트워크 권한
  • 멀티 클라우드 환경
  • 빠른 POC 구성

Native Routing 모드

# cilium-config.yaml
apiVersion: v1
kind: ConfigMap
metadata:
  name: cilium-config
  namespace: kube-system
data:
  tunnel: "disabled"
  ipam: "kubernetes"
  enable-endpoint-routes: "true"
  auto-direct-node-routes: "true"

장점

  • 오버헤드 최소화
  • 최대 성능
  • 기존 네트워크 인프라와 통합

사용 시나리오

  • 온프레미스 환경
  • BGP 라우팅 사용 환경
  • 고성능이 필요한 워크로드

L7 프로토콜 인식 보안

Cilium은 애플리케이션 계층(L7)에서 트래픽을 이해하고 제어할 수 있습니다.

HTTP/REST API 보안 정책

apiVersion: cilium.io/v2
kind: CiliumNetworkPolicy
metadata:
  name: api-security
  namespace: production
spec:
  endpointSelector:
    matchLabels:
      app: api-server
  ingress:
  - fromEndpoints:
    - matchLabels:
        app: frontend
    toPorts:
    - ports:
      - port: "80"
        protocol: TCP
      rules:
        http:
        - method: "GET"
          path: "/api/v1/users"
        - method: "POST"
          path: "/api/v1/users"
          headers:
          - "Authorization: Bearer .*"

Kafka 보안 정책

apiVersion: cilium.io/v2
kind: CiliumNetworkPolicy
metadata:
  name: kafka-producer-consumer
  namespace: streaming
spec:
  endpointSelector:
    matchLabels:
      app: kafka
  ingress:
  - fromEndpoints:
    - matchLabels:
        role: producer
    toPorts:
    - ports:
      - port: "9092"
        protocol: TCP
      rules:
        kafka:
        - role: "produce"
          topic: "events"
  - fromEndpoints:
    - matchLabels:
        role: consumer
    toPorts:
    - ports:
      - port: "9092"
        protocol: TCP
      rules:
        kafka:
        - role: "consume"
          topic: "events"

신원 기반 보안

전통적인 IP 기반 보안과 달리, Cilium은 워크로드의 신원(Identity)을 기반으로 보안을 적용합니다.

# 신원 기반 정책 예시
apiVersion: cilium.io/v2
kind: CiliumClusterwideNetworkPolicy
metadata:
  name: identity-based-policy
spec:
  endpointSelector:
    matchLabels:
      env: production
  ingress:
  - fromEndpoints:
    - matchLabels:
        env: production
        team: backend
  - fromEndpoints:
    - matchLabels:
        env: staging
        team: backend
    toPorts:
    - ports:
      - port: "443"
        protocol: TCP

고급 로드 밸런싱

Cilium은 eBPF 해시 테이블을 사용하여 효율적인 로드 밸런싱을 제공합니다.

DSR (Direct Server Return) 설정

apiVersion: v1
kind: Service
metadata:
  name: web-service
  annotations:
    service.cilium.io/mode: "dsr"
spec:
  type: LoadBalancer
  selector:
    app: web
  ports:
  - port: 80
    targetPort: 8080

Maglev 일관된 해싱

apiVersion: v1
kind: ConfigMap
metadata:
  name: cilium-config
  namespace: kube-system
data:
  maglev-table-size: "65521"
  maglev-hash-seed: "JLfvgnHc2kaSUFaI"

대역폭 관리

EDT(Earliest Departure Time) 기반 속도 제한으로 효율적인 대역폭 관리를 제공합니다.

apiVersion: cilium.io/v2
kind: CiliumNetworkPolicy
metadata:
  name: bandwidth-limit
spec:
  endpointSelector:
    matchLabels:
      app: video-streaming
  egress:
  - toBandwidth:
      rate: "10mbit"
      burst: "15mbit"

아키텍처와 동작 원리

Cilium 컴포넌트 구조

┌─────────────────────────────────────────────────┐
│                   Control Plane                  │
├─────────────────┬───────────────┬───────────────┤
│  Cilium Agent   │ Cilium Operator│    Hubble     │
├─────────────────┴───────────────┴───────────────┤
│                  Data Plane                      │
├─────────────────────────────────────────────────┤
│                eBPF Programs                     │
├─────────────────────────────────────────────────┤
│              Linux Kernel (>= 4.19)              │
└─────────────────────────────────────────────────┘

패킷 처리 흐름

  1. Ingress 트래픽 외부 트래픽 → XDP/TC eBPF → 신원 확인 → 정책 평가 → 로드 밸런싱 → Pod
  2. Egress 트래픽 Pod → TC eBPF → 신원 부여 → 정책 평가 → NAT/Masquerade → 외부

설치 및 구성

사전 요구사항

# 커널 버전 확인 (>= 4.19)
uname -r

# 필수 커널 모듈 확인
lsmod | grep -E "bpf|xdp"

# 마운트 포인트 확인
mount | grep /sys/fs/bpf

Helm을 통한 설치

# Helm repo 추가
helm repo add cilium https://helm.cilium.io/

# 기본 설치
helm install cilium cilium/cilium --version 1.17.4 \
  --namespace kube-system \
  --set operator.replicas=2 \
  --set ipam.mode=kubernetes

# 고급 설치 (Hubble 포함)
helm install cilium cilium/cilium --version 1.17.4 \
  --namespace kube-system \
  --set hubble.enabled=true \
  --set hubble.relay.enabled=true \
  --set hubble.ui.enabled=true \
  --set prometheus.enabled=true \
  --set operator.prometheus.enabled=true

설치 확인

# Cilium 상태 확인
kubectl -n kube-system exec -ti deployment/cilium-operator \
  -- cilium status --brief

# 연결성 테스트
kubectl create ns cilium-test
kubectl apply -n cilium-test \
  -f https://raw.githubusercontent.com/cilium/cilium/v1.17/examples/kubernetes/connectivity-check/connectivity-check.yaml

# 테스트 결과 확인
kubectl get pods -n cilium-test

실전 활용 예시

예시 1: 마이크로서비스 간 Zero Trust 네트워크 구성

# 1. 네임스페이스 레이블링
apiVersion: v1
kind: Namespace
metadata:
  name: microservices
  labels:
    env: production
---
# 2. 기본 거부 정책
apiVersion: cilium.io/v2
kind: CiliumNetworkPolicy
metadata:
  name: default-deny
  namespace: microservices
spec:
  endpointSelector: {}
  ingress:
  - {}
  egress:
  - toEntities:
    - kube-apiserver
  - toEndpoints:
    - matchLabels:
        k8s:io.kubernetes.pod.namespace: kube-system
        k8s:k8s-app: kube-dns
    toPorts:
    - ports:
      - port: "53"
        protocol: UDP
---
# 3. 서비스별 세밀한 정책
apiVersion: cilium.io/v2
kind: CiliumNetworkPolicy
metadata:
  name: frontend-policy
  namespace: microservices
spec:
  endpointSelector:
    matchLabels:
      app: frontend
  ingress:
  - fromEndpoints:
    - matchLabels:
        app: gateway
    toPorts:
    - ports:
      - port: "3000"
        protocol: TCP
  egress:
  - toEndpoints:
    - matchLabels:
        app: backend-api
    toPorts:
    - ports:
      - port: "8080"
        protocol: TCP
      rules:
        http:
        - method: "GET"
          path: "/api/v1/.*"
        - method: "POST"
          path: "/api/v1/orders"

예시 2: 멀티 클러스터 메시 구성

# 클러스터 1 설정
helm install cilium cilium/cilium --version 1.17.4 \
  --namespace kube-system \
  --set cluster.name=cluster1 \
  --set cluster.id=1 \
  --set ipam.mode=cluster-pool \
  --set ipam.operator.clusterPoolIPv4PodCIDRList="10.1.0.0/16"

# 클러스터 2 설정
helm install cilium cilium/cilium --version 1.17.4 \
  --namespace kube-system \
  --set cluster.name=cluster2 \
  --set cluster.id=2 \
  --set ipam.mode=cluster-pool \
  --set ipam.operator.clusterPoolIPv4PodCIDRList="10.2.0.0/16"

# 클러스터 메시 활성화
cilium clustermesh enable --service-type LoadBalancer
cilium clustermesh connect --destination-endpoint <CLUSTER2_ENDPOINT>

예시 3: 고급 L7 보안 정책

# gRPC 서비스 보호
apiVersion: cilium.io/v2
kind: CiliumNetworkPolicy
metadata:
  name: grpc-policy
  namespace: production
spec:
  endpointSelector:
    matchLabels:
      app: grpc-server
  ingress:
  - fromEndpoints:
    - matchLabels:
        app: grpc-client
    toPorts:
    - ports:
      - port: "50051"
        protocol: TCP
      rules:
        l7proto: grpc
        l7:
        - path: "/productcatalog.ProductCatalog/GetProduct"
        - path: "/productcatalog.ProductCatalog/ListProducts"

모니터링과 트러블슈팅

Hubble을 통한 가시성

# Hubble CLI 설치
export HUBBLE_VERSION=$(curl -s https://raw.githubusercontent.com/cilium/hubble/master/stable.txt)
curl -L --remote-name-all https://github.com/cilium/hubble/releases/download/$HUBBLE_VERSION/hubble-linux-amd64.tar.gz
tar xvfz hubble-linux-amd64.tar.gz
sudo mv hubble /usr/local/bin/

# Hubble 포트 포워딩
kubectl port-forward -n kube-system deployment/hubble-relay 4245:4245

# 실시간 플로우 관찰
hubble observe --follow

# 특정 네임스페이스 트래픽 필터링
hubble observe --namespace production --protocol http

# HTTP 에러 모니터링
hubble observe --http-status 500-599

Prometheus 메트릭

# ServiceMonitor 설정
apiVersion: monitoring.coreos.com/v1
kind: ServiceMonitor
metadata:
  name: cilium-metrics
  namespace: kube-system
spec:
  selector:
    matchLabels:
      app.kubernetes.io/name: cilium-agent
  endpoints:
  - port: metrics
    interval: 30s
    path: /metrics

주요 메트릭

  • cilium_endpoint_count: 엔드포인트 수
  • cilium_policy_count: 활성 정책 수
  • cilium_drop_count_total: 드롭된 패킷 수
  • cilium_forward_count_total: 포워딩된 패킷 수
  • cilium_bpf_map_ops_total: BPF 맵 작업 수

트러블슈팅 명령어

# Cilium 상태 전체 확인
cilium status --verbose

# 엔드포인트 목록 및 상태
cilium endpoint list

# 정책 적용 상태 확인
cilium policy get

# BPF 맵 확인
cilium bpf lb list
cilium bpf endpoint list

# 연결성 디버깅
cilium-dbg debuginfo
cilium connectivity test

# 특정 Pod의 정책 추적
cilium policy trace --src-endpoint <ENDPOINT_ID> --dst-endpoint <ENDPOINT_ID>

Cilium은 eBPF를 활용하여 클라우드 네이티브 환경에서 네트워킹, 보안, 관찰성을 혁신적으로 개선하는 강력한 솔루션입니다.

주요 이점 정리

  1. 성능: eBPF 기반으로 커널 레벨에서 고성능 처리
  2. 보안: L3-L7 계층의 세밀한 정책과 신원 기반 보안
  3. 확장성: 거의 무제한의 확장성과 효율적인 리소스 사용
  4. 관찰성: Hubble을 통한 실시간 가시성과 디버깅
  5. 유연성: 다양한 네트워킹 모드와 통합 옵션

도입 시 고려사항

  • 커널 버전: Linux 4.19 이상 필요
  • 학습 곡선: eBPF와 Cilium 개념 이해 필요
  • 리소스: 각 노드에 Cilium Agent 실행으로 추가 리소스 필요
  • 네트워크 정책: 기존 NetworkPolicy와의 차이점 이해

 

Cilium은 단순한 CNI를 넘어 클라우드 네이티브 인프라의 핵심 구성 요소로 자리매김하고 있으며, 특히 마이크로서비스 아키텍처와 제로 트러스트 보안 모델을 구현하는 데 이상적인 솔루션입니다.

추가 리소스

728x90
그리드형(광고전용)

댓글