نسخه آنلاین در حال بارگذاری زمان... تهران: ۲۶°C
۲۸ کاربر آنلاین

PNo.30Light

نشریه تخصصی هوش مصنوعی، سیستم‌های سرور و مهندسی داده

تازه ترین‌ها
زیرساخت و سرور
زمان مطالعه: ۲۱ دقیقه ۰ بازدید

Cilium: شبکه، امنیت و Observability مبتنی بر eBPF در Kubernetes — راهنمای کامل

نویسنده: تحریریه فنی P30Light
Cilium: شبکه، امنیت و Observability مبتنی بر eBPF در Kubernetes — راهنمای کامل
✦ خلاصه نکات کلیدی مقاله
  • Cilium CNI مبتنی بر eBPF است — networking، policy L3-L7، LB و observability در kernel، بدون iptables chain.
  • Hubble flow-level visibility می‌دهد؛ Service Mesh با Envoy per-node (نه per-pod sidecar) + WireGuard encryption.
  • CNCF Graduated (اولین CNI) — default در GKE Dataplane V2، Azure CNI Powered by Cilium، و greenfield EKS.

شبکه Kubernetes سال‌ها روی iptables و kube-proxy سوار بود: هر Service یک chain rule، هر scale-out یک به‌روزرسانی، هر policy یک IP:port که با churn میکروسرویس stale می‌شود.

وقتی cluster به هزاران Pod، L7 policy (HTTP path/method)، observability بدون sidecar، یا multi-cluster identity می‌رسد — Calico و Flannel کافی نیستند؛ Istio sidecar tax سنگین است.

Cilium پاسخ نسل بعد است:

Cloud Native, eBPF-based Networking, Observability, and Security

یعنی برنامه‌های eBPF مستقیم در Linux kernel — packet processing، load balancing، network policy و telemetry بدون تغییر application و بدون iptables explosion.

پروژه توسط Isovalent (اکنون بخشی از Cisco) ساخته شد، اکتبر ۲۰۲۳ اولین CNI با CNCF Graduation شد، و امروز در GKE Dataplane V2، Azure CNI Powered by Cilium و clusterهای EKS greenfield به‌صورت native offer می‌شود.


مشکل مدل شبکه سنتی Kubernetes

مدل iptables/kube-proxy:
Pod scale → rule table بزرگ‌تر → latency ↑
IP churn → NetworkPolicy stale
L7 HTTP path → نیاز sidecar proxy per pod
Observability → agent + sidecar + sampling
مشکلiptables / kube-proxyCilium eBPF
Scale rule tableO(n) traversalHash map lookup
IdentityIP address (ephemeral)Security Identity (label-based)
L7 policySidecar per podKernel + per-node Envoy
kube-proxyiptables/IPVSeBPF socket-level LB
Observabilityaddon جداHubble built-in
Encryptionmanual / meshWireGuard / IPSec native
Multi-clusterپیچیدهCluster Mesh

Cilium چیست؟

Cilium یک پلتفرم open-source برای:

  • CNI — Pod networking (overlay VXLAN/Geneve یا native routing)
  • Network Policy — L3/L4/L7 identity-aware
  • Load Balancing — جایگزین kube-proxy با eBPF
  • Observability — Hubble flows، service map، DNS/HTTP metrics
  • Service Mesh — traffic control، mTLS، Gateway API بدون sidecar per pod
  • Multi-cluster — Cluster Mesh با global service discovery

Repo: github.com/cilium/cilium — ۲۵K+ stars

Docs: docs.cilium.io


eBPF: موتور Cilium

eBPF (extended Berkeley Packet Filter) اجازه می‌دهد برنامه‌های verified در kernel اجرا شوند — بدون kernel module و بدون restart.

Cilium در hook pointهای مختلف attach می‌کند:

Hookکاربرد
XDPearliest ingress — DDoS mitigation، north-south LB با throughput بالا
TC (Traffic Control)L3/L4 policy enforce، NAT، routing
socket / sockopsredirect L7 traffic به Envoy per-node
cgroupsocket-level LB (kube-proxy replacement)
Packet ingress


  [ XDP ] ──► drop / LB / DSR


  [ TC ingress ] ──► identity lookup → policy allow/drop


  Pod / socket


  [ TC egress ] ──► egress policy + SNAT


  [ Hubble ] ──► flow record (verdict, identity, L7 metadata)

نتیجه: policy evaluation در nanoseconds — نه traverse هزاران iptables rule.


معماری Cilium

اجزای control plane

