feat(eks): add option to disable k3s's bundled CNI (#1793)

* feat(eks): add option to disable k3s's bundled CNI

Adds eks.disable-cni config to start k3s with --flannel-backend=none
--disable-network-policy --disable-kube-proxy, since flannel and
kube-proxy run embedded in the k3s server process and can't be evicted
after the fact — a real CNI like Cilium can only take over if k3s never
starts its own. Also makes / rshared before k3s starts so Cilium's BPF
filesystem mount succeeds inside the nested container.

* fix(eks): surface rshare mount failures and document disable-cni

Addresses review feedback: a failed mount --make-rshared / was
silently swallowed, making later CNI failures confusing to trace back;
it's now reported to stderr instead. Also reworded comments claiming
the entrypoint used only sh builtins (it calls mount and k3s, both
external commands), and added the disable-cni knob to application.yml
alongside the other EKS options so it's discoverable.
This commit is contained in:
Mike Attara authored and GitHub committed 2026-07-28 22:04:12 -05:00
1 parent 9b6695c321
commit 444e4a6e89
4 files changed
+121 -4

No files matched your search

@@ -1514,6 +1514,18 @@ public interface EmulatorConfig {
*/
@WithDefault("true")
boolean ecrRegistryMirror();
/**
* When true, starts k3s with {@code --flannel-backend=none --disable-network-policy
* --disable-kube-proxy} instead of its bundled networking stack. k3s's default flannel CNI
* and kube-proxy run embedded in the k3s server process itself (not separate, killable
* DaemonSets), so a real CNI (e.g. Cilium) can only cleanly take over if k3s never starts
* its own in the first place — there is no way to evict them after the fact. CoreDNS,
* local-path-provisioner, and metrics-server are unaffected; they don't depend on which CNI
* is in place.
*/
@WithDefault("false")
boolean disableCni();
}
interface InitHooksConfig {
@@ -111,9 +111,7 @@ public class EksClusterManager {
// filesystem, so chmod works correctly and data persists across container restarts.
String volumeName = ContainerStorageHelper.resourceName(config, "eks", null, cluster.getName());
List<String> serverArgs = new ArrayList<>(List.of("server",
"--disable=traefik",
"--tls-san=localhost"));
List<String> serverArgs = buildServerArgs(config.services().eks().disableCni());
ContainerBuilder.Builder specBuilder = containerBuilder.newContainer(image)
.withName(containerName)
@@ -141,7 +139,20 @@ public class EksClusterManager {
}
}
ContainerSpec spec = specBuilder.withCmd(serverArgs).build();
if (config.services().eks().disableCni()) {
// A container's /sys mount defaults to private propagation, which breaks
// Cilium's BPF filesystem mount ("mounted on /sys but it is not a shared or
// slave mount") — real EKS/kubeadm nodes don't hit this since they're VMs,
// not nested containers. `mount --make-rshared /` before k3s starts fixes
// it; kind's own node image runs the same fix in its entrypoint for the
// same reason. RSHARE_ENTRYPOINT is POSIX sh-compatible (no bashisms) — the
// k3s image has no bash, only busybox sh.
specBuilder.withEntrypoint(RSHARE_ENTRYPOINT);
specBuilder.withCmd(buildRshareWrappedCmd(serverArgs));
} else {
specBuilder.withCmd(serverArgs);
}
ContainerSpec spec = specBuilder.build();
// create -> inject webhook kubeconfig -> start, so the file exists before the API server boots.
String containerId = lifecycleManager.create(spec);
@@ -248,6 +259,47 @@ public class EksClusterManager {
LOG.infov("Stopped k3s container for cluster {0}", cluster.getName());
}
/**
* Builds the k3s {@code server} command-line args. When {@code disableCni} is true, flannel,
* k3s's default network policy controller, and kube-proxy are all disabled up front — see the
* {@code disableCni} config javadoc for why this must happen at startup, not after the fact.
*/
static List<String> buildServerArgs(boolean disableCni) {
List<String> serverArgs = new ArrayList<>(List.of("server",
"--disable=traefik",
"--tls-san=localhost"));
if (disableCni) {
serverArgs.add("--flannel-backend=none");
serverArgs.add("--disable-network-policy");
serverArgs.add("--disable-kube-proxy");
}
return serverArgs;
}
/**
* Overrides the image's default {@code ["/bin/k3s"]} entrypoint so a {@code mount
* --make-rshared /} can run immediately before k3s starts (see the disableCni branch
* in {@link #startCluster} for why). POSIX sh-compatible — the k3s image has no bash.
* A failed mount is logged to stderr rather than silently ignored, since it means the
* external CNI's BPF filesystem mount will fail later in a much more confusing way.
*/
static final List<String> RSHARE_ENTRYPOINT = List.of("sh", "-c",
"mount --make-rshared / || echo 'floci: WARN: mount --make-rshared / failed; "
+ "external CNI may not work' >&2; exec /bin/k3s \"$@\"");
/**
* Builds the CMD to pair with {@link #RSHARE_ENTRYPOINT}: an unused $0 placeholder
* followed by the real k3s server args, so the entrypoint's "$@" expands to exactly
* {@code serverArgs} — the same args {@code withCmd(serverArgs)} would pass directly
* when the entrypoint isn't overridden.
*/
static List<String> buildRshareWrappedCmd(List<String> serverArgs) {
List<String> wrappedCmd = new ArrayList<>();
wrappedCmd.add("floci-k3s");
wrappedCmd.addAll(serverArgs);
return wrappedCmd;
}
/**
* Resolves the public {@code describe-cluster} endpoint. Returns the container DNS name only when
* Floci runs in a container and {@code endpoint-mode=network}; otherwise the host-reachable