Slide 1

Slide 1 text

eBPF and Go: The Core of Modern Kubernetes Networking Donia Chaiehloudj | @doniacld Software Engineer, Isovalent at Cisco Co-author of the book “Learn Go with Pocket-Sized Projectsˮ Nov 1, 2025 10

Slide 2

Slide 2 text

Without @doniacld

Slide 3

Slide 3 text

What is ? @doniacld Makes the Linux kernel programmable

Slide 4

Slide 4 text

With @doniacld

Slide 5

Slide 5 text

Overview of @doniacld Program App Linux Kernel Userspace syscalls

Slide 6

Slide 6 text

Overview of @doniacld Program App Linux Kernel Userspace syscalls event

Slide 7

Slide 7 text

Overview of @doniacld Program App Linux Kernel Userspace syscalls event Events HookPoints) ● tracepoints ● kprobes (kernel) ● uprobes (user) ● TC Traffic Control) ● XDP Express Datapath)

Slide 8

Slide 8 text

is safe @doniacld Program App Linux Kernel Userspace syscalls

Slide 9

Slide 9 text

is safe @doniacld Program App Linux Kernel Userspace syscalls eBPF verifier

Slide 10

Slide 10 text

is safe @doniacld Program App Linux Kernel Userspace syscalls eBPF verifier eBPF verifier guarantees: ● No Infinite Loops ● Memory Safety ● Kernel Integrity

Slide 11

Slide 11 text

is safe @doniacld Program App Linux Kernel Userspace syscalls eBPF verifier approved eBPF verifier guarantees: ● No Infinite Loops ● Memory Safety ● Kernel Integrity

Slide 12

Slide 12 text

is safe and performant @doniacld Program App Linux Kernel Userspace syscalls eBPF verifier eBPF JIT Compiler approved eBPF verifier guarantees: ● No Infinite Loops ● Memory Safety ● Kernel Integrity

Slide 13

Slide 13 text

is safe and performant @doniacld Program App Linux Kernel Userspace syscalls eBPF verifier eBPF JIT Compiler approved eBPF verifier guarantees: ● No Infinite Loops ● Memory Safety ● Kernel Integrity eBPF Just In Time Compiler: ● eBPF bytecode ⟶ native machine code ● ~ same speed as native kernel code

Slide 14

Slide 14 text

@doniacld Communicating with Program App Linux Kernel Userspace syscalls Maps BPF_MAP_TYPE_HASH BPF_MAP_TYPE_ARRAY BPF_MAP_TYPE_PERCPU_HASH ...

Slide 15

Slide 15 text

@doniacld Communicating with Program App Linux Kernel Userspace syscalls Maps BPF_MAP_TYPE_HASH BPF_MAP_TYPE_ARRAY BPF_MAP_TYPE_PERCPU_HASH ... Use Cases: ● kernel → userspace read write

Slide 16

Slide 16 text

@doniacld Communicating with App Linux Kernel Userspace syscalls Maps BPF_MAP_TYPE_HASH BPF_MAP_TYPE_ARRAY BPF_MAP_TYPE_PERCPU_HASH ... Use Cases: ● kernel → userspace ● userspace → kernel write read Program

Slide 17

Slide 17 text

@doniacld Communicating with App Linux Kernel Userspace Program syscalls Maps Use Cases: ● kernel → userspace ● userspace → kernel ● kernel → kernel Program write read

Slide 18

Slide 18 text

Why for Kubernetes? @doniacld pod Linux Kernel Userspace pod pods One kernel for all the containers syscalls

Slide 19

Slide 19 text

Why for Kubernetes? @doniacld Program pod Linux Kernel Userspace pod pods syscalls One kernel for all the containers

Slide 20

Slide 20 text

Why for Kubernetes? @doniacld Program pod Linux Kernel Userspace event pod pods One kernel for all the containers syscalls

Slide 21

Slide 21 text

Why for Kubernetes? @doniacld

Slide 22

Slide 22 text

Why for Kubernetes? @doniacld

Slide 23

Slide 23 text

Why for Kubernetes? @doniacld

Slide 24

Slide 24 text

