calico: Calico panics if kube-proxy using nftables mode

Expected Behavior

One of my nodes is emitting a warning about incompatible nft rules and then panic-looping while failing to log something.

Current Behavior

2023-09-17 16:22:39.290 [WARNING][12833] felix/table.go 765: iptables-nft-save command failed error=iptables-save failed because there are incompatible nft rules in the table ipVersion=0x4 stderr="" table="filter"
2023-09-17 16:22:39.290 [PANIC][12833] felix/table.go 771: iptables-nft-save command failed after retries ipVersion=0x4 table="filter"
panic: (*logrus.Entry) 0x400035db90

goroutine 152 [running]:
github.com/sirupsen/logrus.(*Entry).log(0x40001424d0, 0x0, {0x4000b84b70, 0x2e})
    /go/pkg/mod/github.com/sirupsen/logrus@v1.9.0/entry.go:260 +0x4c0
github.com/sirupsen/logrus.(*Entry).Log(0x40001424d0, 0x0, {0x4000a669e8?, 0x1?, 0x1?})
    /go/pkg/mod/github.com/sirupsen/logrus@v1.9.0/entry.go:304 +0x60
github.com/sirupsen/logrus.(*Entry).Logf(0x40001424d0, 0x0, {0x2bced89?, 0x6?}, {0x4000a66ab8?, 0x3?, 0x0?})
    /go/pkg/mod/github.com/sirupsen/logrus@v1.9.0/entry.go:349 +0x88
github.com/sirupsen/logrus.(*Entry).Panicf(...)
    /go/pkg/mod/github.com/sirupsen/logrus@v1.9.0/entry.go:387
github.com/projectcalico/calico/felix/iptables.(*Table).getHashesAndRulesFromDataplane(0x40002206c0)
    /go/src/github.com/projectcalico/calico/felix/iptables/table.go:771 +0x2f4
github.com/projectcalico/calico/felix/iptables.(*Table).loadDataplaneState(0x40002206c0)
    /go/src/github.com/projectcalico/calico/felix/iptables/table.go:608 +0x158
github.com/projectcalico/calico/felix/iptables.(*Table).Apply(0x40002206c0)
    /go/src/github.com/projectcalico/calico/felix/iptables/table.go:992 +0x290
github.com/projectcalico/calico/felix/dataplane/linux.(*InternalDataplane).apply.func4(0x7f5b6825c0?)
    /go/src/github.com/projectcalico/calico/felix/dataplane/linux/int_dataplane.go:2120 +0x48
created by github.com/projectcalico/calico/felix/dataplane/linux.(*InternalDataplane).apply
    /go/src/github.com/projectcalico/calico/felix/dataplane/linux/int_dataplane.go:2119 +0xf18

Possible Solution

The error doesn’t suggest how to remove the incompatible rules. I’ve tried nft flush ruleset but the problem consistently comes back.

Steps to Reproduce (for bugs)

Context

Your Environment

  • Calico version 3.26.1
  • Orchestrator version (e.g. kubernetes, mesos, rkt): kubernetes v1.25.13+k3s1
  • Operating System and version: Debian Bullseye (5.15.32-v8+)
  • Link to your project (optional):

About this issue

  • Original URL
  • State: closed
  • Created 3 years ago
  • Reactions: 3
  • Comments: 25 (12 by maintainers)

Most upvoted comments

Quick update - just merged a Calico nftables dataplane implementation compatible with nftables kube-proxy here: https://github.com/projectcalico/calico/pull/8780

tech-preview support is currently scheduled for Calico v3.29.0, and a GA release will come sometime after that once we determine it to be sufficiently stable.

Sorry @tomastigera @zzvara, setting the mode to legacy is not a solution to this problem. The current best answer is to use iptables-nft for all your components until we get a proper nftables backend in place. Using a mix of legacy iptables and nftables doesn’t fail (assuming your kernel supports both) but the behaviour is very counter-intuitive. nftables can “undo” the verdict made by iptables-legacy so your policy may not get properly enforced and the failures will be confusing.

I understand the desire to jump to “proper” nftables mode ASAP but please bear in mind that kubernetes nftables mode is in Alpha in v1.29. It’s not ready for prod use either.

We’ve been relying on the itpables-nft translation layer for a long time, which has meant that we’re in sync with kube-proxy. If we moved to native nftables before kube-proxy then we’d have caused the same problem for kube-proxy!

Clearly, now that kube-proxy has nftables support, we also need to add it ASAP in order to remain in sync. I for one didn’t spot that nftables support was on the slate for v1.29.

I’ve lost several days iterating through this problem, and it’s unsolveable without a complete rewrite of the NFT support in Calico.

The underlying problem here is that instead of adding real nftables support, it was added by using the iptables emulation layer. If any other subsystem on the node makes use of nft features incompatible with iptables, calico-node breaks entirely and ceases to work.

iptables-nft-save command failed error=iptables-save failed because there are incompatible nft rules in the table ipVersion=0x4 stderr=“” table=“filter”

At this time the current versions of all of the following make nft-specific changes to the rules which will cause calico to break:

  • docker
  • CRI
  • kubernetes (specifically kube-proxy)

There is no solution, so people are being forced to switch away from Calico to restore their kubernetes cluster networking

Set FELIX_IPTABLESBACKEND from Auto to Legacy and you are fixed.

@luniHw Yes, the workaround is to not use kube-proxy in nftables mode with Calico!

I’ve lost several days iterating through this problem, and it’s unsolveable without a complete rewrite of the NFT support in Calico.

The underlying problem here is that instead of adding real nftables support, it was added by using the iptables emulation layer. If any other subsystem on the node makes use of nft features incompatible with iptables, calico-node breaks entirely and ceases to work.

iptables-nft-save command failed error=iptables-save failed because there are incompatible nft rules in the table ipVersion=0x4 stderr=“” table=“filter”

At this time the current versions of all of the following make nft-specific changes to the rules which will cause calico to break:

  • docker
  • CRI
  • kubernetes (specifically kube-proxy)

There is no solution, so people are being forced to switch away from Calico to restore their kubernetes cluster networking

We are Also facing the Same Issue in the below environment.

Operating System : Debian Bookworm 12.1
Kernel version : 6.1.0-12-amd64
Canal Version : v3.24.5
Canal Iptables version : v1.8.6 (nf_tables)
RKE2 Version : v1.26.0+rke2r2
Debian Bookworm Host Iptables Version : 1.8.9

Please let us know if there is any resolution.

On observation that we have seen is if we flush the IP tables we are not seeing this issue.

The nft list ruleset command output looks like the below.

nft-list-ruleset-bookworm.txt