🌍 Networking

Cilium

eBPF-based CNI

An eBPF-based Kubernetes CNI plugin and cloud-native solution providing high-performance networking, Service Mesh, Hubble observability, and NetworkPolicy.

📖 Detailed Explanation

Cilium is a Kubernetes CNI (Container Network Interface) plugin that leverages the eBPF (extended Berkeley Packet Filter) technology of the Linux kernel. It overcomes the performance limitations of traditional iptables-based networking and can process millions of packets per second by handling network packets at the kernel level. It has been adopted by major cloud vendors such as Google, AWS, and Microsoft, and its maturity has been recognized as a CNCF Graduated project.

eBPF, the core technology of Cilium, makes it possible to run sandboxed programs inside the kernel without modifying kernel source code. Through this, it performs network packet filtering, load balancing, and traffic monitoring without kube-proxy. With in-kernel routing using eBPF maps, it achieves latency that is more than 40% lower than Calico and Flannel.

Hubble is the observability component of Cilium and visualizes real-time network traffic flows. It displays service-to-service communication as a Service Map and collects L3/L4/L7-level network metrics with Prometheus. It provides application-level visibility down to DNS queries, HTTP requests, and gRPC calls, dramatically simplifying microservice debugging.

Cilium fully supports Kubernetes NetworkPolicy, and with CiliumNetworkPolicy it enables fine-grained traffic control at the L7 level (HTTP, gRPC, Kafka). Tetragon is a security observability extension of Cilium that monitors process execution, file access, and network connections in real time to detect runtime security threats. It also provides Service Mesh functionality without sidecars, reducing resource usage by more than 50% compared to Istio.

💻 Code Example

