2445 Commits

Author SHA1 Message Date
Adrian Moisey
55245ec4ec Make TestOverallNFTablesRulesIPv6 test 2026-07-28 10:26:42 +02:00
Adrian Moisey
50c7121fc7 Add unit test for proxier Endpoint DNAT rules 2026-07-28 10:26:39 +02:00
Adrian Moisey
4209adaed7 Fix single-endpoint DNAT rule
The previous rule would cause nft to coredump on IPv6:
```console
$ nft add rule ip6 kube-proxy 'svc-ABC123-default/my-svc/tcp/https' meta l4proto tcp dnat ip6 addr . port to fd00:10:244::4 . 6443
Assertion failed: dreg < ctx->reg_low (src/netlink_linearize.c: netlink_gen_expr: 911)
Aborted                    (core dumped) nft add rule ip6 kube-proxy 'svc-ABC123-default/my-svc/tcp/https' meta l4proto tcp dnat ip6 addr . port to fd00:10:244::4 . 6443
```

The new rule allows IPv6 without coredumping.
2026-07-27 13:06:58 +02:00
Dan Winship
ce01dea3f7 Make nftables metrics linux-specific 2026-07-22 17:32:06 +00:00
Antonio Ojea
7f7ff95304 kube-proxy: Enable netlink support for nftables mode by default
We introduced a feature gate "NFTablesNetlink" that is Beta (enabled by default).

When this feature gate is enabled, kube-proxy initializes the knftables client with the `knftables.UseNetlink` option.
This enables using netlink directly for listing rules instead of parsing the output of the `nft` command-line binary, improving performance.

Using a feature gate allows us to safely roll this out while giving users the ability to opt-out in case of problems.

Change-Id: Id68cbd314c40da65664a3d3b30ff78d720043ddc
2026-07-22 17:31:14 +00:00
Antonio Ojea
f0b82d92de Revert "pkg/proxy/nftables: fix kube-proxy crash with newer nftables versions"
This reverts commit 117df3de4d.
2026-07-22 17:31:13 +00:00
Adrian Moisey
b7a9abad89 kube-proxy/nftables: avoid numgen map for single-endpoint service DNAT 2026-07-21 19:14:23 +02:00
kubernetes-prow[bot]
7b8fb5ef24 Merge pull request #138427 from AustinAbro321/enable-localhost-nodeport-userspace-proxy
kube-proxy: serve localhost NodePorts in nftables mode
2026-07-21 16:03:44 +00:00
Austin Abro
6bc5b884a6 kube-proxy: serve localhost NodePorts in nftables mode
Add a userspace proxy that accepts TCP connections on loopback NodePort
addresses and forwards them into the nftables data path, gated behind the
new KubeProxyNFTablesLocalhostNodePorts feature gate and enabled when
--nodeport-addresses explicitly includes loopback.

Signed-off-by: Austin Abro <austinabro321@gmail.com>
2026-07-21 08:31:03 -04:00
Austin Abro
9db3c1074a kube-proxy: add localhost/all nodeport-addresses keywords
Extend --nodeport-addresses to accept the "localhost" and "all" keywords
alongside "primary", expanding them to the corresponding loopback and
zero CIDRs.

