Skip to content

Commit d7774fc

Browse files
authored
Merge pull request kubernetes#129653 from danwinship/nftables-ga
KEP-3866 nftables kube-proxy to GA
2 parents e62ce1c + 83595f5 commit d7774fc

File tree

5 files changed

+40
-13
lines changed

5 files changed

+40
-13
lines changed

cmd/kube-proxy/app/server_linux.go

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -36,13 +36,11 @@ import (
3636
"k8s.io/apimachinery/pkg/fields"
3737
"k8s.io/apimachinery/pkg/runtime"
3838
"k8s.io/apimachinery/pkg/watch"
39-
utilfeature "k8s.io/apiserver/pkg/util/feature"
4039
clientset "k8s.io/client-go/kubernetes"
4140
"k8s.io/client-go/tools/cache"
4241
toolswatch "k8s.io/client-go/tools/watch"
4342
utilsysctl "k8s.io/component-helpers/node/util/sysctl"
4443
"k8s.io/klog/v2"
45-
"k8s.io/kubernetes/pkg/features"
4644
"k8s.io/kubernetes/pkg/proxy"
4745
proxyconfigapi "k8s.io/kubernetes/pkg/proxy/apis/config"
4846
"k8s.io/kubernetes/pkg/proxy/iptables"
@@ -527,11 +525,9 @@ func platformCleanup(ctx context.Context, mode proxyconfigapi.ProxyMode, cleanup
527525
}
528526
}
529527

530-
if utilfeature.DefaultFeatureGate.Enabled(features.NFTablesProxyMode) {
531-
// Clean up nftables rules when switching to iptables or ipvs, or if cleanupAndExit
532-
if isIPTablesBased(mode) || cleanupAndExit {
533-
encounteredError = nftables.CleanupLeftovers(ctx) || encounteredError
534-
}
528+
// Clean up nftables rules when switching to iptables or ipvs, or if cleanupAndExit
529+
if isIPTablesBased(mode) || cleanupAndExit {
530+
encounteredError = nftables.CleanupLeftovers(ctx) || encounteredError
535531
}
536532

537533
if encounteredError {

pkg/features/versioned_kube_features.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -540,6 +540,7 @@ var defaultVersionedKubernetesFeatureGates = map[featuregate.Feature]featuregate
540540
NFTablesProxyMode: {
541541
{Version: version.MustParse("1.29"), Default: false, PreRelease: featuregate.Alpha},
542542
{Version: version.MustParse("1.31"), Default: true, PreRelease: featuregate.Beta},
543+
{Version: version.MustParse("1.33"), Default: true, PreRelease: featuregate.GA, LockToDefault: true},
543544
},
544545

545546
NodeInclusionPolicyInPodTopologySpread: {

pkg/proxy/apis/config/validation/validation.go

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@ import (
3030
logsapi "k8s.io/component-base/logs/api/v1"
3131
"k8s.io/component-base/metrics"
3232
apivalidation "k8s.io/kubernetes/pkg/apis/core/validation"
33-
"k8s.io/kubernetes/pkg/features"
3433
kubeproxyconfig "k8s.io/kubernetes/pkg/proxy/apis/config"
3534
netutils "k8s.io/utils/net"
3635
)
@@ -173,12 +172,9 @@ func validateProxyModeLinux(mode kubeproxyconfig.ProxyMode, fldPath *field.Path)
173172
validModes := sets.New[string](
174173
string(kubeproxyconfig.ProxyModeIPTables),
175174
string(kubeproxyconfig.ProxyModeIPVS),
175+
string(kubeproxyconfig.ProxyModeNFTables),
176176
)
177177

178-
if utilfeature.DefaultFeatureGate.Enabled(features.NFTablesProxyMode) {
179-
validModes.Insert(string(kubeproxyconfig.ProxyModeNFTables))
180-
}
181-
182178
if mode == "" || validModes.Has(string(mode)) {
183179
return nil
184180
}

pkg/proxy/nftables/README.md

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,4 +106,34 @@ This is implemented as follows:
106106
rule for ClusterIPs belonging to any of the ServiceCIDRs in `forward` and `output` hook, with a
107107
higher (i.e. less urgent) priority than the DNAT chains making sure all valid
108108
traffic directed for ClusterIPs is already DNATed. Drop rule will only
109-
be installed if `MultiCIDRServiceAllocator` feature is enabled.
109+
be installed if `MultiCIDRServiceAllocator` feature is enabled.
110+
111+
## Integrating with kube-proxy's nftables mode
112+
113+
Implementations of pod networking, NetworkPolicy, service meshes, etc, may need to be
114+
aware of some slightly lower-level details of kube-proxy's implementation.
115+
116+
Components other than kube-proxy should *never* make any modifications to the
117+
`kube-proxy` nftables table, or any of the chains, sets, maps, etc, within it. Every
118+
component should create its own table and only work within that table. However,
119+
you can ensure that rules in your own table will run before or after kube-proxy's rules
120+
by setting appropriate `priority` values for your base chains. In particular:
121+
122+
- Service traffic that needs to be DNATted will be DNATted by kube-proxy on a chain of
123+
`type nat` with `priority dstnat` and either `hook output` (for traffic on the
124+
"output" path) or `hook prerouting` (for traffic on the "input" or "forward" paths).
125+
(So chains in other tables that run before this will see traffic addressed to service
126+
IPs, while chains that run after this will see traffic addressed to endpoint IPs.)
127+
128+
- Service traffic that needs to be masqueraded will be SNATted on a chain of `type
129+
nat`, `hook postrouting`, and `priority srcnat`. (So chains in other tables that run
130+
before this will always see the original client IP, while chains that run after this
131+
will will see masqueraded source IPs for some traffic.)
132+
133+
- Traffic to services with no endpoints will be dropped or rejected from a chain with
134+
`type filter`, `priority dstnat-10`, and any of `hook input`, `hook output`, or `hook
135+
forward`.
136+
137+
Note that the use of `mark` to indicate what traffic needs to be masqueraded is *not*
138+
part of kube-proxy's public API, and you should not assume that you can cause traffic to
139+
be masqueraded (or not) by setting or clearing a particular mark bit.

test/featuregates_linter/test_data/versioned_feature_list.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -842,6 +842,10 @@
842842
lockToDefault: false
843843
preRelease: Beta
844844
version: "1.31"
845+
- default: true
846+
lockToDefault: true
847+
preRelease: GA
848+
version: "1.33"
845849
- name: NodeInclusionPolicyInPodTopologySpread
846850
versionedSpecs:
847851
- default: false

0 commit comments

Comments
 (0)