@doniacld Go is the 💎 in Cloud-native ecosystem ● eBPF is kernel-level magic → But hard to interact with directly C, bytecode). ● Most cloud-native projects are written in Go → Kubernetes, Docker, Prometheus, Cilium, etc. ● Go offers simplicity + performance → Ideal for distributed systems and networking. ● Go + eBPF = productive + powerful → SDKs like cilium/ebpf let you write networking/security tooling

Slide 25

Slide 25 text

@doniacld 1 Write eBPF C program 2 Generate Go Objects & Methods 3 Write Go main program 4 Run your program Development cycle and

Slide 26

Slide 26 text

1. TRACING @doniacld

Slide 27

Slide 27 text

Tracing Open File Events https://github.com/doniacld/ebpf-4-gophers @doniacld

Slide 28

Slide 28 text

1. Write C program: Trace when files are open #include // BPF header for definitions. #include // BPF helper functions. // Attach to sys_enter_openat tracepoint. SEC("tracepoint/syscalls/sys_enter_openat") int trace_openat(void *ctx) { char msg[] = "File opening..."; // Message to log. bpf_trace_printk(msg, sizeof(msg)); // Log message to trace pipe. return 0; } char LICENSE[] SEC("license") = "GPL"; @doniacld

Slide 29

Slide 29 text

1. Write C program: Trace when files are open #include // BPF header for definitions. #include // BPF helper functions. // Attach to sys_enter_openat tracepoint. SEC("tracepoint/syscalls/sys_enter_openat") int trace_openat(void *ctx) { char msg[] = "File opening..."; // Message to log. bpf_trace_printk(msg, sizeof(msg)); // Log message to trace pipe. return 0; } char LICENSE[] SEC("license") = "GPL"; @doniacld

Slide 30

Slide 30 text

1. Write C program: Trace when files are open #include // BPF header for definitions. #include // BPF helper functions. // Attach to sys_enter_openat tracepoint. SEC("tracepoint/syscalls/sys_enter_openat") int trace_openat(void *ctx) { char msg[] = "File opening..."; // Message to log. bpf_trace_printk(msg, sizeof(msg)); // Log message to trace pipe. return 0; } char LICENSE[] SEC("license") = "GPL"; @doniacld $ sudo cat /sys/kernel/debug/tracing/trace_pipe systemd-journal-326 [000] ...21 53765.037027: bpf_trace_printk: File opening... systemd-journal-326 [000] ...21 53765.037048: bpf_trace_printk: File opening... cat-35252 [000] ...21 53765.037948: bpf_trace_printk: File opening... cat-35252 [000] ...21 53765.037966: bpf_trace_printk: File opening... cat-35252 [000] ...21 53765.038107: bpf_trace_printk: File opening... process id

Slide 31

Slide 31 text

2. Compile & Generate Go Objects: bpf2go @doniacld //go:generate go run github.com/cilium/ebpf/cmd/bpf2go openfile openfile.c call clang under the hood

Slide 32

Slide 32 text

@doniacld 2. Generated Go Objects // openfilePrograms contains all programs after they have been loaded into the kernel. //type openfilePrograms struct { TraceOpenat *ebpf.Program `ebpf:"trace_openat"` } Objects to manipulate // openfileObjects contains all objects after they have been loaded into the kernel. type openfileObjects struct { openfilePrograms openfileMaps openfileVariables } //go:generate go run github.com/cilium/ebpf/cmd/bpf2go openfile openfile.c eBPF program bytecodes

Slide 33

Slide 33 text

