Skip to content

Commit efc4b12

Browse files
committed
add ExternalTrafficPolicy support for External IPs in iptables kubeproxy
1 parent df9a567 commit efc4b12

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

pkg/proxy/iptables/proxier.go

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1070,8 +1070,13 @@ func (proxier *Proxier) syncProxyRules() {
10701070
"-d", utilproxy.ToCIDR(net.ParseIP(externalIP)),
10711071
"--dport", strconv.Itoa(svcInfo.Port()),
10721072
)
1073-
// We have to SNAT packets to external IPs.
1074-
writeLine(proxier.natRules, append(args, "-j", string(KubeMarkMasqChain))...)
1073+
1074+
destChain := svcXlbChain
1075+
// We have to SNAT packets to external IPs if externalTrafficPolicy is cluster.
1076+
if !(utilfeature.DefaultFeatureGate.Enabled(features.ExternalPolicyForExternalIP) && svcInfo.OnlyNodeLocalEndpoints()) {
1077+
destChain = svcChain
1078+
writeLine(proxier.natRules, append(args, "-j", string(KubeMarkMasqChain))...)
1079+
}
10751080

10761081
// Allow traffic for external IPs that does not come from a bridge (i.e. not from a container)
10771082
// nor from a local process to be forwarded to the service.
@@ -1080,11 +1085,11 @@ func (proxier *Proxier) syncProxyRules() {
10801085
externalTrafficOnlyArgs := append(args,
10811086
"-m", "physdev", "!", "--physdev-is-in",
10821087
"-m", "addrtype", "!", "--src-type", "LOCAL")
1083-
writeLine(proxier.natRules, append(externalTrafficOnlyArgs, "-j", string(svcChain))...)
1088+
writeLine(proxier.natRules, append(externalTrafficOnlyArgs, "-j", string(destChain))...)
10841089
dstLocalOnlyArgs := append(args, "-m", "addrtype", "--dst-type", "LOCAL")
10851090
// Allow traffic bound for external IPs that happen to be recognized as local IPs to stay local.
10861091
// This covers cases like GCE load-balancers which get added to the local routing table.
1087-
writeLine(proxier.natRules, append(dstLocalOnlyArgs, "-j", string(svcChain))...)
1092+
writeLine(proxier.natRules, append(dstLocalOnlyArgs, "-j", string(destChain))...)
10881093
} else {
10891094
// No endpoints.
10901095
writeLine(proxier.filterRules,

0 commit comments

Comments
 (0)