# Cilium CLI 설치 (Linux/macOS)
CILIUM_CLI_VERSION=$(curl -s https://raw.githubusercontent.com/cilium/cilium-cli/main/stable.txt)
curl -L --fail --remote-name-all \
  https://github.com/cilium/cilium-cli/releases/download/${CILIUM_CLI_VERSION}/cilium-linux-amd64.tar.gz
sudo tar xzvfC cilium-linux-amd64.tar.gz /usr/local/bin

# Helm으로 Cilium 설치
helm repo add cilium https://helm.cilium.io/
helm repo update

# 기본 설치 (kube-proxy 대체)
helm install cilium cilium/cilium --version 1.15.0 \
  --namespace kube-system \
  --set kubeProxyReplacement=true \
  --set k8sServiceHost=API_SERVER_IP \
  --set k8sServicePort=6443

# Hubble 활성화하여 설치
helm upgrade cilium cilium/cilium --version 1.15.0 \
  --namespace kube-system \
  --reuse-values \
  --set hubble.enabled=true \
  --set hubble.relay.enabled=true \
  --set hubble.ui.enabled=true

# 설치 상태 확인
cilium status --wait
cilium connectivity test  # 네트워크 연결성 테스트

# Cilium 에이전트 상태 확인
kubectl -n kube-system exec -it ds/cilium -- cilium status
kubectl -n kube-system exec -it ds/cilium -- cilium endpoint list
# CiliumNetworkPolicy - L7 HTTP 트래픽 제어
apiVersion: "cilium.io/v2"
kind: CiliumNetworkPolicy
metadata:
  name: "api-allow-get-only"
  namespace: production
spec:
  endpointSelector:
    matchLabels:
      app: api-server
  ingress:
    - fromEndpoints:
        - matchLabels:
            app: frontend
      toPorts:
        - ports:
            - port: "8080"
              protocol: TCP
          rules:
            http:
              - method: "GET"
                path: "/api/v1/users.*"
              - method: "POST"
                path: "/api/v1/auth/login"
                headers:
                  - 'Content-Type: application/json'
---
# CiliumNetworkPolicy - DNS 기반 외부 접근 제어
apiVersion: "cilium.io/v2"
kind: CiliumNetworkPolicy
metadata:
  name: "allow-external-apis"
spec:
  endpointSelector:
    matchLabels:
      app: payment-service
  egress:
    - toFQDNs:
        - matchName: "api.stripe.com"
        - matchPattern: "*.amazonaws.com"
      toPorts:
        - ports:
            - port: "443"
              protocol: TCP
---
# CiliumClusterwideNetworkPolicy - 클러스터 전체 정책
apiVersion: "cilium.io/v2"
kind: CiliumClusterwideNetworkPolicy
metadata:
  name: "deny-external-egress-default"
spec:
  endpointSelector: {}  # 모든 Pod에 적용
  egressDeny:
    - toEntities:
        - "world"  # 외부 인터넷 차단
  egress:
    - toEntities:
        - "cluster"  # 클러스터 내부만 허용
# Hubble CLI 설치
export HUBBLE_VERSION=$(curl -s https://raw.githubusercontent.com/cilium/hubble/master/stable.txt)
curl -L --fail --remote-name-all \
  https://github.com/cilium/hubble/releases/download/$HUBBLE_VERSION/hubble-linux-amd64.tar.gz
sudo tar xzvfC hubble-linux-amd64.tar.gz /usr/local/bin

# Hubble Relay 포트 포워딩
cilium hubble port-forward &

# 실시간 네트워크 플로우 모니터링
hubble observe --follow
hubble observe --namespace production --follow  # 특정 네임스페이스
hubble observe --pod production/api-server      # 특정 Pod

# HTTP 트래픽만 필터링
hubble observe --protocol http --follow
hubble observe --http-status 500 --follow       # 500 에러만
hubble observe --http-method POST --follow      # POST 요청만

# DNS 쿼리 모니터링
hubble observe --protocol dns --follow
hubble observe --verdict DROPPED --follow       # 차단된 트래픽

# 네트워크 플로우를 JSON으로 출력 (분석용)
hubble observe --output json | jq '.flow.source.labels'

# Hubble UI 접속 (localhost:12000)
cilium hubble ui

# 서비스 맵 조회
hubble observe --service-map --namespace default

🗣️ Say It Like This in Practice

💬 In an Infrastructure Architecture Design Meeting
"For the new cluster, we'll configure the CNI with Cilium. Since it's eBPF-based, service load balancing is possible without kube-proxy, and we can gain visibility into service-to-service traffic with Hubble. Pod-to-pod latency should also improve by about 30% compared to the existing Calico."
💬 In a Collaboration Meeting with the Security Team
"CiliumNetworkPolicy enables L7-level control. For example, payment-service allows only POST requests to the /api/v1/payment path, and everything else is blocked. In addition, if we also monitor runtime security events with Tetragon, we can detect suspicious process execution inside containers in real time."
💬 In an Incident Response Situation
"In Hubble, the traffic between checkout-service → inventory-service is in DROPPED status. It looks like the label selector is missing in the CiliumNetworkPolicy, so I'll check the endpoint status with cilium endpoint list and run a policy trace."

⚠️ Common Mistakes & Cautions

❌
Kernel Version Not Checked

Cilium requires Linux kernel 4.19 or later, and the latest features (Bandwidth Manager, Host Routing) require 5.10 or later. Before installation, check the kernel version with `uname -r`, and use the latest kernel image in cloud environments.

❌
Conflict with Existing CNI

When installing Cilium, the existing CNI (Flannel, Calico) must be completely removed. In particular, if the existing configuration files in the /etc/cni/net.d/ directory remain, network errors will occur. During migration, replace nodes by draining them sequentially.

❌
Mistaken Belief That NetworkPolicy Is Applied

Cilium's default mode is 'allow all'. If you do not explicitly apply a CiliumNetworkPolicy, all traffic is allowed. In production, apply a default-deny policy first, and then allow only the necessary traffic.

✅
The Right Way to Operate Cilium

Run regular connectivity tests with `cilium connectivity test`, and collect Hubble metrics with Prometheus/Grafana. Adjust the eBPF map size (--bpf-map-max) to match the cluster scale, and monitor cilium-agent memory usage.

🔗 Related Terms

📚 Learn More