Skip to content

fix(k8s): use the node's configured iptables backend for node prep - #2145

Merged
katiewasnothere merged 2 commits into
apple:mainfrom
guanchzhou:fix-k8s-node-prep-iptables-backend
Sep 24, 2026
Merged

katiewasnothere merged 2 commits into
apple:mainfrom
guanchzhou:fix-k8s-node-prep-iptables-backend

Conversation

@guanchzhou

@guanchzhou guanchzhou commented Aug 21, 2026 •

Copy link
Copy Markdown
Contributor

Fixes #2120

Summary

Use the node image's configured iptables alternative for the two TCP MSS clamping rules instead of hard-coding iptables-nft.

The original failure is specific to installations that still boot a kernel without nftables support. Container upgrades can retain an existing pre-1.0 guest kernel because container system start does not replace a kernel that is already installed. On the retained vmlinux-6.12.28-153 kernel, node preparation aborts when the hard-coded iptables-nft commands fail.

The current recommended Kata 3.32.0 kernel (vmlinux-6.18.35-197-debug) has CONFIG_NF_TABLES=y; with that kernel, the existing iptables-nft commands work and an unmodified Container 1.4.1 completes container k8s create. This corrects the earlier interpretation that the failure was a Container 1.3.1 regression.

Why this change is still useful

kindest/node selects an iptables backend during its entrypoint and updates /etc/alternatives/iptables before node preparation runs. On the retained kernel, it selects iptables-legacy, which works. Calling /usr/sbin/iptables respects that node-image decision and lets node preparation work with retained or deliberately selected kernels rather than assuming nftables is available.

Appending || true would also prevent the abort, but it would silently omit the MSS clamping rules. This change keeps the rules and only removes the backend assumption.

The separate upgrade-path improvement discussed in #2120 would be to detect an outdated Container-managed default kernel and notify or prompt the user without silently replacing a deliberately selected custom kernel.

Evidence

On Container 1.4.1 with the retained vmlinux-6.12.28-153 kernel:

$ /usr/sbin/iptables-nft -t mangle -S
iptables v1.8.11 (nf_tables): Could not fetch rule set generation id: Invalid argument

$ /usr/sbin/iptables --version
iptables v1.8.11 (legacy)

Both TCPMSS rules apply successfully through /usr/sbin/iptables.

After installing the recommended kernel:

$ container system kernel set --recommended --force
vmlinux-6.18.35-197-debug

kindest/node:v1.35.5 reports CONFIG_NF_TABLES=y, iptables-nft -t mangle -S succeeds, and an unmodified container k8s create --cpus 2 --memory 4g completes successfully.

Verification

  • swift build --product container
  • swift build --target k8s
  • The changed node-prep commands apply both TCPMSS rules on the retained kernel through its configured legacy alternative.
  • End-to-end container k8s create was reproduced failing on the retained kernel and succeeding after switching to the recommended kernel.

Environment: macOS 27.0, Apple silicon, Container 1.4.1, node image docker.io/kindest/node:v1.35.5.

The node-prep script hardcodes /usr/sbin/iptables-nft for the two TCP MSS
clamping rules, but the default node image runs a kernel with no nftables
support, so those calls always fail:

  $ ls /proc/net/nf_tables*
  ls: cannot access '/proc/net/nf_tables*': No such file or directory
  $ /usr/sbin/iptables-nft -t mangle -S
  iptables v1.8.11 (nf_tables): Could not fetch rule set generation id: Invalid argument

/usr/sbin/iptables resolves through alternatives to the backend the image is
actually set up for -- legacy in kindest/node -- and the same two rules apply
cleanly through it. On an image whose kernel does carry nftables, alternatives
selects nft, so naming iptables is strictly more portable than naming a
specific backend.

Because nodePrepScript runs under set -e and these are its last two lines, the
failure aborts node prep and surfaces the accumulated stdout of the commands
that already succeeded, which is why the reported error names a sysctl that
worked rather than the command that failed.

Fixes apple#2120
@katiewasnothere

Copy link
Copy Markdown
Contributor

Hi @guanchzhou Could you update the description here with the findings from #2120? Otherwise this lgtm

@guanchzhou

Copy link
Copy Markdown
Contributor Author

@katiewasnothere updated. The description now includes the issue findings: the failure comes from an upgraded installation retaining the pre-1.0 kernel, the current recommended Kata 3.32.0 kernel works with the existing nft commands, and this change remains useful for retained or custom kernels because it respects the node image’s configured iptables backend.

@katiewasnothere

Copy link
Copy Markdown
Contributor

@guanchzhou I'm not sure why the CI is in the weird state it's in. Could you try pushing an empty update to this branch and I'll retriever the workflow?

The build workflow is stuck in a stale state; no code changes.
@guanchzhou

Copy link
Copy Markdown
Contributor Author

@guanchzhou I'm not sure why the CI is in the weird state it's in. Could you try pushing an empty update to this branch and I'll retriever the workflow?

Thanks @katiewasnothere, I've added dummy commit.

@github-actions

Copy link
Copy Markdown

Code Coverage

Tier Line Coverage
Unit 24.98%
Integration 66.76%
Combined 76.21%

@katiewasnothere
katiewasnothere merged commit eafe6b8 into apple:main Sep 24, 2026
3 checks passed
@guanchzhou
guanchzhou deleted the fix-k8s-node-prep-iptables-backend branch September 24, 2026 18:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: container k8s create fails when node preparation invokes iptables-nft

2 participants