Skip to content

Enable Kubernetes CNI, Service load balancing and NetworkPolicy kernel facilities - #29

Merged
gm-e2b merged 9 commits into
mainfrom
kube-networking-cni
Jul 28, 2026
Merged

Enable Kubernetes CNI, Service load balancing and NetworkPolicy kernel facilities#29
gm-e2b merged 9 commits into
mainfrom
kube-networking-cni

Conversation

@gm-e2b

@gm-e2b gm-e2b commented Jul 28, 2026

Copy link
Copy Markdown
Contributor

Note

Includes the commits from #28 (thanks @c-kruse!); its four commits are unchanged.

Why

A customer reported that the e2b/k3s docs page doesn't work because the sandbox kernel lacks xt_statistic. Reproduced on the production e2b/k3s template: a Service with two ready endpoints sends all in-cluster traffic to one pod — kube-proxy cannot program random endpoint selection in either iptables or nftables mode. A capability audit found the same class of gap across CNIs, NetworkPolicy engines, and tunneling.

What this adds on top of #28

  • x86_64 CNI facilities: DUMMY, VXLAN, GENEVE (flannel's default vxlan backend, Docker overlay, Cilium tunnels, dummy devices); IP_SET + set types + NETFILTER_XT_SET + rpfilter matches (Calico, kube-router); NETFILTER_XT_TARGET_NFQUEUE; NET_SCH_INGRESS + NET_ACT_MIRRED (tc clsact for eBPF dataplanes); SCHEDSTATS, CRYPTO_USER_API_HASH (Cilium).
  • arm64 CNI facilities + nftables parity: same set, plus NETFILTER_XT_MARK (emitted by kube-proxy iptables mode) and the nf_tables subsystem — closing the arm64-vs-x86_64 delta Add kube networking facilities #28 flagged as an open question.
  • xt_physdev: k3s's embedded NetworkPolicy controller (kube-router) programs -m physdev --physdev-is-bridged rules; without the match, iptables-restore fails and every NetworkPolicy silently does not enforce.

CONFIG_MODULES stays off everywhere: no runtime module loading in the guest, capabilities are added one by one as built-ins. (Consequence on 6.1: BPF_JIT and KPROBES cannot be enabled — Kconfig hard dependency on MODULES, relaxed upstream only in 6.8+/6.12+.)

c-kruse added 4 commits July 21, 2026 15:35
Allows kube-proxy in iptables mode and other networking tools to use
probabilistic packet matching for load balancing across multiple
endpoints. e.g. `iptables -m statistic ...`

Sets CONFIG_NETFILTER_XT_MATCH_STATISTIC=y

On arm64, enable two Xtables options needed, already set on x86_64

    CONFIG_NETFILTER_XT_MATCH_COMMENT=y
    CONFIG_NETFILTER_XT_MATCH_MULTIPORT=y

Signed-off-by: Christian Kruse <christian@c-kruse.com>
Allows kube-proxy in nftables mode and other networking tools to use
random number generation for endpoint selection and forwarding
information base lookups for local-address dispatch. e.g. `nft add
rule ... numgen random mod 1 map { ... }`, `nft add rule ... fib
daddr type local`

Sets CONFIG_NFT_NUMGEN=y
Sets CONFIG_NFT_FIB_IPV4=y  (selects CONFIG_NFT_FIB=y)
Sets CONFIG_NFT_FIB_IPV6=y

Signed-off-by: Christian Kruse <christian@c-kruse.com>
Allows kindnetd using the kube-network-policies reference implementation,
firewalls, and other networking tools to enforce policy via first-packet
NFQUEUE inspection with conntrack label caching. e.g. `nft add table inet
...`, `nft add rule ... queue num 101 bypass`, `ct label set 28`

Sets CONFIG_NF_TABLES_INET=y
Sets CONFIG_NETFILTER_NETLINK_QUEUE=y
Sets CONFIG_NETFILTER_NETLINK_GLUE_CT=y
Sets CONFIG_NF_CT_NETLINK=y

Signed-off-by: Christian Kruse <christian@c-kruse.com>
Allows kube-proxy in iptables mode and other networking tools to
implement session affinity, rate limiting and throttling with xtables
recency rules.

Sets CONFIG_NETFILTER_XT_MATCH_RECENT=y

Signed-off-by: Christian Kruse <christian@c-kruse.com>
@cla-bot cla-bot Bot added the cla-signed label Jul 28, 2026
gm-e2b added 3 commits July 28, 2026 12:29
- DUMMY, VXLAN, GENEVE: flannel vxlan backend, Docker overlay networks,
  Cilium tunnels, dummy devices (NodeLocal DNS, kube-vip, IPVS)
- IP_SET + set types, NETFILTER_XT_SET, rpfilter matches: Calico
  iptables dataplane, kube-router
- NETFILTER_XT_TARGET_NFQUEUE: iptables-based NetworkPolicy engines
- NET_SCH_INGRESS, NET_ACT_MIRRED: tc clsact hook for eBPF dataplanes
- SCHEDSTATS, CRYPTO_USER_API_HASH: Cilium base requirements
Same CNI set as x86_64, plus arm64-only gaps:
- NETFILTER_XT_MARK: emitted by kube-proxy iptables mode
- nf_tables subsystem and conntrack/queue netlink: x86_64 parity,
  required by iptables-nft userspace and kube-proxy nftables mode
k3s's embedded network policy controller (kube-router) programs
'-m physdev --physdev-is-bridged' rules for traffic crossing the CNI
bridge. Without the match, iptables-restore fails with
'Extension physdev revision 0 not supported' and NetworkPolicy
silently does not enforce.
@gm-e2b
gm-e2b force-pushed the kube-networking-cni branch from 6b56773 to 379c044 Compare July 28, 2026 10:29
gm-e2b added 2 commits July 28, 2026 14:54
kube-router's per-policy chains end with rate-limited logging of
denied traffic ('-m limit ... -j NFLOG') before REJECT. Without
xt_limit the whole iptables-restore aborts (exit status 4) and no
pod firewall rules are programmed, so NetworkPolicy does not enforce
even with xt_physdev present.
- NETFILTER_XT_TARGET_CT: Calico felix programs NOTRACK/CT rules in the
  raw table; without the target its iptables-restore fails
  ('Extension CT revision 0 not supported') and calico-node never
  reports Ready
- MACVLAN, IPVLAN, VLAN_8021Q: secondary pod networks (Multus) and
  Docker macvlan/ipvlan network drivers
@gm-e2b

gm-e2b commented Jul 28, 2026

Copy link
Copy Markdown
Contributor Author

Validation results for this branch (amd64 build of 56bcb8d, dev cluster, stock k3s v1.36.2+k3s1 template with flannel default vxlan backend — no host-gw workaround):

Test Old kernel This branch
flannel vxlan backend crash-loop flannel.1 up, cluster Ready
Service LB, 40 in-cluster requests / 2 replicas (iptables mode) 40 / 0 21 / 19
Same in kube-proxy nftables mode (numgen) mode unusable 20 / 20
sessionAffinity: ClientIP (xt_recent) 20/20 to one pod
NetworkPolicy deny-all (k3s embedded controller) silent no-op blocked
NetworkPolicy allow-from-label silent no-op friend 200, stranger blocked
Calico v3.29 (VXLAN dataplane) calico-node 1/1 Ready, pod-to-pod OK, policies enforce
Docker overlay / macvlan / ipvlan network attach all fail all OK
ip link add dummy/vxlan/geneve/macvlan/ipvlan/vlan, tc qdisc add clsact, iptables -j CT --notrack fail OK
sudo k3s check-config 2 fails passes except IPVS (out of scope)
Sandbox pause → resume → Service traffic OK

The three follow-up commits (xt_physdev, xt_limit+NFLOG, xt_CT+macvlan/ipvlan/vlan) each came out of this loop: one unsupported extension aborts an entire iptables-restore, so kube-router programmed zero pod-firewall rules and Calico's felix never reported Ready until these were added.

Cilium remains blocked regardless of this PR: cilium-agent hard-fails at startup with Require support for the eBPF JIT (CONFIG_BPF_JIT=y), and BPF_JIT (like KPROBES) has a Kconfig hard dependency on MODULES on 6.1 — relaxed upstream only in 6.8+/6.12+.

@gm-e2b
gm-e2b marked this pull request as ready for review July 28, 2026 14:22

@tomassrnka tomassrnka left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm based on slack conv

@gm-e2b
gm-e2b merged commit b15756f into main Jul 28, 2026
14 checks passed
@gm-e2b
gm-e2b deleted the kube-networking-cni branch July 28, 2026 15:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants