شبکه 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-proxy | Cilium eBPF |
|---|---|---|
| Scale rule table | O(n) traversal | Hash map lookup |
| Identity | IP address (ephemeral) | Security Identity (label-based) |
| L7 policy | Sidecar per pod | Kernel + per-node Envoy |
| kube-proxy | iptables/IPVS | eBPF socket-level LB |
| Observability | addon جدا | Hubble built-in |
| Encryption | manual / mesh | WireGuard / 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 | کاربرد |
|---|---|
| XDP | earliest ingress — DDoS mitigation، north-south LB با throughput بالا |
| TC (Traffic Control) | L3/L4 policy enforce، NAT، routing |
| socket / sockops | redirect L7 traffic به Envoy per-node |
| cgroup | socket-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 agent | DaemonSet روی هر node — compile/load eBPF، endpoint management |
| cilium operator | Cluster-wide: IPAM، CRD reconcile، Envoy config |
| cilium-envoy | L7 proxy یک instance per node (نه per pod) |
| Hubble Relay | aggregate flows از agents |
| Hubble UI | service 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 routing | Linux routing table | cloud VPC با route به Pod CIDR |
| BGP | advertise Pod CIDR | on-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/ordersDNS / FQDN egress — toFQDNs برای APIهای خارجی:
egress:
- toFQDNs:
- matchName: api.stripe.com
- matchPattern: "*.github.com"
toPorts:
- ports:
- port: "443"
protocol: TCPCiliumClusterwideNetworkPolicy (CCNP) — default-deny cluster-wide baseline.
Zero Trust workflow
- Hubble observe — ببینید Pod واقعاً با چه کسی صحبت میکند
- Allowlist policy بنویسید بر اساس flow واقعی
- Enforce — default-deny + explicit allow
- 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؟ |
| Application | rate 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 statusUI
# با Helm
--set hubble.enabled=true
--set hubble.relay.enabled=true
--set hubble.ui.enabled=trueService map real-time — ideal برای debug و policy authoring.
Service Mesh (Sidecar-Free)
Cilium Service Mesh بدون inject sidecar به هر pod:
| Layer | پیادهسازی |
|---|---|
| L3/L4 | eBPF — mTLS identity، policy، LB |
| L7 | Envoy per-node via sockops redirect |
| Encryption | WireGuard یا IPSec transparent بین nodeها |
| Ingress/Gateway | Gateway API data plane |
WireGuard encryption
# Helm
--set encryption.enabled=true
--set encryption.type=wireguardTraffic بین 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 SM | Istio (sidecar/ambient) | |
|---|---|---|
| Overhead | eBPF + 1 Envoy/node | sidecar per pod یا ambient ztunnel |
| L7 routing/retries | محدودتر | کامل (VirtualService) |
| Policy L7 | ✅ CNP | ✅ AuthorizationPolicy |
| mTLS | WireGuard / IPSec | workload mTLS |
| Observability | Hubble native | Prometheus + 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 discovery —
curl 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.100BGP و 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
پیشنیاز
- 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=trueOCI (توصیه):
helm install cilium oci://quay.io/cilium/charts/cilium \
--version 1.20.1 \
--namespace kube-system \
--set kubeProxyReplacement=true \
--set hubble.enabled=trueValidate
cilium status --wait
cilium connectivity test
kubectl -n kube-system get pods -l k8s-app=ciliumStar Wars Demo
برای یادگیری policy — Getting Started with Star Wars Demo در docs.
Migrate از CNI دیگر
از Migrating a cluster to Cilium:
- Cilium را parallel نصب کنید (با chaining یا secondary CNI — بسته به distro)
- یا blue/green node pool — nodeهای جدید با Cilium
- NetworkPolicy را به CNP migrate
- kube-proxy را disable پس از validate LB
- CNI قدیمی را uninstall
روی cluster production بدون plan و rollback migrate in-place نکنید.
مقایسه با CNI/Mesh دیگر
| Flannel | Calico | Kube-OVN | Cilium | |
|---|---|---|---|---|
| سادگی | ✅ | متوسط | پیچیده | متوسط |
| Policy L3-L4 | ❌ | ✅ | ✅ | ✅ |
| Policy L7 | ❌ | محدود | محدود | ✅ |
| eBPF datapath | ❌ | optional | ❌ (OVS) | ✅ |
| Observability | ❌ | basic | moderate | ✅ 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 overlap | Kube-OVN |
| kernel قدیمی (< 4.19) | Calico iptables |
| L7 traffic management پیچیده (retry, fault inject) | Istio ambient |
| Windows node networking | Cilium محدود — 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/) GitOpsPlatform 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 network | agent not ready | cilium status — kernel/eBPF |
| Policy drop | CNP too strict | hubble observe --verdict DROPPED |
| Service unreachable | kube-proxy conflict | kubeProxyReplacement + remove kube-proxy |
| L7 policy fail | Envoy not running | check cilium-envoy DaemonSet |
| DNS egress block | missing toFQDNs | add DNS policy rule port 53 |
| High CPU | debug enabled | reduce Hubble verbosity |
Performance و Production
- 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-proxy | eBPF LB + policy |
| IP-based policy | Identity-based security |
| sidecar observability | Hubble kernel flows |
| Istio برای L7 + mTLS | CNP L7 + WireGuard |
| multi-cluster manual | Cluster Mesh |
| blind network debug | service 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 دارید.
قدم بعدی
- Helm install روی staging cluster
cilium connectivity test— baseline سالم- Hubble UI — service map را ببینید
- یک
CiliumNetworkPolicyL4 + L7 HTTP تست hubble observe --verdict DROPPED— policy tuningkubeProxyReplacement=true— kube-proxy را حذف و LB را benchmark کنید- WireGuard encryption — enable در non-prod و latency measure
منابع:
- Cilium — Official Site
- Documentation
- Introduction to Cilium & Hubble
- Installation using Helm
- Network Policy
- Hubble Observability
- Cluster Mesh
- Service Mesh
- GitHub — cilium/cilium
منتشر شده در P30Light — بخش زیرساخت سرور و Cloud Native.