┌─────────────────────────────────────────────────────────┐
│              Kubernetes API Server                       │
│   (NetworkPolicy, CiliumNetworkPolicy, CiliumNode, …)   │
└────────────────────────┬────────────────────────────────┘

         ┌───────────────┼───────────────┐
         ▼               ▼               ▼
  ┌─────────────┐ ┌─────────────┐ ┌─────────────┐
  │   cilium    │ │   cilium    │ │   cilium    │  ← DaemonSet (per node)
  │   agent     │ │   agent     │ │   agent     │
  └──────┬──────┘ └──────┬──────┘ └──────┬──────┘
         │               │               │
         ▼               ▼               ▼
    eBPF maps        eBPF maps        eBPF maps
    (policy, LB,     (identity,       (routing,
     conntrack)       endpoints)       ipcache)


  ┌─────────────┐     ┌─────────────┐
  │   cilium    │     │   Hubble    │
  │  operator   │     │ Relay + UI  │
  └─────────────┘     └─────────────┘
Componentنقش
cilium agentDaemonSet روی هر node — compile/load eBPF، endpoint management
cilium operatorCluster-wide: IPAM، CRD reconcile، Envoy config
cilium-envoyL7 proxy یک instance per node (نه per pod)
Hubble Relayaggregate flows از agents
Hubble UIservice dependency map

Security Identity

به‌جای IP، Cilium به هر Pod یک numeric identity می‌دهد — hash از labels + namespace + service account.

  • Pod جدید → identity جدید → BPF maps در همه nodeها update
  • Policy روی identity است — نه IP که هر ۳۰ ثانیه عوض می‌شود
  • Hubble هر flow را با source/destination identity log می‌کند

CNI: حالت‌های networking

از docs — CNI:

Modeتوضیحمناسب
Overlay (VXLAN/Geneve)tunnel بین nodeهاهر infrastructure — فقط IP connectivity لازم
Native routingLinux routing tablecloud VPC با route به Pod CIDR
BGPadvertise Pod CIDRon-prem، bare-metal، ToR integration

Dual-stack IPv4/IPv6، Direct Server Return (DSR) برای LB، Maglev consistent hashing — همه در datapath eBPF.


جایگزینی kube-proxy

kube-proxy با iptables/IPVS Service VIP را به Pod IP map می‌کند — با scale bottleneck می‌شود.

Cilium با kubeProxyReplacement=true:

  • Load balancing در eBPF hash table
  • Socket-level rewrite در connect() — بدون per-packet NAT
  • XDP برای north-south throughput بالا
# Helm flag
--set kubeProxyReplacement=true

پس از migrate، DaemonSet kube-proxy را حذف کنید — CPU و latency بهبود محسوس (به‌خصوص p99 تحت churn).


Network Policy: L3 تا L7

Kubernetes NetworkPolicy (سازگار)

Cilium NetworkPolicy استاندارد K8s را enforce می‌کند — drop-in replacement برای Calico policy mode.

CiliumNetworkPolicy (CNP) — قدرت واقعی

L3/L4 — label selector + port:

apiVersion: cilium.io/v2
kind: CiliumNetworkPolicy
metadata:
  name: api-server-policy
  namespace: production
spec:
  endpointSelector:
    matchLabels:
      app: api-server
  ingress:
    - fromEndpoints:
        - matchLabels:
            app: frontend
      toPorts:
        - ports:
            - port: "8080"
              protocol: TCP
  egress:
    - toEndpoints:
        - matchLabels:
            app: postgres
      toPorts:
        - ports:
            - port: "5432"
              protocol: TCP
    - toEndpoints:
        - matchLabels:
            k8s:io.kubernetes.pod.namespace: kube-system
      toPorts:
        - ports:
            - port: "53"
              protocol: UDP
              rules:
                dns:
                  - matchPattern: "*"

L7 HTTP — method و path (بدون sidecar per pod):

apiVersion: cilium.io/v2
kind: CiliumNetworkPolicy
metadata:
  name: api-server-l7
  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/.*
              - method: POST
                path: /api/v1/orders

DNS / FQDN egresstoFQDNs برای APIهای خارجی:

  egress:
    - toFQDNs:
        - matchName: api.stripe.com
        - matchPattern: "*.github.com"
      toPorts:
        - ports:
            - port: "443"
              protocol: TCP

CiliumClusterwideNetworkPolicy (CCNP) — default-deny cluster-wide baseline.

Zero Trust workflow

  1. Hubble observe — ببینید Pod واقعاً با چه کسی صحبت می‌کند
  2. Allowlist policy بنویسید بر اساس flow واقعی
  3. Enforce — default-deny + explicit allow
  4. Alert روی policy drop در Prometheus/Hubble

Hubble: Observability

Hubble لایه observability Cilium است — built on eBPF، بدون sidecar agent.

چه سوالاتی جواب می‌دهد؟

دستهمثال
Service mapچه service با چه service ای صحبت می‌کند؟
Networkکدام connection fail شده — DNS؟ TCP timeout؟
Applicationrate 5xx، latency p95/p99 بین serviceها
Securityکدام flow توسط policy block شده؟ egress خارج cluster؟

CLI

# نصب hubble CLI
brew install hubble

# port-forward به relay
kubectl port-forward -n kube-system svc/hubble-relay 4245:80 &

# observe flows
hubble observe --namespace production
hubble observe --pod api-server --protocol http
hubble observe --verdict DROPPED

# service dependency
hubble status

UI

# با Helm
--set hubble.enabled=true
--set hubble.relay.enabled=true
--set hubble.ui.enabled=true

Service map real-time — ideal برای debug و policy authoring.


Service Mesh (Sidecar-Free)

Cilium Service Mesh بدون inject sidecar به هر pod:

Layerپیاده‌سازی
L3/L4eBPF — mTLS identity، policy، LB
L7Envoy per-node via sockops redirect
EncryptionWireGuard یا IPSec transparent بین nodeها
Ingress/GatewayGateway API data plane

WireGuard encryption

# Helm
--set encryption.enabled=true
--set encryption.type=wireguard

Traffic بین nodeها encrypt — بدون certificate management per pod که Istio می‌خواهد.

Gateway API

Cilium as Gateway API implementation — Ingress، traffic split، TLS termination declarative با CRDهای Kubernetes-native. با cert-manager برای TLS Secret integrate می‌شود.

Cilium vs Istio

Cilium SMIstio (sidecar/ambient)
OverheadeBPF + 1 Envoy/nodesidecar per pod یا ambient ztunnel
L7 routing/retriesمحدودترکامل (VirtualService)
Policy L7✅ CNP✅ AuthorizationPolicy
mTLSWireGuard / IPSecworkload mTLS
ObservabilityHubble nativePrometheus + Jaeger
Operational complexityپایین‌تربالاتر

قاعده: اگر network policy + encryption + observability می‌خواهید → Cilium. اگر advanced traffic management (circuit breaker، fault injection، external auth) → Istio ambient.


Cluster Mesh

Cluster Mesh — چند cluster Kubernetes را به یک fabric وصل می‌کند:

  • Global service discoverycurl backend.default.svc.global از cluster دیگر
  • Unified identity — policy across clusters
  • Failover — backend در cluster B اگر A down باشد
 Cluster A (eu-west)          Cluster B (us-east)
 ┌─────────────────┐         ┌─────────────────┐
 │  Cilium + Pods  │◄───────►│  Cilium + Pods  │
 │  clustermesh    │  tunnel │  clustermesh    │
 └─────────────────┘         └─────────────────┘
         │                           │
         └───── Global Services ─────┘

برای multi-region، hybrid cloud، DR active-active — بدون VPN دستی per service.


Egress Gateway

Egress Gateway — traffic خروجی Pod از IP ثابت node مشخص exit کند:

  • whitelist در firewall خارج cluster
  • audit egress per team
  • compliance (همه egress از gateway مشخص)
apiVersion: cilium.io/v2
kind: CiliumEgressGatewayPolicy
metadata:
  name: finance-egress
spec:
  selectors:
    - podSelector:
        matchLabels:
          team: finance
  destinationCIDRs:
    - 0.0.0.0/0
  egressGateway:
    nodeSelector:
      matchLabels:
        egress-gateway: "true"
    egressIP: 10.0.50.100

BGP و Datacenter

Cilium BGP control plane — advertise Pod CIDR و Service IP به ToR/router:

  • bare-metal Kubernetes
  • on-prem بدون cloud LB
  • integration با L2 Announcements برای LoadBalancer IP

نصب Cilium با Helm

از Installation using Helm:

پیش‌نیاز

  • Kubernetes 1.27+ (برای v1.20)
  • Linux kernel ≥ 5.10 (eBPF features)
  • Helm 3

نصب production-ready

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

helm install cilium cilium/cilium \
  --version 1.20.1 \
  --namespace kube-system \
  --set kubeProxyReplacement=true \
  --set hubble.enabled=true \
  --set hubble.relay.enabled=true \
  --set hubble.ui.enabled=true \
  --set operator.prometheus.enabled=true \
  --set prometheus.enabled=true

OCI (توصیه):

helm install cilium oci://quay.io/cilium/charts/cilium \
  --version 1.20.1 \
  --namespace kube-system \
  --set kubeProxyReplacement=true \
  --set hubble.enabled=true

Validate

cilium status --wait
cilium connectivity test
kubectl -n kube-system get pods -l k8s-app=cilium

Star Wars Demo

برای یادگیری policy — Getting Started with Star Wars Demo در docs.


Migrate از CNI دیگر

از Migrating a cluster to Cilium:

  1. Cilium را parallel نصب کنید (با chaining یا secondary CNI — بسته به distro)
  2. یا blue/green node pool — nodeهای جدید با Cilium
  3. NetworkPolicy را به CNP migrate
  4. kube-proxy را disable پس از validate LB
  5. CNI قدیمی را uninstall

