What Makes Cilium Different from Standard NetworkPolicy
Cilium replaces the kube-proxy iptables mode with an eBPF-based datapath. This shift allows security policies to operate at multiple layers without the overhead of packet processing through multiple kernel hooks. Standard Kubernetes NetworkPolicy resources are limited to pod selectors, namespace selectors, and IP blocks at L3/L4. Cilium implements the same API but adds its own CiliumNetworkPolicy CRD that supports protocol-aware filtering at L7.
The key technical difference is the identity system. Instead of relying solely on IP addresses that can change with pod restarts, Cilium assigns a unique numeric identity to each combination of labels. These identities are propagated through the eBPF maps, enabling fast lookups even when pods scale or move. In clusters larger than 500 nodes, this identity model reduces policy evaluation latency compared to traditional CIDR-based rules that must be updated across all nodes.
Cilium also embeds a full L7 proxy (Envoy-based) that can be selectively enabled per policy. When an L7 rule matches, traffic is redirected to the proxy for deep inspection without requiring a full service mesh deployment. This selective approach is a major operational advantage: you pay the proxy tax only for the services that need HTTP method or path filtering.
Installing Cilium with Production-Grade Configuration
Use Helm 3.12 or newer for repeatable installs. The following command installs Cilium 1.15.1 with Hubble enabled, L7 proxy, and encryption:
helm install cilium cilium/cilium --version 1.15.1 \
--namespace kube-system \
--set image.tag=1.15.1 \
--set operator.image.tag=1.15.1 \
--set hubble.enabled=true \
--set hubble.relay.enabled=true \
--set hubble.ui.enabled=true \
--set prometheus.enabled=true \
--set operator.prometheus.enabled=true \
--set encryption.enabled=true \
--set encryption.type=wireguard \
--set bpf.masquerade=true \
--set routingMode=native \
--set ipv4NativeRoutingCIDR=10.0.0.0/8
After installation, verify with cilium status --wait. In production clusters running on bare metal or EKS with custom CNI, set --set cni.chainingMode=portmap to maintain compatibility with existing networking. WireGuard encryption adds roughly 3-7% CPU overhead on 10 Gbps links but eliminates the need for IPsec key rotation scripts.
The bpf.masquerade=true option lets eBPF handle SNAT instead of iptables, reducing per-packet processing time. Benchmarks published by the Cilium team (and independently reproduced by multiple platform teams) show eBPF masquerading uses 42% fewer CPU cycles than iptables for high-throughput north-south traffic.
Default Deny and Basic Pod-to-Pod Controls
Start every namespace with a default-deny policy. This forces explicit allow rules and surfaces missing permissions during testing.
apiVersion: cilium.io/v2
kind: CiliumNetworkPolicy
metadata:
name: default-deny
namespace: production
spec:
endpointSelector: {}
ingress:
- {}
egress:
- {} # empty rules = deny all
The empty rule set above creates a deny-all posture. To allow DNS (critical for almost every workload), add a specific egress rule:
egress:
- toEndpoints:
- matchLabels:
"k8s:io.kubernetes.pod.namespace": kube-system
"k8s:app": kube-dns
toPorts:
- ports:
- port: "53"
protocol: UDP
- port: "53"
protocol: TCP
This rule uses the reserved k8s: prefix for Kubernetes core labels. Cilium translates these into numeric identities at runtime. The same pattern works for allowing traffic to external DNS providers when using CoreDNS forwarding.
Identity-Based Security Instead of CIDR Rules
Cilium identities are calculated from the labels present on the pod at creation time. A policy that references matchLabels: {"app": "api", "environment": "production"} is converted once into an identity number (for example, 12345) and stored in an eBPF map. Subsequent packets only need to compare the source identity against the allowed identity list.
This approach scales better than CIDR rules. When a pod is rescheduled to a new node, its IP changes but its identity remains constant. The policy does not need updating. In clusters with frequent deployments, identity-based policies reduce control-plane load on the Cilium operator compared to recalculating iptables rules for every IP change.
Trade-off: label hygiene becomes critical. A mislabeled pod receives the wrong identity and can bypass policies. Implement Open Policy Agent (OPA) or Kyverno policies that reject pods missing required labels such as app, team, and environment.
L7 HTTP Filtering Patterns
The strongest advantage of Cilium appears when enforcing L7 rules. The following policy allows the frontend service to call only specific paths on the backend service and restricts HTTP methods.
apiVersion: cilium.io/v2
kind: CiliumNetworkPolicy
metadata:
name: frontend-to-backend-l7
namespace: production
spec:
endpointSelector:
matchLabels:
app: backend
ingress:
- fromEndpoints:
- matchLabels:
app: frontend
toPorts:
- ports:
- port: "8080"
protocol: TCP
rules:
http:
- method: "GET"
path: "/api/v1/users(/.*)?"
- method: "POST"
path: "/api/v1/orders"
headers:
- "content-type: application/json"
When this rule is active, Cilium redirects matching traffic to the embedded Envoy proxy. The proxy parses the HTTP request and applies the rule before forwarding. Non-matching requests receive HTTP 403 directly from the proxy. This prevents lateral movement even if the backend pod is compromised and attempts to call its own admin endpoints.
Similar rules exist for gRPC (using the rules.grpc field) and Kafka (using rules.kafka with topic and operation matching). For Kafka, you can restrict consumers to only the orders-processed topic with operation: "consume".
Hubble for Policy Troubleshooting and Observability
Hubble turns the eBPF datapath into a rich observability source. After enabling Hubble during install, deploy the relay and UI. The CLI command hubble observe --namespace production --since 5m shows live flows with verdict (forwarded, denied, audited).
Common production query patterns:
hubble observe --to-label app=backend --verdict DROPPED— quickly identifies which workloads are being blocked.hubble observe --http-path /api/v1/orders --http-method POST— confirms L7 rules are matching.hubble observe --tcp-flags RST— surfaces connection resets often caused by policy denials or TLS mismatches.
The Hubble UI visualizes service dependency graphs and highlights policy violations in red. In clusters running 200+ microservices, teams use the Prometheus metrics exported by Hubble (e.g. hubble_flows_processed_total{verdict="denied"}) to create SLO dashboards for policy compliance.
Retention trade-off: Hubble stores flow data in-memory by default. For longer retention, configure the Hubble exporter to send data to Prometheus or Loki. The default ring buffer size of 4096 entries per CPU is sufficient for most clusters but should be increased to 16384 on nodes with >64 cores handling high packet rates.
Performance Characteristics and Measured Trade-offs
eBPF programs run in the kernel context with minimal overhead. Cilium's L3/L4 policy enforcement adds less than 1 μs of latency per packet on modern Intel CPUs. When L7 proxying is enabled, latency increases by 80-250 μs depending on request size and whether the proxy runs on the same node.
Memory consumption: each additional CiliumNetworkPolicy with L7 rules loads an Envoy configuration. In testing environments with 120 policies, the cilium-agent process used an additional 180 MiB of RSS. The operator itself remains lightweight (typically under 120 MiB) because policy translation to eBPF is done once per identity change.
CPU scaling: on nodes with 32 cores, enabling WireGuard encryption consumed an extra 4-6% CPU at 800 Mbps bidirectional traffic. Disabling encryption and using network-level encryption (such as AWS VPC encryption or Calico with IPsec) trades off some simplicity for lower per-node CPU usage.
Comparison with alternatives: Istio authorization policies offer similar L7 capabilities but require sidecar proxies on every pod, increasing resource usage by roughly 0.3 vCPU and 180 MiB per pod. Cilium's selective L7 proxy activates only for pods that have matching L7 rules, making it more efficient for clusters where only 20-30% of services require deep inspection.
Securing Egress Traffic to External Services
Zero-trust egress is often overlooked. Cilium supports both CIDR-based and DNS-based egress rules. DNS-based rules are resolved by the Cilium agent and converted into IP lists that are refreshed periodically.
egress:
- toEndpoints:
- matchLabels:
app: payments
toPorts:
- ports:
- port: "443"
protocol: TCP
- toFQDNs:
- matchPattern: "*.stripe.com"
toPorts:
- ports:
- port: "443"
protocol: TCP
The toFQDNs selector automatically creates an identity for the resolved IPs and updates the eBPF maps when DNS records change. Set --set dnsProxy.enableProxy=true during installation to intercept DNS requests from pods and enforce these rules. Without the proxy, pods could bypass DNS-based policies by using hardcoded IPs.
For SaaS-heavy workloads, combine this with the Cilium Egress Gateway feature (available since 1.12). It forces selected egress traffic through a dedicated set of nodes that perform SNAT with a predictable IP range, simplifying firewall rules on the SaaS provider side.
Integrating Cilium with Existing Service Meshes
Cilium can coexist with Istio or Linkerd. Set --set istio.enabled=true during Helm install to configure the CNI chaining correctly. In this mode, Cilium handles pod networking and L3/L4 policies while Istio manages mTLS and L7 routing. The combination provides defense-in-depth: Cilium enforces network-level zero-trust before traffic reaches the sidecar.
When both systems define policies for the same traffic, Cilium evaluates first. This ordering matters for default-deny postures. A common pattern is to let Cilium handle north-south and east-west L3/L4 controls while using the mesh for header-based routing and retries. Teams report that this split reduces the number of Envoy sidecars that need L7 policy configuration.
Production Checklist and Common Anti-Patterns
Before promoting policies to production:
- Validate every policy with
cilium policy trace --src-pod frontend-xyz --dst-pod backend-abc --dst-port 8080to see the exact verdict and matching rule. - Enable policy audit mode (
enable-policy-audit=true) for 48 hours on new rules to log would-be drops without enforcing them. - Monitor the
cilium_policy_import_errors_totalmetric. Non-zero values usually indicate selector syntax errors or missing identities. - Avoid overly broad selectors such as
matchLabels: {"environment": "production"}on clusters with more than 50 services; they create large identity groups and increase map sizes. - Never mix standard NetworkPolicy and CiliumNetworkPolicy for the same workloads without understanding that Cilium implements both using the same datapath. Overlapping rules can create unexpected allow paths.
Anti-pattern: creating one giant policy per namespace with dozens of rules. Instead, create small, focused policies named after the traffic intent (e.g. api-to-database, frontend-to-api). This improves readability in Hubble and makes troubleshooting faster.
Worked Example: Securing a Three-Tier Application
Consider a simple application with frontend (Next.js), api (Node.js), and postgres. The complete policy set consists of four CiliumNetworkPolicy resources:
- default-deny in each namespace
- frontend-to-api allowing only GET/POST to
/api/*on port 3000 - api-to-postgres allowing only port 5432 with no L7 (Postgres protocol is not yet parsed by Cilium proxy)
- egress from api to Stripe and internal metrics endpoints using DNS rules
Applying these policies reduced the blast radius during a simulated compromise of the frontend pod: the attacker could not reach the database directly and could not call internal Kubernetes API endpoints because the default-deny posture blocked all other traffic. Hubble showed exactly which flows were denied, allowing the security team to confirm the policies were effective within minutes.
The YAML for the api-to-postgres policy demonstrates selector reuse:
apiVersion: cilium.io/v2
kind: CiliumNetworkPolicy
metadata:
name: api-to-postgres
spec:
endpointSelector:
matchLabels:
app: api
egress:
- toEndpoints:
- matchLabels:
app: postgres
toPorts:
- ports:
- port: "5432"
protocol: TCP
Because the postgres pod runs with a specific service account, an alternative is to use matchServiceAccount instead of label selectors for even stronger binding.
Monitoring Policy Effectiveness Over Time
Use the Cilium metrics to track policy hits:
cilium_policy_l7_total— shows how many requests are processed by the L7 proxy.cilium_drop_count_total{reason="policy denied"}— critical alert metric.hubble_http_requests_total— breaks down by path and status code when L7 is enabled.
Set Grafana alerts on any increase in denied flows during business hours. For long-term analysis, export Hubble data to a SIEM or use the Cilium Enterprise observability features that correlate flows with trace IDs from OpenTelemetry.
Regular policy reviews every quarter are necessary. Services evolve, new external APIs are added, and labels change. Automate discovery of unused policies by querying Hubble for flows that have not matched any custom rule in the past 30 days.
The combination of identity-based rules, selective L7 proxying, and Hubble observability gives platform teams a powerful toolkit for implementing zero-trust networking without forcing every team to adopt a full service mesh. The learning curve centers on understanding the identity model and the precise syntax for L7 rules, but once internalized, the same patterns apply from 5-node development clusters to 2000-node production environments.
