eBPF in Production: Kernel-Level Observability and Security

Use eBPF for kernel-level observability and runtime security, with Cilium, Tetragon, bpftrace examples, and the trade-offs against sidecars and host agents.

By · · Updated · 9 min read

If you run a service mesh sidecar in every pod, sooner or later you ask why you need a full proxy per pod just to see and control traffic the kernel already handles. That is the case for eBPF observability and security. You move visibility and enforcement into the kernel, at the same hook points that traffic and system calls already pass through.

I’d look at this architecture when a sidecar mesh is eating double-digit percentages of fleet-wide CPU and memory, or when a security team needs process-level enforcement that a network-only agent can’t give. I assume that you already know basic Linux networking and container runtime concepts, and I skip the introduction to eBPF itself. The topic here is using it for observability and security in production.

The problem: why sidecars and host agents miss what production needs

A sidecar-based service mesh solves a real problem: consistent mTLS, retries and L7 routing without touching application code. But it does so by putting a full userspace proxy into the request path of every pod. That has a cost and leaves gaps, and host agents have gaps too.

You pay the overhead per pod instead of per node. A typical Envoy sidecar adds 50-100MB of memory and a meaningful CPU tax per pod, and every request now makes two extra hops (client-side proxy, server-side proxy) instead of zero. On a fleet with thousands of pods that adds up, and you pay it even in the hours when nobody uses the mesh’s advanced routing features. Latency-sensitive services feel it directly. 1-2ms per proxy hop doesn’t sound like much until it’s stacked twice on every call in a deep service graph.

A proxy can only inspect traffic that’s routed through it. Raw sockets, UDP flows some meshes don’t intercept, and traffic between processes on the same host outside the mesh’s iptables/nftables redirect rules are invisible to it. A sidecar also doesn’t see what happens inside the container’s process tree: which binary executed, which file got opened, whether a shell spawned unexpectedly inside a database pod. I’d call that a security blind spot, which is worse than an observability gap.

Traditional host agents trade depth for compatibility, and in my opinion they usually lose both. Kernel modules give deep visibility but require per-kernel-version builds, and a buggy one can panic the box. Userspace agents that poll /proc, tail logs or sample syscalls are safer but less accurate. You get an incomplete signal, with a delay, instead of an accurate event stream. And high-frequency polling itself adds load.

eBPF runs small programs at kernel hook points such as kprobes, tracepoints, XDP and LSM hooks. Before loading a program, the verifier checks its state and memory access, and rejects it if it violates the rules. Those checks reduce risk, but they do not replace kernel patching or testing. CO-RE helps compiled programs adapt to kernel data layouts. You still need to validate kernel support, hook availability and the behavior of the tools you choose on the hosts where they will run.

Reference architecture: an eBPF data plane without sidecars

The setup is eBPF programs attached directly to kernel hook points on every node. They feed a network policy path and an observability/security event path. Node agents do the userspace coordination (Cilium for networking, Tetragon for runtime security, often deployed together). There is no per-pod proxy anywhere in the diagram.

Pod and host workloads reach Linux kernel hook points. Verified eBPF programs use these hooks for network policy and process tracing. Programs store identity, policy, and connection state in hash maps and send tracing events to a ring buffer. A Cilium or Tetragon node agent reads the maps and events, sends telemetry to observability tools and the SIEM, and updates policy maps without reloading programs.

Policy and identity live in BPF maps. The kernel programs read these maps when they handle a packet or a syscall, and the userspace agent updates them live. For rules that fit in those maps, changing a policy means writing a new map entry, without recompiling or reloading the eBPF program. Such changes can propagate in milliseconds, with no rolling proxy restart.

The diagram focuses on kernel paths. Cilium's HTTP policy uses a shared Envoy proxy for the traffic selected for Layer 7 inspection. Count that proxy path too when you assess overhead and encryption coverage.

Decision criteria: eBPF-native vs sidecar service mesh vs traditional host agents

Criteria eBPF-Native (Cilium/Tetragon) Sidecar Service Mesh (Istio/Linkerd) Traditional Host Agents
Performance overhead Low: in-kernel processing, no extra hops, shared per-node cost instead of per-pod High: proxy per pod, two extra hops per request, meaningful memory/CPU tax at scale Medium: depends on polling frequency; kernel modules add near-zero runtime overhead but real crash risk
Visibility depth Deep: syscalls, process exec, file access, and network, correlated by kernel-verified identity Network/L7 only, and only for traffic actually routed through the proxy Shallow to deep depending on tooling; usually sampled or delayed, rarely both broad and real-time
Security enforcement In-kernel packet filtering, process termination, and supported return-value overrides; prevention guarantees depend on the hook and action L7 policy (mTLS, authz) only for meshed traffic; no process-level enforcement Detection-oriented; enforcement usually requires a separate LSM or firewall layer
Operational complexity Medium-high: requires kernel/BPF literacy on the team, but a single agent replaces mesh + several point tools Medium: well-documented, but adds a proxy lifecycle (upgrades, cert rotation, resource tuning) to manage per workload Low to medium: familiar tooling, but often means stitching together separate network, process, and file monitoring products
Kernel/version constraints Real: needs a reasonably modern kernel (5.x+ recommended) with BTF for CO-RE; older or heavily customized kernels need work None specific to the kernel: runs in userspace, portable across kernel versions Kernel modules are tightly kernel-version coupled; userspace agents are portable but lose depth
Best fit Platforms already on Kubernetes/cloud-native stacks with kernel expertise in-house, needing both network policy and runtime security from one data plane Teams that need mesh features (traffic shaping, canary routing, mTLS) more than raw performance, and don’t have in-house kernel expertise Simple environments, legacy (non-containerized) hosts, or teams unwilling to take on kernel-level tooling yet

Where I draw the line: if you’re running Kubernetes at meaningful scale and already fighting sidecar tax or gaps in runtime security visibility, eBPF-native tooling is worth the ramp-up. If you mostly need mesh-style traffic management (canaries, retries, fine-grained L7 routing) and your fleet is small enough that sidecar tax doesn’t hurt yet, I’d stay with a service mesh. Several mesh projects are adopting eBPF for the data plane while keeping the control plane familiar. I think it’s a reasonable middle path.

A concrete example: bpftrace for ad hoc observability, Tetragon for enforcement

Production eBPF work needs both quick ad hoc tracing during an incident and durable, declarative policies that run continuously, so I have an example of each.

For ad hoc observability, you can attach a single bpftrace line to a kernel function, with no agent or daemon and nothing deployed to the application:

# Count TCP retransmissions by the process on the CPU, every 10 seconds.
# Timer-based retransmits run in kernel context, so comm is often not the
# process that owns the socket.
bpftrace -e '
kprobe:tcp_retransmit_skb { @retransmits[comm] = count(); }
interval:s:10 { print(@retransmits); clear(@retransmits); }
'

This attaches a kprobe to tcp_retransmit_skb, the kernel function invoked on TCP retransmission. It keeps a count per process name (comm) in a BPF map, and prints and clears it every ten seconds. The name is the process that was on the CPU. For timer-based retransmits it is often not the socket owner, so the total is more useful than the names. During an incident, it quickly tells you if the node is retransmitting right now. To tie a retransmit to a service, print the socket addresses and ports, as tcpretrans.bt does. You don’t need to ship logs, build dashboards or inspect a sidecar.

Now the process-termination example. This Tetragon TracingPolicy matches the file path at security_file_permission and sends SIGKILL. Check hook availability and coverage on your target kernel before using it:

apiVersion: cilium.io/v1alpha1
kind: TracingPolicy
metadata:
  name: "block-shadow-read"
spec:
  kprobes:
  - call: "security_file_permission"
    syscall: false
    args:
    - index: 0
      type: "file"
    - index: 1
      type: "int"
    selectors:
    - matchArgs:
      - index: 0
        operator: "Prefix"
        values:
        - "/etc/shadow"
      matchActions:
      - action: Sigkill

The selector matches paths prefixed with /etc/shadow. Sigkill terminates the matching process, but does not guarantee that the triggering operation is denied. For access prevention, Tetragon documents combining a signal with a supported return-value override. This example has no override. When you test a prevention policy, check both the returned error and whether data was accessed.