روی cluster production بدون plan و rollback migrate in-place نکنید.


مقایسه با CNI/Mesh دیگر

FlannelCalicoKube-OVNCilium
سادگیمتوسطپیچیدهمتوسط
Policy L3-L4
Policy L7محدودمحدود
eBPF datapathoptional❌ (OVS)
Observabilitybasicmoderate✅ Hubble
Service Mesh
Multi-tenant VPC
KubeVirt underlay

Cilium + Kube-OVN — use case متفاوت: Kube-OVN برای VPC/underlay enterprise؛ Cilium برای eBPF policy/observability/mesh. بعضی stackها chaining می‌کنند؛ معمولاً یک CNI primary انتخاب می‌شود.


چه زمانی Cilium؟

✅ مناسب

  • cluster جدید ۲۰۲۶ — default CNI توصیه‌شده
  • Zero Trust network — identity policy L7
  • Observability بدون sidecar tax
  • kube-proxy replacement در scale بالا
  • Multi-cluster با Cluster Mesh
  • Encryption WireGuard بین nodeها
  • Gateway API ingress
  • GitOps (Argo CD) — CNP YAML در Git

❌ کمتر مناسب

وضعیتجایگزین
cluster minimal dev (kind single-node)Flannel/kindnet
VPC multi-tenant با CIDR overlapKube-OVN
kernel قدیمی (< 4.19)Calico iptables
L7 traffic management پیچیده (retry, fault inject)Istio ambient
Windows node networkingCilium محدود — Calico

Cilium در stack P30Light

Internet


Ingress (Gateway API / nginx)


Cilium CNI + Network Policy

    ├── Hubble (flow observability)
    ├── WireGuard (node encryption)
    ├── [cert-manager](/blog/cert-manager-kubernetes-tls-certificates/) TLS
    └── [Argo CD](/blog/argo-project-kubernetes-gitops-cicd/) GitOps

Platform team: CNP default-deny + Hubble observe قبل از enforce.


Troubleshooting

# وضعیت agent
cilium status
cilium status --verbose

# endpoint list
cilium endpoint list

# policy
cilium policy get
cilium policy selectors

# BPF maps
cilium bpf policy list

# connectivity
cilium connectivity test

# Hubble drops
hubble observe --verdict DROPPED --namespace production

# لاگ agent
kubectl logs -n kube-system -l k8s-app=cilium -f
علامتعلتfix
Pod no networkagent not readycilium status — kernel/eBPF
Policy dropCNP too stricthubble observe --verdict DROPPED
Service unreachablekube-proxy conflictkubeProxyReplacement + remove kube-proxy
L7 policy failEnvoy not runningcheck cilium-envoy DaemonSet
DNS egress blockmissing toFQDNsadd DNS policy rule port 53
High CPUdebug enabledreduce Hubble verbosity

Performance و Production

از Performance & Scalability:

  • eBPF policy: O(1) lookup vs iptables O(n)
  • XDP north-south: million+ pps per node
  • Maglev consistent hashing — minimal disruption on scale
  • Prometheus metrics: cilium_agent_*, hubble_*

Best practices:

  • kernel ≥ 5.10 LTS
  • kubeProxyReplacement=true برای cluster جدید
  • Hubble relay + UI در staging/production
  • CCNP default-deny + namespace CNP allowlist
  • observe-before-enforce با Hubble
  • regular cilium connectivity test در CI/CD
  • upgrade با Upgrade Guide — یک minor version at a time

جمع‌بندی

بدون Ciliumبا Cilium
iptables kube-proxyeBPF LB + policy
IP-based policyIdentity-based security
sidecar observabilityHubble kernel flows
Istio برای L7 + mTLSCNP L7 + WireGuard
multi-cluster manualCluster Mesh
blind network debugservice map + verdict logs

Cilium دیگر «فقط یک CNI» نیست — پلتفرم networking + security + observability برای Kubernetes است. با eBPF در kernel، sidecar tax را حذف می‌کند و همان‌جا policy L7 و encryption را enforce می‌کند.

برای cluster greenfield در ۲۰۲۶، Cilium strong default است — مخصوصاً اگر Hubble و zero-trust network در roadmap دارید.

قدم بعدی

  1. Helm install روی staging cluster
  2. cilium connectivity test — baseline سالم
  3. Hubble UI — service map را ببینید
  4. یک CiliumNetworkPolicy L4 + L7 HTTP تست
  5. hubble observe --verdict DROPPED — policy tuning
  6. kubeProxyReplacement=true — kube-proxy را حذف و LB را benchmark کنید
  7. WireGuard encryption — enable در non-prod و latency measure

منابع:


منتشر شده در P30Light — بخش زیرساخت سرور و Cloud Native.

لینک گزارش با موفقیت کپی گردید!