@doniacld 3. Main Go Program: Load the eBPF program func main() { // Allow the current process to lock memory for eBPF resources. if err := rlimit.RemoveMemlock(); err != nil { log.Fatalf("failed to remove memlock: %v", err) } var objs openfileObjects err := loadOpenfileObjects(&objs, nil) if err != nil { log.Fatalf("failed to load objects: %v", err) } // Attach the eBPF program to the tracepoint. tp, err := link.Tracepoint("syscalls", "sys_enter_openat", objs.TraceOpenat, nil) if err != nil { log.Fatalf("failed to attach tracepoint: %v", err) } defer tp.Close() log.Println("eBPF program attached. Waiting for events...") // ... // Log “/sys/kernel/debug/tracing/trace_pipe" output // ... }

Slide 34

Slide 34 text

@doniacld 3. Main Go Program: Attach the eBPF program to tracepoint func main() { // Allow the current process to lock memory for eBPF resources. if err := rlimit.RemoveMemlock(); err != nil { log.Fatalf("failed to remove memlock: %v", err) } var objs openfileObjects err := loadOpenfileObjects(&objs, nil) if err != nil { log.Fatalf("failed to load objects: %v", err) } // Attach the eBPF program to the tracepoint tp, err := link.Tracepoint("syscalls", "sys_enter_openat", objs.TraceOpenat, nil) if err != nil { log.Fatalf("failed to attach tracepoint: %v", err) } defer tp.Close() log.Println("eBPF program attached. Waiting for events...") // ... // Log “/sys/kernel/debug/tracing/trace_pipe" output // ... }

Slide 35

Slide 35 text

@doniacld Open File Tracing Demo

Slide 36

Slide 36 text

@doniacld Open File Tracing Demo

Slide 37

Slide 37 text

@doniacld Open File Tracing Demo ✅

Slide 38

Slide 38 text

XDP hooks power 󰭈 https://blog.ippon.tech/ebpf-and-kernel-modules-whats-the-difference @doniacld

Slide 39

Slide 39 text

2. OBSERVABILITY @doniacld

Slide 40

Slide 40 text

Packet Counter with Maps Example https://github.com/doniacld/ebpf-4-gophers @doniacld

Slide 41

Slide 41 text

1. Write C Program: Define a Map to store the counter #include #include struct { __uint(type, BPF_MAP_TYPE_ARRAY); __type(key, __u32); __type(value, __u64); __uint(max_entries, 1); } pkt_count SEC(".maps"); // count_packets atomically increases a packet counter on every invocation. SEC("xdp") int count_packets() { __u32 key = 0; __u64 *count = bpf_map_lookup_elem(&pkt_count, &key); if (count) { __sync_fetch_and_add(count, 1); } return XDP_PASS; } char __license[] SEC("license") = "Dual MIT/GPL";

Slide 42

Slide 42 text

1. Write C Program: Increment packet counter #include #include struct { __uint(type, BPF_MAP_TYPE_ARRAY); __type(key, __u32); __type(value, __u64); __uint(max_entries, 1); } pkt_count SEC(".maps"); // count_packets atomically increases a packet counter on every invocation. SEC("xdp") int count_packets() { __u32 key = 0; __u64 *count = bpf_map_lookup_elem(&pkt_count, &key); if (count) { __sync_fetch_and_add(count, 1); } return XDP_PASS; } char __license[] SEC("license") = "Dual MIT/GPL";

Slide 43

Slide 43 text

3. Main Go Program: Load the eBPF program package main import ( // … "github.com/cilium/ebpf/link" "github.com/cilium/ebpf/rlimit" ) func main() { err := rlimit.RemoveMemlock() var objs counterObjects err := loadCounterObjects(&objs, nil) if err != nil { //… } defer objs.Close() ifname := "eth0" iface, err := net.InterfaceByName(ifname) if err != nil {//…} link, err := link.AttachXDP(link.XDPOptions{ Program: objs.CountPackets, Interface: iface.Index, }) defer link.Close()

Slide 44

Slide 44 text

3. Main Go Program: Choose an interface package main import ( // … "github.com/cilium/ebpf/link" "github.com/cilium/ebpf/rlimit" ) func main() { err := rlimit.RemoveMemlock() var objs counterObjects err := loadCounterObjects(&objs, nil) if err != nil { //… } defer objs.Close() ifname := "eth0" iface, err := net.InterfaceByName(ifname) if err != nil {//…} link, err := link.AttachXDP(link.XDPOptions{ Program: objs.CountPackets, Interface: iface.Index, }) defer link.Close()

Slide 45

Slide 45 text

3. Main Go Program: Attach the program to a hook package main import ( // … "github.com/cilium/ebpf/link" "github.com/cilium/ebpf/rlimit" ) func main() { err := rlimit.RemoveMemlock() var objs counterObjects err := loadCounterObjects(&objs, nil) if err != nil { //… } defer objs.Close() ifname := "eth0" iface, err := net.InterfaceByName(ifname) if err != nil {//…} link, err := link.AttachXDP(link.XDPOptions{ Program: objs.CountPackets, Interface: iface.Index, }) defer link.Close() ...

Slide 46

Slide 46 text

3. Main Go Program: Read from the map // Periodically fetch the packet counter from PktCount tick := time.Tick(time.Second) stop := make(chan os.Signal, 5) signal.Notify(stop, os.Interrupt) for { select { case <-tick: var count uint64 err := objs.PktCount.Lookup(uint32(0), &count) if err != nil { log.Fatal("Map lookup:", err) } log.Printf("Received %d packets", count) case <-stop: log.Print("Received signal, exiting..") return } } }

Slide 47

Slide 47 text

3. Main Go Program: Log // Periodically fetch the packet counter from PktCount tick := time.Tick(time.Second) stop := make(chan os.Signal, 5) signal.Notify(stop, os.Interrupt) for { select { case <-tick: var count uint64 err := objs.PktCount.Lookup(uint32(0), &count) if err != nil { log.Fatal("Map lookup:", err) } log.Printf("Received %d packets", count) case <-stop: log.Print("Received signal, exiting..") return } }

Slide 48

Slide 48 text

Packet Counter Observability Demo @doniacld

Slide 49

Slide 49 text

@doniacld Packet Counter Observability Demo

Slide 50

Slide 50 text

Packet Counter Observability Demo ✅ @doniacld

Slide 51

Slide 51 text

3. SECURITY @doniacld

Slide 52

Slide 52 text

XDP Drop Example https://github.com/doniacld/ebpf-4-gophers @doniacld

Slide 53

Slide 53 text

Example: XDP Drop packets SEC("xdp") int xdp_drop(struct xdp_md *ctx) { char msg[] = "Hello, World!"; bpf_trace_printk(msg, sizeof(msg)); // Print to trace pipe void *data = (void *)(long)ctx->data; void *data_end = (void *)(long)ctx->data_end; // Check if the packet's destination IP is blocked if (isBlockedIP(data, data_end)) { char msg[] = "Got ping packet"; bpf_trace_printk(msg, sizeof(msg)); // Print to trace pipe return XDP_DROP; } return XDP_PASS; // Allow the packet to pass } // License declaration char _license[] SEC("license") = "GPL"; @doniacld

Slide 54

Slide 54 text

Example: XDP Drop packets SEC("xdp") int xdp_drop(struct xdp_md *ctx) { char msg[] = "Hello, World!"; bpf_trace_printk(msg, sizeof(msg)); // Print to trace pipe void *data = (void *)(long)ctx->data; void *data_end = (void *)(long)ctx->data_end; // Check if the packet's destination IP is blocked if (isBlockedIP(data, data_end)) { char msg[] = "Got ping packet"; bpf_trace_printk(msg, sizeof(msg)); // Print to trace pipe return XDP_DROP; } return XDP_PASS; // Allow the packet to pass } // License declaration char _license[] SEC("license") = "GPL"; @doniacld

Slide 55

Slide 55 text

XDP drop Security Example @doniacld

Slide 56

Slide 56 text

XDP Drop Security Demo ✅ @doniacld

Slide 57

Slide 57 text

4. NETWORKING Real Use Case @doniacld

Slide 58

Slide 58 text

Overview of Cilium @doniacld

Slide 59

Slide 59 text

Efficient Networking: Cilium use of @doniacld

Slide 60

Slide 60 text

Cilium Network Policy YAML @doniacld apiVersion: "cilium.io/v2" kind: CiliumNetworkPolicy metadata: name: "deny-external" spec: endpointSelector: matchLabels: app: "backend" ingress: - fromEndpoints: - matchLabels: app: "frontend" frontend pod backend pod frontend pod frontend pods backend pod backend pods external pod external pods 💡 Endpoint = Pod

Slide 61

Slide 61 text

From Endpoint to Identity Go @doniacld type Endpoint struct { ID int Labels map[string]string Identity int } 💡 Endpoint = Pod Endpoints 1: {“app”:”frontend”} 2: {“app”:”backend”} type Policy struct { SourceIdentity int DestinationIdentity int Allowed bool } Policy src: 1 dst: 2 true

Slide 62

Slide 62 text

Store Policies @doniacld struct bpf_map_def SEC("maps") policy_map = { .type = BPF_MAP_TYPE_HASH, .key_size = sizeof(int), .value_size = sizeof(int), .max_entries = 1024, }; eBPF map to store policies

Slide 63

Slide 63 text

Store Policies @doniacld func loadPoliciesToMap(policies []Policy, policyMap *ebpf.Map) error { for _, policy := range policies { err := policyMap.Put(policy.SourceIdentity, policy.DestinationIdentity) if err != nil { return err } } return nil } struct bpf_map_def SEC("maps") policy_map = { .type = BPF_MAP_TYPE_HASH, .key_size = sizeof(int), .value_size = sizeof(int), .max_entries = 1024, }; eBPF map to store policies Function to load policies into the eBPF map

Slide 64

Slide 64 text

eBPF program to enforce policies @doniacld // eBPF map to store policies. struct bpf_map_def SEC("maps") policy_map = { .type = BPF_MAP_TYPE_HASH, .key_size = sizeof(int), .value_size = sizeof(int), .max_entries = 1024, }; // eBPF program to enforce policies. SEC("xdp") int enforce_policy(struct xdp_md *ctx) { int src_identity = get_source_identity(ctx); int dst_identity = get_destination_identity(ctx); int *allowed = bpf_map_lookup_elem(&policy_map, &src_identity); if (allowed && *allowed == dst_identity) { // Allow the packet. return XDP_PASS; } // Drop the packet. return XDP_DROP; }

Slide 65

Slide 65 text

eBPF and Cilium everywhere! @doniacld Amazon EKS Anywhere Anthos GKE Dataplane v2 Azure Kubernetes Service MetaKube Managed Kubernetes Service source: https://cilium.io/use-cases/cni/ Alibaba Cloud Container Service

Slide 66

Slide 66 text

📝 Key Takeaways @doniacld

Slide 67

Slide 67 text

📝 Key Takeaways @doniacld ● eBPF lets you run safe, fast programs in the Linux kernel

Slide 68

Slide 68 text

📝 Key Takeaways @doniacld ● eBPF lets you run safe, fast programs in the Linux kernel ● You can use it for: ○ 🔍 Tracing (e.g. file open events) ○ 📊 Observability (e.g. counting packets by IP ○ 🛡 Security (e.g. dropping packets with XDP ○ 🌐 Networking (e.g. packets routing with Cilium)

Slide 69

Slide 69 text

📝 Key Takeaways @doniacld ● eBPF lets you run safe, fast programs in the Linux kernel ● You can use it for: ○ 🔍 Tracing (e.g. file open events) ○ 📊 Observability (e.g. counting packets by IP ○ 🛡 Security (e.g. dropping packets with XDP ○ 🌐 Networking (e.g. packets routing with Cilium) ● Go is the language of the cloud-native ecosystem

Slide 70

Slide 70 text

📝 Key Takeaways @doniacld ● eBPF lets you run safe, fast programs in the Linux kernel ● You can use it for: ○ 🔍 Tracing (e.g. file open events) ○ 📊 Observability (e.g. counting packets by IP ○ 🛡 Security (e.g. dropping packets with XDP and Tetragon) ○ 🌐 Networking (e.g. packets routing with Cilium) ● Go is the language of the cloud-native ecosystem ● With libraries like cilium/ebpf, you can use Go to: ○ Load eBPF programs & Interact with kernel data safely ● Perfect fit for building Kubernetes CNI, agents, operators, and tools, etc

Slide 71

Slide 71 text

Thank you! ebpf.io @ciliumproject @isovalent isovalent.com/labs/ebpf-getting-started/ github.com/doniacld/ebpf-4-gophers/ Letʼs connect @doniacld

Slide 72

Slide 72 text

How works under the hood? @doniacld

Slide 73

Slide 73 text

How works under the hood? @doniacld

Slide 74

Slide 74 text

How works under the hood? @doniacld

Slide 75

Slide 75 text

How works under the hood? @doniacld

Slide 76

Slide 76 text

How works under the hood? @doniacld

Slide 77

Slide 77 text

How works under the hood? @doniacld

Slide 78

Slide 78 text

How works under the hood? @doniacld