You set up a k3s cluster for an edge workload — three nodes in a small DC, decent traffic, mostly L7 with a few stateful services. After a few months a profiling pass shows kube-proxy burning real CPU during traffic spikes and the iptables rule table on each node has grown into the tens of thousands. The cluster is doing nothing wrong; the architecture is. iptables NAT for service traffic was fine when “service” meant “a handful of frontends” — once you have hundreds of pods churning, the rule table becomes a measurable bottleneck and a debugging black hole. The fix is to swap k3s’s default flannel + kube-proxy combo for Cilium running in eBPF mode, where service traffic never touches iptables and you get Hubble flow visibility for free.
What’s happening
k3s ships with flannel CNI and the standard iptables-based kube-proxy. Both work, both are well-understood, both have limits. iptables kube-proxy turns every Service into a chain of NAT rules; the kernel walks that chain on every packet hitting a service IP, and with five thousand pods you’re walking a non-trivial number of rules per packet. eBPF kube-proxy replacement (KPR) compiles the service map into a BPF program that runs in the kernel without iptables traversal — order of magnitude fewer instructions per packet on busy services, and the rule table on each node shrinks to a handful of policy chains. The flip side: BPF KPR needs a kernel new enough to handle the program set (5.4 minimum, 5.14+ recommended for full feature parity), it requires you to disable k3s’s built-in kube-proxy entirely (not just override it), and it changes the observability story — iptables -L no longer tells you anything useful about service routing, but Cilium ships Hubble which is strictly better. This installer assumes you can rebuild the k3s cluster (or that you started fresh) — swapping CNI on a live cluster with workloads in flight is possible but messier than it sounds.
How to verify
Confirm kernel version on each node:
uname -r
# 5.14 or newer is the comfortable starting point
Confirm BPF filesystem is mountable:
mount | grep bpf
# bpf on /sys/fs/bpf type bpf (rw,nosuid,nodev,noexec,relatime)
ls /sys/fs/bpf
Count current iptables rules (gives you a before/after to look at):
iptables-save | wc -l
# baseline on a busy k3s cluster: 3000-10000+
If iptables is over a few thousand lines and you’re CPU-bound during peaks, you’re a candidate. Confirm k3s server config flags:
cat /etc/systemd/system/k3s.service.env 2>/dev/null
ps -ef | grep k3s | head -5
You’re looking for the presence (or absence) of --flannel-backend=none --disable-network-policy --disable-kube-proxy. If those flags aren’t set, the cluster is running flannel + iptables kube-proxy.
The fix
The script does three things: re-installs k3s with the right disable flags (this is the cleanest path; bringing up Cilium alongside an existing kube-proxy on an existing cluster works but produces config drift), installs Cilium 1.16 with eBPF KPR and Hubble enabled, and runs end-to-end verification — the BPF KPR map shows entries, the iptables count drops, a service is reachable through the eBPF path, and Hubble can observe flows. Edit the variables at the top: cluster IP, pod CIDR, service CIDR, k3s version.
#!/usr/bin/env bash
set -euo pipefail
### Cilium 1.16 + k3s 1.30 installer with eBPF kube-proxy replacement
### Run on the k3s server node (single-server) or first server (HA)
### Assumes a fresh node OR a willingness to reinstall k3s
if [[ "$(id -u)" -ne 0 ]]; then
echo "Run as root."
exit 1
fi
# === EDIT BEFORE RUNNING ===
K3S_VERSION="v1.30.5+k3s1"
CILIUM_VERSION="1.16.3"
NODE_IP="10.20.0.11" # this server's IP
POD_CIDR="10.42.0.0/16" # k3s default
SERVICE_CIDR="10.43.0.0/16" # k3s default
CLUSTER_NAME="edge-k3s"
HUBBLE_RELAY="true" # set to false if you don't want the Hubble UI
# ===========================
KERNEL_MAJ=$(uname -r | cut -d. -f1)
KERNEL_MIN=$(uname -r | cut -d. -f2)
if (( KERNEL_MAJ < 5 || (KERNEL_MAJ == 5 && KERNEL_MIN < 4) )); then
echo "ERROR: kernel $(uname -r) is too old for Cilium eBPF KPR."
echo " Need at least 5.4. Upgrade your kernel before continuing."
exit 1
fi
echo "==> Mounting BPF and cgroup-v2 filesystems"
mkdir -p /sys/fs/bpf
mount bpffs /sys/fs/bpf -t bpf || true
mkdir -p /run/cilium/cgroupv2
mount -t cgroup2 none /run/cilium/cgroupv2 || true
cat > /etc/fstab.d/cilium.conf <<'EOF' 2>/dev/null || true
bpffs /sys/fs/bpf bpf defaults 0 0
none /run/cilium/cgroupv2 cgroup2 defaults 0 0
EOF
echo "==> Setting kernel parameters"
cat > /etc/sysctl.d/99-cilium.conf <<'EOF'
net.ipv4.conf.all.rp_filter = 0
net.ipv4.conf.default.rp_filter = 0
net.ipv4.conf.lxc*.rp_filter = 0
net.ipv4.ip_forward = 1
net.bridge.bridge-nf-call-iptables = 1
net.bridge.bridge-nf-call-ip6tables = 1
EOF
modprobe br_netfilter || true
sysctl --system
echo "==> Installing k3s server with CNI/kube-proxy/network-policy disabled"
curl -sfL https://get.k3s.io | \
INSTALL_K3S_VERSION="${K3S_VERSION}" \
INSTALL_K3S_EXEC="server \
--node-ip=${NODE_IP} \
--cluster-cidr=${POD_CIDR} \
--service-cidr=${SERVICE_CIDR} \
--flannel-backend=none \
--disable-network-policy \
--disable-kube-proxy \
--disable=traefik \
--disable=servicelb \
--write-kubeconfig-mode=600 \
--tls-san=${NODE_IP}" \
sh -
echo "==> Waiting for k3s API"
for i in {1..60}; do
if k3s kubectl get node >/dev/null 2>&1; then break; fi
sleep 3
done
export KUBECONFIG=/etc/rancher/k3s/k3s.yaml
alias kubectl=k3s\ kubectl
echo "==> Pre-install state — node should be NotReady because no CNI is installed"
k3s kubectl get node
echo "==> Installing cilium CLI"
CILIUM_CLI_VERSION=$(curl -s https://raw.githubusercontent.com/cilium/cilium-cli/main/stable.txt)
CLI_ARCH=amd64
if [[ "$(uname -m)" == "aarch64" ]]; then CLI_ARCH=arm64; fi
curl -L --fail --remote-name-all \
"https://github.com/cilium/cilium-cli/releases/download/${CILIUM_CLI_VERSION}/cilium-linux-${CLI_ARCH}.tar.gz"
tar xzf "cilium-linux-${CLI_ARCH}.tar.gz" -C /usr/local/bin
rm -f "cilium-linux-${CLI_ARCH}.tar.gz"
echo "==> Installing Cilium ${CILIUM_VERSION} with eBPF kube-proxy replacement"
KUBERNETES_SERVICE_HOST="${NODE_IP}"
KUBERNETES_SERVICE_PORT="6443"
cilium install \
--version "${CILIUM_VERSION}" \
--set kubeProxyReplacement=true \
--set k8sServiceHost="${KUBERNETES_SERVICE_HOST}" \
--set k8sServicePort="${KUBERNETES_SERVICE_PORT}" \
--set ipam.operator.clusterPoolIPv4PodCIDRList[0]="${POD_CIDR}" \
--set cluster.name="${CLUSTER_NAME}" \
--set cluster.id=1 \
--set bpf.masquerade=true \
--set bpf.lbExternalClusterIP=true \
--set ipv4NativeRoutingCIDR="${POD_CIDR}" \
--set routingMode=native \
--set autoDirectNodeRoutes=true \
--set hubble.enabled=true \
--set hubble.metrics.enabled='{dns,drop,tcp,flow,icmp,http}' \
--set hubble.relay.enabled=${HUBBLE_RELAY} \
--set hubble.ui.enabled=${HUBBLE_RELAY} \
--set operator.replicas=1
echo "==> Waiting for cilium pods to be ready"
cilium status --wait
echo "==> Confirming kube-proxy is NOT running"
if k3s kubectl get pods -A | grep -q kube-proxy; then
echo "WARNING: kube-proxy pods still present — KPR will conflict."
else
echo " No kube-proxy pods. eBPF KPR is the only service-routing path."
fi
echo "==> Confirming Cilium handles services via BPF"
CILIUM_POD=$(k3s kubectl -n kube-system get pod -l k8s-app=cilium \
-o jsonpath='{.items[0].metadata.name}')
k3s kubectl -n kube-system exec "$CILIUM_POD" -- cilium status | grep -E 'KubeProxyReplacement|Host Routing|Masquerading'
k3s kubectl -n kube-system exec "$CILIUM_POD" -- cilium service list | head -10
echo "==> Measuring iptables rule table (should be small)"
echo " Lines: $(iptables-save | wc -l)"
echo "==> Smoke test: deploying nginx + Service, curling through eBPF KPR"
k3s kubectl create ns cilium-smoke
k3s kubectl -n cilium-smoke run web --image=nginx
k3s kubectl -n cilium-smoke expose pod web --port=80
k3s kubectl -n cilium-smoke wait --for=condition=ready pod/web --timeout=60s
SVC_IP=$(k3s kubectl -n cilium-smoke get svc web -o jsonpath='{.spec.clusterIP}')
echo " Service ClusterIP: ${SVC_IP}"
k3s kubectl -n cilium-smoke run curl-test --rm -i --restart=Never \
--image=curlimages/curl -- curl -s -m 5 -o /dev/null -w "%{http_code}\n" "http://${SVC_IP}"
k3s kubectl delete ns cilium-smoke
if [[ "${HUBBLE_RELAY}" == "true" ]]; then
echo "==> Enabling hubble client on this node"
HUBBLE_VERSION=$(curl -s https://raw.githubusercontent.com/cilium/hubble/master/stable.txt)
curl -L --fail --remote-name-all \
"https://github.com/cilium/hubble/releases/download/${HUBBLE_VERSION}/hubble-linux-amd64.tar.gz"
tar xzf hubble-linux-amd64.tar.gz -C /usr/local/bin
rm -f hubble-linux-amd64.tar.gz
echo " Run: cilium hubble port-forward&"
echo " hubble observe --follow"
fi
echo
echo "========================================"
echo "Cilium on k3s install complete"
echo "========================================"
echo
echo "Verify cluster:"
echo " k3s kubectl get nodes"
echo " cilium status"
echo " k3s kubectl -n kube-system get pods"
echo
echo "Inspect eBPF kube-proxy map:"
echo " k3s kubectl -n kube-system exec \\"
echo " \$(k3s kubectl -n kube-system get pod -l k8s-app=cilium -o jsonpath='{.items[0].metadata.name}') \\"
echo " -- cilium service list"
echo
echo "Hubble flows:"
echo " cilium hubble port-forward &"
echo " hubble observe --follow"
echo
echo "Join additional servers/agents with:"
echo " K3S_URL=https://${NODE_IP}:6443 K3S_TOKEN=\$(cat /var/lib/rancher/k3s/server/node-token) \\"
echo " curl -sfL https://get.k3s.io | INSTALL_K3S_VERSION=\"${K3S_VERSION}\" \\"
echo " INSTALL_K3S_EXEC='agent --flannel-backend=none --disable-network-policy --disable-kube-proxy' sh -"
Make it executable and run on the server node:
chmod 700 /root/install-cilium-k3s.sh
/root/install-cilium-k3s.sh
Once it returns clean, validate four things before declaring the cluster ready: cilium status reports KubeProxyReplacement: True, the iptables line count is in the hundreds (not thousands), cilium service list shows your services, and Hubble can see flows (hubble observe --follow from inside the cilium-agent pod). The most common first failure is the kernel — if cilium status reports KubeProxyReplacement: Disabled, check the cilium-agent log; if it’s complaining about missing BPF features, you need a newer kernel. The second most common is running this against a k3s install that still has kube-proxy — the --disable-kube-proxy flag has to be set at k3s install time, not added later. If you missed it, systemctl stop k3s and k3s-uninstall.sh is faster than trying to surgically remove kube-proxy from a running install.
We run k3s edge clusters on our managed cloud compute under Managed Cloud Ops with CNI selection, Hubble flow retention, and kernel updates coordinated so eBPF KPR keeps working across upgrades — start a scoping call if you want help.