Pitfalls and what I’d do in production

Kernel and CO-RE portability isn’t automatic. CO-RE relies on BTF (BPF Type Format) being present in the running kernel, so a program compiled once can adjust to that kernel’s actual struct layouts at load time. Most distros ship BTF by default on kernels 5.x+, but older kernels, minimal/embedded images or heavily customized kernels sometimes strip it. Before committing to an eBPF-based rollout, I’d verify that /sys/kernel/btf/vmlinux exists on the target hosts as well as in your dev VM. Keep a fallback plan (bundling BTF, or building per-kernel) for the hosts that don’t have it.

The verifier will reject programs that look fine to you. It enforces a bounded stack (512 bytes), limits on program complexity, and restrictions on loops and pointer arithmetic. All of this is needed so a program terminates and can’t read arbitrary memory. Programs that need to do more get split across tail calls (up to 32 chained programs) or use BPF-to-BPF function calls. For anything non-trivial, I’d plan time for fighting with verifier. Expect to restructure logic around its rules, even when a simpler algorithm exists. Take existing map-based patterns from mature projects instead of writing your own state tracking.

Observability cardinality gets expensive fast. With eBPF it’s easy to trace every syscall, packet or function call, so it’s just as easy to generate more events than your backend can ingest or you can afford to store. I’d aggregate in-kernel using BPF maps (counts, histograms, top-N) before anything crosses into userspace. Full per-event export is for debugging, with a target and a time limit. I wouldn’t leave it on by default.

Loading eBPF programs is privileged. Historically it required CAP_SYS_ADMIN. Kernels 5.8+ split this into more granular capabilities (CAP_BPF, CAP_PERFMON, CAP_NET_ADMIN), but it’s still meaningful kernel access. Kernel lockdown in confidentiality mode can also restrict bpf(). I’d restrict which nodes and service accounts can load programs, and in production use signed/vetted images from the project you standardize on rather than ad hoc custom programs. Also audit the bpf() syscall itself. If an attacker can load their own eBPF program, treat it as kernel-level access.

Measure real overhead on your hardware. XDP performance is very different between native mode (running in the NIC driver) and generic mode (running later in the stack, when the driver doesn’t support native XDP). The difference can be an order of magnitude in packets-per-second. Before trusting any published number, I’d benchmark on your own NIC/driver combination with your own traffic shape. Do it again after driver or kernel upgrades, because native XDP support is driver-specific and can regress silently.

There are cases when I wouldn’t use eBPF. Firstly, I’d avoid custom eBPF programs for problems that mature projects already solve (Cilium, Tetragon, Falco, Pixie), unless you have kernel engineers in-house. You inherit verifier debugging, BTF/CO-RE edge cases and upgrade risk that a maintained project has already dealt with. eBPF is also a poor fit on kernels too old for BTF/CO-RE, on managed platforms that restrict the capabilities needed to load programs, or when you need L7 application routing logic. For that, a proxy that understands the protocol semantics is still better than kernel-level packet inspection.

References

These project documents explain the kernel checks, tracing language and enforcement actions from this post. Use the documentation for the versions deployed on your hosts.

  • ebpf-observability-samples. The companion repo: the bpftrace one-liner, the Tetragon block-shadow-read policy, and Cilium L3/L4 + L7 policies from this article, plus BTF/CO-RE and XDP-mode readiness checks. All runnable.
  • Networking. The full pillar on service meshes, eBPF-native data planes, and cloud networking trade-offs.
  • Zero Trust. Identity-aware segmentation and kernel-level policy enforcement patterns.
  • Service Mesh vs eBPF-Native Data Planes: How to Choose. The head-to-head on when sidecars still win.
  • Zero-Trust Segmentation with Cilium Network Policies. Coming soon: identity-aware L3-L7 policy design for multi-tenant clusters.

Let’s talk eBPF

If you’re choosing between eBPF-native tooling, a sidecar mesh or legacy host agents and want a second opinion, I’m happy to compare notes. Connect with me on LinkedIn or reach out via Contact.