Signed-off-by: Austin Abro <austinabro321@gmail.com>
2026-07-17 16:36:18 -04:00
kubernetes-prow[bot]
566951ae3c Merge pull request #140150 from ravindudanthanarayana/docs/fix-nftables-readme-typo
docs: fix duplicated word in nftables README
2026-07-17 18:05:41 +00:00
kubernetes-prow[bot]
7609ed9769 Merge pull request #138833 from alexmchughdev/perf-preallocate-ipset-list-results
kube-proxy/ipvs/ipset: preallocate ListEntries result with bound capacity
2026-07-17 18:05:33 +00:00
kubernetes-prow[bot]
04ea5bc4d5 Merge pull request #138831 from alexmchughdev/perf-preallocate-ipvs-runner
kube-proxy/ipvs: preallocate result slices in runner getters
2026-07-17 18:05:25 +00:00
kubernetes-prow[bot]
eee287c67f Merge pull request #139247 from danwinship/utiliptables-cleanup
remove old workarounds in utiliptables
2026-07-17 12:41:25 +00:00
kubernetes-prow[bot]
52a35b12ff Merge pull request #138183 from abishekgiri/codex-fix-kube-proxy-node-manager-exit
Restart kube-proxy on node IP changes and deletion
2026-07-10 17:25:43 +00:00
kubernetes-prow[bot]
5d6c0c7f97 Merge pull request #140056 from adrianmoisey/kube-proxy-managed-fields
Strip managedFields in kube-proxy informers to reduce informer cache size
2026-07-09 13:22:31 +00:00
Antonio Ojea
eba60f9995 proxy: consolidate EndpointSlice logging
Moves endpoint logging from endpointslicecache.go down to endpointschangetracker.go merge and unmerge methods to be consistent with service updates, without losing endpoint tracking information.

Change-Id: I09369a4b32929d8df4b520921d74223090872a60
2026-07-03 15:27:42 +00:00
Antonio Ojea
2521c2effd proxy: log nodePort changes for improved observability
Logs when a nodePort is configured, cleared, or removed from a service, similar to how endpoints are logged, to improve traceability in kube-proxy.

Change-Id: I75179292cb7ef52649b6fb3081afea1d0c9534af
2026-07-03 09:13:27 +00:00
ravindudanthanarayana
1dc6846c42 docs: fix duplicated word in nftables README
Signed-off-by: ravindudanthanarayana <ravindu.danth@gmail.com>
2026-07-01 17:47:17 +05:30
Joe Betz
e89ecc6af0 generate 2026-06-30 18:02:28 -04:00
kubernetes-prow[bot]
b6b907fda0 Merge pull request #138668 from yashsingh74/cleanup-test
nftables: add unit tests for CleanupLeftovers
2026-06-30 13:50:11 +00:00
yashsingh74
0d77ee7a6c nftables: add unit tests for CleanupLeftovers
Signed-off-by: yashsingh74 <yashsingh1774@gmail.com>
2026-06-30 13:00:37 +05:30
Adrian Moisey
a26b0205b3 Strip managedFields in kube-proxy informers to reduce informer cache size 2026-06-27 16:33:57 +02:00
Davanum Srinivas
92ce184653 kube-proxy: detect host CPU count via cpuset.NumCPU instead of cadvisor
detectNumCPU sized nf_conntrack_max using github.com/google/cadvisor/lib
machine topology. nf_conntrack_max is host-wide, so it must be sized from the
node's CPU count, not runtime.NumCPU(): the latter honors the process cpuset
and undercounts when kube-proxy runs under a static CPU policy, which is the
behavior cadvisor worked around (kubernetes/kubernetes#99225).

Use cpuset.NumCPU() from k8s.io/utils, which reads the node's online CPU count
from /sys/devices/system/cpu/online, with a runtime.NumCPU() fallback. This
drops the cadvisor dependency from pkg/proxy/conntrack and bumps k8s.io/utils
to pick up cpuset.NumCPU.
2026-06-26 08:01:46 -04:00
kubernetes-prow[bot]
fbef17bc5f Merge pull request #139870 from dims/cadvisor-lib
kubelet: depend on github.com/google/cadvisor/lib
2026-06-25 16:46:29 +00:00
kubernetes-prow[bot]
00b16544cd Merge pull request #137516 from luiscorreiaOps/fix-nftables-typo
docs: fix duplicated word in pkg/proxy/nftables README
2026-06-21 15:23:35 +00:00
Davanum Srinivas
997834af0f import-boss: allow github.com/google/cadvisor/lib only where used; forbid the full module
Add import-boss .import-restrictions so the lean github.com/google/cadvisor/lib module is allowed only in the directories that consume it -- pkg/kubelet, cmd/kubelet/app, and pkg/proxy/conntrack -- and forbidden everywhere else. The repo-root .import-restrictions default-denies all github.com/google/cadvisor imports; the three consumer subtrees re-allow only .../lib.
2026-06-20 17:27:17 -04:00
Davanum Srinivas
f451aa0762 kubelet: depend on github.com/google/cadvisor/lib
Migrate the kubelet (and the kube-proxy conntrack helper) off the full github.com/google/cadvisor module onto the lean github.com/google/cadvisor/lib: repoint info/v1+info/v2 type usage to lib/model and the manager/fs/cache/etc. consumers to lib/*; regenerate the cadvisor.Interface mocks; keep the kubelet-pinned cAdvisor global flags via lib/cadvisorflags.

go.mod: require + replace github.com/google/cadvisor/lib (=> the dims/cadvisor/lib fork for now, until lib is tagged) and drop the full github.com/google/cadvisor module entirely; keep github.com/containerd/containerd/api at v1.11.0 (matching upstream master); add github.com/google/cadvisor to unwanted-dependencies.json unwantedModules so the full module cannot be re-vendored.

test/e2e_node: the one remaining consumer of the full module -- the node-e2e ResourceCollector, which used the v2 HTTP client (client/v2) + v2 API types (info/v2) -- now scrapes the standalone cAdvisor pod's /api/v2.1/stats directly over HTTP+JSON, so test/e2e_node depends on no cAdvisor package. No change to the kubelet's stats surfaces.
2026-06-20 17:27:16 -04:00
Kubernetes Prow Robot
3520485f85 Merge pull request #139503 from princepereira/ppereira-create-lb-failure
Handling syscall failures when hns is not running.
2026-06-13 00:52:47 +05:30
Prince Pereira
bc9e4c12ef Handling sycall failures when hns is not running. 2026-06-12 17:10:32 +05:30
Kubernetes Prow Robot
dac71e780a Merge pull request #139629 from Bafff/fix/conntrack-cleanup-no-endpoints
kube-proxy: clear stale conntrack entries for UDP services with no endpoints
2026-06-12 13:26:49 +05:30
Baf
fd81afe040 kube-proxy: clear stale conntrack entries for UDP services with no endpoints
The conntrack reconciler skips services without serving endpoints, so
conntrack entries established while endpoints existed are never removed
when a UDP service scales down to zero. The REJECT (iptables) / reject
(nftables) rule installed for such services does not cover those flows:
they are DNATed to the deleted endpoint IP before the rule, which
matches on the service IP, can be evaluated. One-way UDP senders (e.g.
statsd clients) refresh the 30s conntrack timeout with every packet, so
the stale flows blackhole traffic to the deleted pod IP indefinitely;
recovery only happens when the service gets an endpoint again.

This was handled before the reconciler rewrite (kubernetes#127318):
the event-based cleanup cleared entries for every deleted UDP endpoint
regardless of how many endpoints remained.

Process services with an empty endpoints set instead of skipping them,
so every entry directed to their ClusterIP, LoadBalancer IP and
ExternalIP frontends is treated as stale and deleted.

NodePort cleanup is still skipped for services without serving
endpoints: NodePort entries are matched on the destination port only,
and with an empty endpoints set that would also remove UDP flows not
owned by kube-proxy (e.g. traffic to an unrelated host on the same
port).
2026-06-11 19:01:48 +01:00
Prince Pereira
c62228debd Handling sycall failures when hns is not running. 2026-06-11 21:28:50 +05:30
Prince Pereira
92c1071355 Handling sycall failures when hns is not running. 2026-06-11 21:28:45 +05:30
Prince Pereira
57cfc45762 Handling sycall failures when hns is not running. 2026-06-11 21:14:49 +05:30
Prince Pereira
ba9ce27fd7 Handling sycall failures when hns is not running. 2026-06-11 21:14:42 +05:30
Lukasz Wojciechowski
a800e7077f Fix TestClassifyLBError test case for nil error
The classifyLBError function returns lbErrNone when err is nil,
but the test was incorrectly expecting lbErrOther.

Also add lbErrNone to TestLBErrorTypeConstants verification.
2026-06-10 23:54:35 +02:00
Prince Pereira
62f1d9062c Add Prometheus metrics for KubeProxy failed loadbalancer operations 2026-06-09 20:30:36 +00:00
Vinayak Mohanty
4d306fc68e fix: truncate service comments in nftables to prevent length limit violations
refactor: rename svcPortNameString to svcPortComment and update test validation in nftables proxier
2026-06-06 01:49:08 +05:30
Adrian Moisey
f7265100cb KEP-5495: Add featuregate for IPVS 2026-06-03 21:04:16 +02:00
ytcisme
3616ffa284 proxy/ipvs: avoid per-interface RTM_GETADDR dump in GetAllLocalAddressesExcept
GetAllLocalAddressesExcept previously iterated over net.Interfaces() and
called iface.Addrs() for each interface. iface.Addrs() internally performs
a full RTM_GETADDR netlink dump for the entire node and then filters in
user space. With many interfaces and many addresses (for example tens of
thousands of ClusterIPs bound to kube-ipvs0) the cost is
O(N_interfaces * N_addresses) and dominates syncProxyRules latency.

This change replaces the per-interface loop with a single
netlink.AddrList(nil, unix.AF_UNSPEC) call that dumps all addresses on
the node in one RTM_GETADDR request, then filters by LinkIndex in user
space. This makes the call O(N_addresses) and avoids the per-interface
fan-out.

On a production node with 251 interfaces and 19757 addresses, this
reduces GetAllLocalAddressesExcept latency from 34.8s to 60ms (~705x).
2026-05-24 13:31:10 +08:00
Dan Winship
6ee779e962 Assume iptables has --random-fully
(This became available in the same release as iptables-restore -w, so
we're already assuming it.)
2026-05-22 12:03:54 -04:00
Joe Betz
9d65aeabb6 Explicitly disable validation-gen where not needed 2026-05-12 12:49:01 -04:00
Joe Betz
119a1460c1 Generate deepcopy 2026-05-11 12:27:56 -04:00
alexmchughdev
9727de2d9d kube-proxy/ipvs/ipset: preallocate ListEntries result with bound capacity
ListEntries' result slice is bounded by the number of lines parsed from
the ipset output (`len(strs)`). Pass that as the make() capacity so
the slice doesn't need to be regrown as entries are appended.

No behavior change.
2026-05-06 20:04:58 +01:00
alexmchughdev
50f5cb9046 kube-proxy/ipvs: preallocate result slices in runner getters
GetVirtualServers and GetRealServers each build a result slice by
appending one entry per source element (`ipvsSvcs` and `dsts`
respectively). Pass the source length as the make() capacity so the
slice does not need to be regrown during the loop.

No behavior change.
2026-05-06 20:03:36 +01:00
Dan Winship
0af2c0a767 Pass complete KubeProxyConfiguration to NewNodeManager 2026-04-29 10:35:14 -04:00
Dan Winship
6492838d08 Pass complete KubeProxyConfiguration to NewProxier methods
Simplify the interface between cmd/kube-proxy and the backends by
passing the complete KubeProxyConfiguration to the backend rather than
having kube-proxy need to know specifically which fields each backend
cares about.
2026-04-29 10:35:12 -04:00
Dan Winship
fe50a9420a Consistently import pkg/proxy/apis/config as kubeproxyconfig 2026-04-29 08:51:50 -04:00
Kubernetes Prow Robot
7d3b347d20 Merge pull request #138571 from aojea/proxy_large_cluster_nosync
kube-proxy: don't do full periodic syncs on large cluster mode
2026-04-27 03:12:46 +05:30