Commit Graph

1879 Commits

Author SHA1 Message Date
DingShujie
e1f0b85334 Dismiss connects to localhost early in the service chain
Signed-off-by: DingShujie <dingshujie@huawei.com>
2022-10-11 13:57:35 +08:00
Amim Knabben
7df6c02288 Remove Linux and Windows Kube-proxy Userspace mode 2022-10-05 16:59:02 -03:00
daschott
5bbf421841 Fix winkernel proxier setting the wrong HNS loadbalancer ID for ingress IP 2022-10-03 13:23:56 -07:00
Dan Winship
818de5a545 proxy/iptables: Add metric for partial sync failures, add test 2022-09-26 16:31:42 -04:00
Dan Winship
ab326d2f4e proxy/iptables: Don't rewrite chains that haven't changed
iptables-restore requires that if you change any rule in a chain, you
have to rewrite the entire chain. But if you avoid mentioning a chain
at all, it will leave it untouched. Take advantage of this by not
rewriting the SVC, SVL, EXT, FW, and SEP chains for services that have
not changed since the last sync, which should drastically cut down on
the size of each iptables-restore in large clusters.
2022-09-26 16:30:42 -04:00
Quan Tian
8a73e79777 Fix outdated code comments of proxierHealthServer
Signed-off-by: Quan Tian <qtian@vmware.com>
2022-09-21 23:21:19 +08:00
Kubernetes Prow Robot
e8e20ce563
Merge pull request #112451 from aojea/proxy_logging
kube-proxy use debug log level for Service cache operations
2022-09-19 14:21:45 -07:00
Kubernetes Prow Robot
918f84cd90
Merge pull request #112463 from Nordix/fix-ipvs-filter
Corrects target in the KUBE-IPVS-FILTER chain
2022-09-15 02:45:22 -07:00
Lars Ekman
639b9bca5d Corrects target in the KUBE-IPVS-FILTER chain
The target was "ACCEPT" which disabled any other check like
loadBalancerSourceRanges in the KUBE-PROXY-FIREWALL chain.
The target is now "RETURN".
2022-09-15 07:49:12 +02:00
Antonio Ojea
b84a5faaae kube-proxy use debug log level for cache operations
Level 4 is mean for debug operations.
The default level use to be level 2, on clusters with a lot of
Services this means that the kube-proxy will generate a lot of
noise on the logs, with the performance penalty associated to
it.
2022-09-14 17:57:08 +02:00
JunYang
fc6b421d97 cleanup useless check about CIDR 2022-09-14 11:43:35 +08:00
kerthcet
2b7373f336 kube-proxy: code optimization
Signed-off-by: kerthcet <kerthcet@gmail.com>
2022-09-04 19:34:22 +08:00
Kubernetes Prow Robot
9924814270
Merge pull request #108460 from Nordix/issue-72236
Prevent host access on VIP addresses in proxy-mode=ipvs
2022-09-01 12:59:18 -07:00
Sanskar Jaiswal
8b5f263cd3 add tests for initialSync usage in syncEndpoint
Signed-off-by: Sanskar Jaiswal <jaiswalsanskar078@gmail.com>
2022-08-27 07:42:21 +00:00
Sanskar Jaiswal
b670656a09 update ipvs proxier to update realserver weights at startup
Update the IPVS proxier to have a bool `initialSync` which is set to
true when a new proxier is initialized and then set to false on all
syncs. This lets us run startup-only logic, which subsequently lets us
update the realserver only when needed and avoiding any expensive
operations.

Signed-off-by: Sanskar Jaiswal <jaiswalsanskar078@gmail.com>
2022-08-27 07:42:07 +00:00
Dan Winship
c437b15441 proxy/iptables: make part of the unit test sanity-checking optional 2022-08-24 09:02:48 -04:00
Kubernetes Prow Robot
da112dda68
Merge pull request #111806 from danwinship/kube-proxy-no-mode-fallback
remove kube-proxy mode fallback
2022-08-24 05:52:03 -07:00
Kubernetes Prow Robot
ef25013252
Merge pull request #111842 from ialidzhikov/cleanup/pkg-proxy
pkg/proxy: Replace deprecated func usage from the `k8s.io/utils/pointer` pkg
2022-08-23 20:08:08 -07:00
Kubernetes Prow Robot
9efbe6eb9b
Merge pull request #111379 from muyangren2/describe_err
wrong description
2022-08-23 16:05:17 -07:00
Dan Winship
1609017f2b kube-proxy: remove ipvs-to-iptables fallback
If the user passes "--proxy-mode ipvs", and it is not possible to use
IPVS, then error out rather than falling back to iptables.

There was never any good reason to be doing fallback; this was
presumably erroneously added to parallel the iptables-to-userspace
fallback (which only existed because we had wanted iptables to be the
default but not all systems could support it).

In particular, if the user passed configuration options for ipvs, then
they presumably *didn't* pass configuration options for iptables, and
so even if the iptables proxy is able to run, it is likely to be
misconfigured.
2022-08-16 09:30:08 -04:00
Dan Winship
9f69a3a9d4 kube-proxy: remove iptables-to-userspace fallback
Back when iptables was first made the default, there were
theoretically some users who wouldn't have been able to support it due
to having an old /sbin/iptables. But kube-proxy no longer does the
things that didn't work with old iptables, and we removed that check a
long time ago. There is also a check for a new-enough kernel version,
but it's checking for a feature which was added in kernel 3.6, and no
one could possibly be running Kubernetes with a kernel that old. So
the fallback code now never actually falls back, so it should just be
removed.
2022-08-16 09:21:34 -04:00
ialidzhikov
f2bc2ed2da pkg/proxy: Replace deprecated func usage from the k8s.io/utils/pointer pkg 2022-08-14 18:27:33 +03:00
Kubernetes Prow Robot
e16ac34361
Merge pull request #110289 from danwinship/kep-3178-source-ranges-drop
Don't use KUBE-MARK-DROP for LoadBalancerSourceRanges
2022-07-28 10:21:10 -07:00
Dan Winship
f65fbc877b proxy/iptables: remove last references to KUBE-MARK-DROP 2022-07-28 09:03:49 -04:00
Dan Winship
9313188909 proxy/iptables: Don't use KUBE-MARK-DROP for LoadBalancerSourceRanges 2022-07-28 09:03:46 -04:00
Kubernetes Prow Robot
4e5711829c
Merge pull request #111228 from Abirdcfly/220716
clean unreachable code
2022-07-27 11:35:00 -07:00
Kubernetes Prow Robot
ce433f87b4
Merge pull request #110266 from danwinship/minimize-prep-reorg
iptables proxy reorg in preparation for minimizing iptables-restore
2022-07-27 04:06:30 -07:00
Davanum Srinivas
a9593d634c
Generate and format files
- Run hack/update-codegen.sh
- Run hack/update-generated-device-plugin.sh
- Run hack/update-generated-protobuf.sh
- Run hack/update-generated-runtime.sh
- Run hack/update-generated-swagger-docs.sh
- Run hack/update-openapi-spec.sh
- Run hack/update-gofmt.sh

Signed-off-by: Davanum Srinivas <davanum@gmail.com>
2022-07-26 13:14:05 -04:00
muyangren2
9b29c930a2 wrong description 2022-07-25 13:41:59 +08:00
Kubernetes Prow Robot
7d72ccf9a8
Merge pull request #110957 from papagalu/kp_remove_hnsv1
kube-proxy: windows: Removed hnsV1
2022-07-20 04:02:38 -07:00
BinacsLee
f1c9a70b47 cleanup: simplify the function implementation of IPSet 2022-07-20 10:13:57 +08:00
Abirdcfly
f71718d644 clean Unreachable code
Signed-off-by: Abirdcfly <fp544037857@gmail.com>
2022-07-19 20:42:09 +08:00
Kubernetes Prow Robot
a521af7007
Merge pull request #111219 from dcbw/proxy-sync-on-node-events
proxy: queue syncs on node events rather than syncing immediately
2022-07-19 05:34:18 -07:00
Kubernetes Prow Robot
8af2c50201
Merge pull request #110762 from pandaamanda/windows_default_proxy
kube-proxy: kernelspace mode is announced to be default for windows
2022-07-18 11:45:15 -07:00
Dan Williams
f197509879 proxy: queue syncs on node events rather than syncing immediately
The proxies watch node labels for topology changes, but node labels
can change in bursts especially in larger clusters. This causes
pressure on all proxies because they can't filter the events, since
the topology could match on any label.

Change node event handling to queue the request rather than immediately
syncing. The sync runner can already handle short bursts which shouldn't
change behavior for most cases.

Signed-off-by: Dan Williams <dcbw@redhat.com>
2022-07-18 09:21:52 -05:00
pandaamanda
fbe934da21 kube-proxy: kernelspace mode is announced to be default for windows 2022-07-18 01:04:56 +00:00
Dan Winship
367f18c49b proxy/iptables: move firewall chain setup
Part of reorganizing the syncProxyRules loop to do:
  1. figure out what chains are needed, mark them in activeNATChains
  2. write servicePort jump rules to KUBE-SERVICES/KUBE-NODEPORTS
  3. write servicePort-specific chains (SVC, SVL, EXT, FW, SEP)

This moves the FW chain creation to the end (rather than having it in
the middle of adding the jump rules for the LB IPs).
2022-07-09 07:08:42 -04:00
Dan Winship
2030591ce7 proxy/iptables: move internal traffic setup code
Part of reorganizing the syncProxyRules loop to do:
  1. figure out what chains are needed, mark them in activeNATChains
  2. write servicePort jump rules to KUBE-SERVICES/KUBE-NODEPORTS
  3. write servicePort-specific chains (SVC, SVL, EXT, FW, SEP)

This fixes the jump rules for internal traffic. Previously we were
handling "jumping from kubeServices to internalTrafficChain" and
"adding masquerade rules to internalTrafficChain" in the same place.
2022-07-09 07:07:48 -04:00
Dan Winship
00f789cd8d proxy/iptables: move EXT chain rule creation to the end
Part of reorganizing the syncProxyRules loop to do:
  1. figure out what chains are needed, mark them in activeNATChains
  2. write servicePort jump rules to KUBE-SERVICES/KUBE-NODEPORTS
  3. write servicePort-specific chains (SVC, SVL, EXT, FW, SEP)

This fixes the handling of the EXT chain.
2022-07-09 07:07:47 -04:00
Dan Winship
8906ab390e proxy/iptables: reorganize cluster/local chain creation
Part of reorganizing the syncProxyRules loop to do:
  1. figure out what chains are needed, mark them in activeNATChains
  2. write servicePort jump rules to KUBE-SERVICES/KUBE-NODEPORTS
  3. write servicePort-specific chains (SVC, SVL, EXT, FW, SEP)

This fixes the handling of the SVC and SVL chains. We were already
filling them in at the end of the loop; this fixes it to create them
at the bottom of the loop as well.
2022-07-09 07:05:05 -04:00
Dan Winship
da14a12fe5 proxy/iptables: move endpoint chain rule creation to the end
Part of reorganizing the syncProxyRules loop to do:
  1. figure out what chains are needed, mark them in activeNATChains
  2. write servicePort jump rules to KUBE-SERVICES/KUBE-NODEPORTS
  3. write servicePort-specific chains (SVC, SVL, EXT, FW, SEP)

This fixes the handling of the endpoint chains. Previously they were
handled entirely at the top of the loop. Now we record which ones are
in use at the top but don't create them and fill them in until the
bottom.
2022-07-09 06:51:47 -04:00
Dan Winship
8a5801996b proxy/iptables: belatedly simplify local traffic policy metrics
We figure out early on whether we're going to end up outputting no
endpoints, so update the metrics then.

(Also remove a redundant feature gate check; svcInfo already checks
the ServiceInternalTrafficPolicy feature gate itself and so
svcInfo.InternalPolicyLocal() will always return false if the gate is
not enabled.)
2022-07-09 06:50:16 -04:00
Dimitrie Mititelu
09ca06e875 kube-proxy: windows: Removed hnsV1
hnsV1 not supported anymore

Signed-off-by: Dimitrie Mititelu <dmititelu@cloudbasesolutions.com>
2022-07-05 22:24:23 +03:00
Dan Winship
95705350d5 proxy/iptables: Don't use KUBE-MARK-DROP for "no local endpoints"
Rather than marking packets to be dropped in the "nat" table and then
dropping them from the "filter" table later, just use rules in
"filter" to drop the packets we don't like directly.
2022-06-29 16:37:24 -04:00
Dan Winship
283218bd4c proxy/iptables: update TestTracePackets
Re-sync the rules from TestOverallIPTablesRulesWithMultipleServices to
make sure we're testing all the right kinds of rules. Remove a
duplicate copy of the KUBE-MARK-MASQ and KUBE-POSTROUTING rules.

Update the "REJECT" test to use the new svc6 from
TestOverallIPTablesRulesWithMultipleServices. (Previously it had used
a modified version of TOIPTRWMS's svc3.)
2022-06-29 16:33:13 -04:00
Dan Winship
59b7f969e8 proxy/iptables: fix up TestOverallIPTablesRulesWithMultipleServices
svc2b was using the same ClusterIP as svc3; change it and rename the
service to svc5 to make everything clearer.

Move the test of LoadBalancerSourceRanges from svc2 to svc5, so that
svc2 tests the rules for dropping packets due to
externalTrafficPolicy, and svc5 tests the rules for dropping packets
due to LoadBalancerSourceRanges, rather than having them both mixed
together in svc2.

Add svc6 with no endpoints.
2022-06-29 16:33:13 -04:00
Kubernetes Prow Robot
f045fb688f
Merge pull request #110334 from danwinship/iptables-fewer-saves
only clean up iptables chains periodically in large clusters
2022-06-29 09:48:06 -07:00
Dan Winship
7d3ba837f5 proxy/iptables: only clean up chains periodically in large clusters
"iptables-save" takes several seconds to run on machines with lots of
iptables rules, and we only use its result to figure out which chains
are no longer referenced by any rules. While it makes things less
confusing if we delete unused chains immediately, it's not actually
_necessary_ since they never get called during packet processing. So
in large clusters, make it so we only clean up chains periodically
rather than on every sync.
2022-06-29 11:14:38 -04:00
Dan Winship
1cd461bd24 proxy/iptables: abstract the "endpointChainsNumberThreshold" a bit
Turn this into a generic "large cluster mode" that determines whether
we optimize for performance or debuggability.
2022-06-29 11:14:38 -04:00
Dan Winship
c12da17838 proxy/iptables: Add a unit test with multiple resyncs 2022-06-29 11:14:38 -04:00
Kubernetes Prow Robot
0d9ed2c3e7
Merge pull request #110328 from danwinship/iptables-counters
Stop trying to "preserve" iptables counters that are always 0
2022-06-29 08:06:06 -07:00
Dan Winship
7c27cf0b9b Simplify iptables-save parsing
We don't need to parse out the counter values from the iptables-save
output (since they are always 0 for the chains we care about). Just
parse the chain names themselves.

Also, all of the callers of GetChainLines() pass it input that
contains only a single table, so just assume that, rather than
carefully parsing only a single table's worth of the input.
2022-06-28 08:39:32 -04:00
Dan Winship
a3556edba1 Stop trying to "preserve" iptables counters that are always 0
The iptables and ipvs proxies have code to try to preserve certain
iptables counters when modifying chains via iptables-restore, but the
counters in question only actually exist for the built-in chains (eg
INPUT, FORWARD, PREROUTING, etc), which we never modify via
iptables-restore (and in fact, *can't* safely modify via
iptables-restore), so we are really just doing a lot of unnecessary
work to copy the constant string "[0:0]" over from iptables-save
output to iptables-restore input. So stop doing that.

Also fix a confused error message when iptables-save fails.
2022-06-28 08:39:32 -04:00
Kubernetes Prow Robot
832c4d8cb7
Merge pull request #110503 from aojea/iptables_rules
kube-proxy iptables test number of generated iptables rules
2022-06-27 18:10:08 -07:00
Lars Ekman
c1e5a9e6f0 Prevent host access on VIP addresses in proxy-mode=ipvs 2022-06-24 08:33:58 +02:00
lokichoggio
52280de403
fix comments in pkg/proxy/types.go 2022-06-24 09:50:02 +08:00
Dan Winship
28253f6030 proxy/ipvs: Use DROP directly rather than KUBE-MARK-DROP
The ipvs proxier was figuring out LoadBalancerSourceRanges matches in
the nat table and using KUBE-MARK-DROP to mark unmatched packets to be
dropped later. But with ipvs, unlike with iptables, DNAT happens after
the packet is "delivered" to the dummy interface, so the packet will
still be unmodified when it reaches the filter table (the first time)
so there's no reason to split the work between the nat and filter
tables; we can just do it all from the filter table and call DROP
directly.

Before:

  - KUBE-LOAD-BALANCER (in nat) uses kubeLoadBalancerFWSet to match LB
    traffic for services using LoadBalancerSourceRanges, and sends it
    to KUBE-FIREWALL.

  - KUBE-FIREWALL uses kubeLoadBalancerSourceCIDRSet and
    kubeLoadBalancerSourceIPSet to match allowed source/dest combos
    and calls "-j RETURN".

  - All remaining traffic that doesn't escape KUBE-FIREWALL is sent to
    KUBE-MARK-DROP.

  - Traffic sent to KUBE-MARK-DROP later gets dropped by chains in
    filter created by kubelet.

After:

  - All INPUT and FORWARD traffic gets routed to KUBE-PROXY-FIREWALL
    (in filter). (We don't use "KUBE-FIREWALL" any more because
    there's already a chain in filter by that name that belongs to
    kubelet.)

  - KUBE-PROXY-FIREWALL sends traffic matching kubeLoadbalancerFWSet
    to KUBE-SOURCE-RANGES-FIREWALL

  - KUBE-SOURCE-RANGES-FIREWALL uses kubeLoadBalancerSourceCIDRSet and
    kubeLoadBalancerSourceIPSet to match allowed source/dest combos
    and calls "-j RETURN".

  - All remaining traffic that doesn't escape
    KUBE-SOURCE-RANGES-FIREWALL is dropped (directly via "-j DROP").

  - (KUBE-LOAD-BALANCER in nat is now used only to set up masquerading)
2022-06-22 13:02:22 -04:00
Dan Winship
a9cd57fa40 proxy/ipvs: add filter table support to ipsetWithIptablesChain 2022-06-22 12:53:18 -04:00
Antonio Ojea
3cb63833ff kube-proxy iptables test number of generated iptables rules
kube-proxy generates iptables rules to forward traffic from Services to Endpoints
kube-proxy uses iptables-restore to configure the rules atomically, however,
this has the downside that large number of rules take a long time to be processed,
causing disruption.
There are different parameters than influence the number of rules generated:
- ServiceType
- Number of Services
- Number of Endpoints per Service
This test will fail when the number of rules change, so the person
that is modifying the code can have feedback about the performance impact
on their changes. It also runs multiple number of rules test cases to check
if the number of rules grows linearly.
2022-06-14 11:55:42 +02:00
Dan Winship
400d474bac proxy/ipvs: fix some identifiers
kubeLoadbalancerFWSet was the only LoadBalancer-related identifier
with a lowercase "b", so fix that.

rename TestLoadBalanceSourceRanges to TestLoadBalancerSourceRanges to
match the field name (and the iptables proxier test).
2022-06-13 09:13:15 -04:00
Dan Winship
0b1e364814 proxy/ipvs: fix a few comments 2022-06-12 20:30:47 -04:00
Kubernetes Prow Robot
dc4e91a875
Merge pull request #109844 from danwinship/iptables-tests-new
improve parsing in iptables unit tests
2022-06-10 14:27:44 -07:00
Kubernetes Prow Robot
cb92b2c119
Merge pull request #110203 from wppzxc/add-testcases
Fix: Add test cases for method IsZeroCIDR() in  pkg/proxy/util/utils_test.go
2022-05-27 00:41:08 -07:00
Kubernetes Prow Robot
4a2391caf3
Merge pull request #108259 from carlosdamazio/refactor/roundrobin
pkg/proxy/userspace/roundrobin: Make `lb.services` nil check standardized
2022-05-26 08:45:23 -07:00
wupengpeng
872be44775 Fix: Add test cases for method IsZeroCIDR() in pkg/proxy/util/utils_test.go 2022-05-25 10:47:33 +08:00
gkarthiks
1fd959e256 refactor: serviceNameString to svcptNameString
Signed-off-by: gkarthiks <github.gkarthiks@gmail.com>

refactor: svc port name variable #108806

Signed-off-by: gkarthiks <github.gkarthiks@gmail.com>

refactor: rename struct for service port information to servicePortInfo and fields for more redability

Signed-off-by: gkarthiks <github.gkarthiks@gmail.com>

fix: drop chain rule

Signed-off-by: gkarthiks <github.gkarthiks@gmail.com>
2022-05-22 03:31:00 -07:00
Dan Winship
24e1e3d9ee proxy/iptables: port packet-flow tests to use new parsing stuff 2022-05-09 11:29:08 -04:00
Dan Winship
913f4bc0ba pkg/util/iptables/testing: Fix FakeIPTables
FakeIPTables barely implemented any of the iptables interface, and the
main part that it did implement, it implemented incorrectly. Fix it:

- Implement EnsureChain, DeleteChain, EnsureRule, and DeleteRule, not
  just SaveInto/Restore/RestoreAll.

- Restore/RestoreAll now correctly merge the provided state with the
  existing state, rather than simply overwriting it.

- SaveInto now returns the table that was requested, rather than just
  echoing back the Restore/RestoreAll.
2022-05-09 11:29:08 -04:00
Dan Winship
10a72a9e03 pkg/util/iptables/testing: Add IPTables dump-parsing helpers 2022-05-09 11:29:06 -04:00
Dan Winship
f0f47ae590 proxy/iptables: tweak sortIPTablesRules some more
Sort the ":CHAINNAME" lines in the same order as the "-A CHAINNAME"
lines (meaning, KUBE-NODEPORTS and KUBE-SERVICES come first).

(This will simplify IPTablesDump because it won't need to keep track
of the declaration order and the rule order separately.)
2022-05-09 11:19:28 -04:00
Dan Winship
f2fa1033d0 pkg/util/iptables/testing: Add better IPTables rule-parsing helpers
There were previously some strange iptables-rule-parsing functions
that were only used by two unit tests in pkg/proxy/ipvs. Get rid of
them and replace them with some much better iptables-rule-parsing
functions.
2022-05-09 11:19:26 -04:00
Dan Winship
b0d9c063a8 unexport mistakenly-exported constants 2022-05-06 07:33:29 -04:00
Kubernetes Prow Robot
2b3508e0f1
Merge pull request #109826 from danwinship/multi-load-balancer
fix kube-proxy bug with multiple LB IPs and source ranges
2022-05-06 03:09:15 -07:00
Dan Winship
813aca47af proxy/iptables: fix firewall rules with multiple LB IPs
The various loops in the LoadBalancer rule section were mis-nested
such that if a service had multiple LoadBalancer IPs, we would write
out the firewall rules multiple times (and the allowFromNode rule for
the second and later IPs would end up being written after the "else
DROP" rule from the first IP).
2022-05-05 10:58:09 -04:00
Dan Winship
df589b46a1 proxy/iptables: test multiple LoadBalancer IPs on one service 2022-05-05 10:58:09 -04:00
Dan Winship
709b4f696d proxy/iptables: test LoadBalancerSourceRanges vs node IP
The LoadBalancer rules change if the node IP is in one of the
LoadBalancerSourceRange subnets, so make sure to set nodeIP on the
fake proxier so we can test this, and add a second source range to
TestLoadBalancer containing the node IP. (This changes the result of
one flow test that previously expected that node-to-LB would be
dropped.)
2022-05-05 10:58:07 -04:00
Kubernetes Prow Robot
8f7e80cd89
Merge pull request #109483 from cyclinder/fix_healthz
kube-proxy: fix healthz return unexpect code 200
2022-05-05 06:40:19 -07:00
Kubernetes Prow Robot
50e1f70027
Merge pull request #109782 from danwinship/no-local-endpoints-metric
Don't increment "no local endpoints" metric when there are no remote endpoints
2022-05-05 05:02:20 -07:00
Kubernetes Prow Robot
794d3ab686
Merge pull request #109740 from AllenZMC/fix_test_iptables
Optimize test cases for iptables
2022-05-05 01:42:51 -07:00
Kubernetes Prow Robot
b5d494cdee
Merge pull request #109738 from AllenZMC/fix
Optimize test cases for ipvs
2022-05-05 01:42:43 -07:00
Kubernetes Prow Robot
889e60ab33
Merge pull request #109124 from daschott/daschott/winkernel-perf-fix
winkernel proxier cache HNS data to improve syncProxyRules performance
2022-05-04 11:47:14 -07:00
Dan Winship
84ad54f0e5 Don't increment "no local endpoints" metric when there are no remote endpoints
A service having no _local_ endpoints when it does have remote
endpoints is different from a service having no endpoints at all.
2022-05-04 12:38:17 -04:00
cyclinder
3fa4705aea kube-proxy: fix healthz return unexpect code 200 2022-05-04 14:05:24 +08:00
Kubernetes Prow Robot
75398940b6
Merge pull request #109288 from ScheererJ/ScheererJ-kube-proxy-kube-node-port-cleanup
[kube-proxy]: Cleanup KUBE-NODE-PORT chain in filter table.
2022-05-03 19:30:48 -07:00
AllenZMC
a5fb9bbd35 Optimize test cases for iptables 2022-05-01 19:33:06 +08:00
AllenZMC
0c23f5093f Optimize test cases for ipvs 2022-05-01 19:29:33 +08:00
daschott
b7466d02cd Winkernel proxier cache HNS data to improve syncProxyRules performance
Resolved issues with proxy rules taking a long time to be synced on Windows, by caching HNS data.

In particular, the following HNS data will be cached for the context of syncProxyRules:
  * HNS endpoints

  * HNS load balancers
2022-04-15 13:31:31 -07:00
Dan Winship
0ecf11a23b proxy/iptables: add a general test of internal vs external traffic
Add TestInternalExternalMasquerade, which tests whether various
packets are considered internal or external for purposes of traffic
policy, and whether they get masqueraded, with and without
--masquerade-all, with and without a working LocalTrafficDetector.
(This extends and replaces the old TestMasqueradeAll.)
2022-04-11 13:23:08 -04:00
Dan Winship
f4261283ac proxy/iptables: add packet-flow-based tests of iptables rules
Add a new framework for testing out how particular packets would be
handled by a given set of iptables rules. (eg, "assert that a packet
from 10.180.0.2 to 172.30.0.41:80 gets NATted to 10.180.0.1:80 without
being masqueraded"). Add tests using this to all of the existing unit
tests.

This makes it easier to tell whether a given code change has any
effect on behavior, without having to carefully examine the diffs to
the generated iptables rules.
2022-04-11 13:23:08 -04:00
Dan Winship
cd55f35306 proxy/iptables: tweak sortIPTablesRules a bit
It's confusing to have the "this must be the last rule" get sorted to
be the first rule in KUBE-SERVICES...
2022-04-07 08:38:14 -04:00
Dan Winship
d9ca665551 proxy/iptables: fix up some test case comments 2022-04-07 08:38:14 -04:00
Dan Winship
261f4f9e2d proxy/iptables: remove redundant test
We originally had one HealthCheckNodePort test that used
assertIPTablesRulesEqual() and one that didn't, but later I went
through and made all the tests use assertIPTablesRulesEqual() and
didn't notice that this resulted in there now being two
nearly-identical HealthCheckNodePort tests.
2022-04-07 08:36:34 -04:00
Johannes Scheerer
a3b7f219a1
Cleanup KUBE-NODE-PORT chain in filter table.
When cleaning up iptables rules and ipsets used by kube-proxy in IPVS mode
iptables chain KUBE-NODE-PORT needs to be deleted before ipset
KUBE-HEALTH-CHECK-NODE-PORT can be removed. Therefore, deletion of
iptables chain KUBE-NODE-PORT is added in this change.
2022-04-04 16:10:06 +02:00
Max Renaud
6454248b6b Moved counting logic to accommodate rebase 2022-04-01 15:52:21 +00:00
Max Renaud
61b7e6c49c Changed usage of NodeLocal* to *PolicyLocal 2022-03-31 18:55:47 +00:00
Max Renaud
198367a486 Added test where both policies are set 2022-03-31 18:54:28 +00:00
Max Renaud
ba4f5c4e7b use sets.String for tracking IPVS no local endpoint metric 2022-03-31 18:54:27 +00:00
Max Renaud
f0dfac5d07 Add sync_proxy_rules_no_local_endpoints_total metric 2022-03-31 18:54:23 +00:00
Kubernetes Prow Robot
f2e5c16545
Merge pull request #109060 from thockin/kube-proxy-rule-cleanups-after-106497
Kube proxy rule reorg XLB->EXT
2022-03-31 00:11:01 -07:00
Kubernetes Prow Robot
5223c1efef
Merge pull request #97081 from Nordix/issue-93456
Ipvs: non-local access to externalTrafficPolicy:Local
2022-03-30 13:37:56 -07:00
Tim Hockin
40e21e310f Elide the -FW- chain when possible
This makes it epsilon harder to reason about but saves one chain
declaration and one rule per service-port usually.
2022-03-30 09:55:34 -07:00
Tim Hockin
7726b5f9fc kube-proxy: inline args in most cases 2022-03-30 09:55:34 -07:00
Tim Hockin
c4271c9a6f Rename tests to avoid underscores 2022-03-30 09:55:34 -07:00
Tim Hockin
9ed6b73495 kube-proxy: comment endpoint in SEP jumps 2022-03-30 09:55:34 -07:00
Tim Hockin
0e47dc3a65 kube-proxy: remove old TODO 2022-03-30 09:55:33 -07:00
Tim Hockin
30c1523708 kube-proxy: Renames for readability 2022-03-30 09:55:32 -07:00
Tim Hockin
f1553f58c5 kube-proxy: Remove now unneeded rule
Now that NodePorts jump to EXT, we don't need a specific rule for
loopback source detection.
2022-03-30 09:54:40 -07:00
Tim Hockin
db932a0ab1 kube-proxy: Rework LB VIP capture logic
* Comments
* If there are multiple VIPs, don't declare the fwChain multiple times.
* Don't emit the last -j DROP if there's no source ranges
2022-03-30 09:54:40 -07:00
Tim Hockin
07b2585927 kube-proxy: Rename XLB -> EXT
This changes the "XLB" chain into the "EXT" chain - the "external
destinations" chain.
2022-03-30 09:54:38 -07:00
Tim Hockin
482f3bc4bf kube-proxy: all external jumps to XLB chain
This makes the "destination" policy model clearer.  All external
destination captures now jump to the "XLB chain, which is the main place
that masquerade is done (removing it from most other places).

This is simpler to trace - XLB *always* exists (as long as you have an
external exposure) and never gets bypassed.
2022-03-30 09:52:18 -07:00
Tim Hockin
dd0fc6b354 kube-proxy: print line number for test failures 2022-03-29 18:48:27 -07:00
Tim Hockin
ef959f00af kube-proxy: clean up tests
No functional changes, much whitespace.

Make assertIPTablesRulesEqual() *not* sort the `expected` value - make
the test cases all be pre-sorted.  This will make followup commits
cleaner.

Make the test output cleaner when this fails.

Use dedent everywhere for easier reading.
2022-03-29 18:48:27 -07:00
Tim Hockin
99330d407a kube-proxy: internal renames 2022-03-29 18:48:27 -07:00
Lars Ekman
61085a7589 Ipvs: non-local access to externalTrafficPolicy:Local
Allow access to externalTrafficPolicy:Local services from PODs
not on a node where a server executes. Problem described in #93456
2022-03-29 21:42:39 +02:00
Andrew Sy Kim
53439020a4 pkg/proxy/ipvs: add unit tests Test_EndpointSliceOnlyReadyAndTerminatingCluster and Test_EndpointSliceReadyAndTerminatingCluster for validating ProxyTerminatingEndpoints when the traffic policy is 'Cluster'
Signed-off-by: Andrew Sy Kim <andrewsy@google.com>
2022-03-29 11:37:15 -04:00
Andrew Sy Kim
718a655e42 pkg/proxy/iptables: add and fix existing unit tests based on changes to ProxyTermintingEndpoints
Signed-off-by: Andrew Sy Kim <andrewsy@google.com>
2022-03-29 11:37:15 -04:00
Andrew Sy Kim
e2e0b6fca8 pkg/proxy: update CategorizeEndpoints to apply ProxyTerminatingEndpoints to all traffic policies
Signed-off-by: Andrew Sy Kim <andrewsy@google.com>
2022-03-29 11:06:58 -04:00
Kubernetes Prow Robot
9f213370cc
Merge pull request #106497 from danwinship/traffic-policy-fixes
fix internalTrafficPolicy
2022-03-28 14:19:54 -07:00
Dan Winship
b9141e5c0d proxy/iptables: rename chain variables 2022-03-26 11:14:18 -04:00
Dan Winship
548cf9d5de proxy/iptables: fix internal-vs-external traffic policy handling
Fix internal and external traffic policy to be handled separately (so
that, in particular, services with Local internal traffic policy and
Cluster external traffic policy do not behave as though they had Local
external traffic policy as well.

Additionally, traffic to an `internalTrafficPolicy: Local` service on
a node with no endpoints is now dropped rather than being rejected
(which, as in the external case, may prevent traffic from being lost
when endpoints are in flux).
2022-03-26 11:06:34 -04:00
Dan Winship
2e780ecd99 proxy/iptables: Split KUBE-SVL-XXX chain out of KUBE-XLB-XXX
Now the XLB chain _only_ implements the "short-circuit local
connections to the SVC chain" rule, and the actual endpoint selection
happens in the SVL chain.

Though not quite implemented yet, this will eventually also mean that
"SVC" = "Service, Cluster traffic policy" as opposed to "SVL" =
"Service, Local traffic policy"
2022-03-26 11:06:34 -04:00
Dan Winship
87dcf8b914 proxy/iptables: move XLB chain initial rule setup 2022-03-26 11:06:34 -04:00
Dan Winship
2b872a990d proxy/iptables: clean up / clarify iptables chain names a bit 2022-03-26 11:06:34 -04:00
Surya Seetharaman
1ea5f9432c Add validation for bridge-interface and interface-name-prefix
Co-authored-by: Will Daly <widaly@microsoft.com>
Signed-off-by: Surya Seetharaman <suryaseetharaman.9@gmail.com>
2022-03-25 20:06:12 +01:00
Surya Seetharaman
7d480d8ac8 Enable local traffic detection using the interface options
This commit adds the framework for the new local detection
modes BridgeInterface and InterfaceNamePrefix to work.

Signed-off-by: Surya Seetharaman <suryaseetharaman.9@gmail.com>
2022-03-25 20:06:12 +01:00
Surya Seetharaman
5632991115 Local Traffic Detector: Add two new modes
This PR introduces two new modes for detecting
local traffic in a cluster.
1) detectLocalByBridgeInterface: This takes a bridge name
as argument and decides all traffic that match on their
originating interface being that of this bridge, shall be
considered as local pod traffic.
2) detectLocalByInterfaceNamePrefix: This takes an interface prefix
name as argument and decides all traffic that match on their
originating interface names having a prefix that matches this
argument shall be considered as local pod traffic.

Signed-off-by: Surya Seetharaman <suryaseetharaman.9@gmail.com>
2022-03-25 20:06:06 +01:00
Kubernetes Prow Robot
475f7af1c1
Merge pull request #108812 from danwinship/endpoint-chain-names
proxy/iptables: fix up endpoint chain name computation
2022-03-19 02:15:09 -07:00
Kubernetes Prow Robot
2bda940add
Merge pull request #108811 from danwinship/simplify-local-traffic-detector
pkg/proxy: Simplify LocalTrafficDetector
2022-03-18 20:59:12 -07:00
Dan Winship
dd4d88398c proxy/iptables: fix up endpoint chain name computation
Rather than lazily computing and then caching the endpoint chain name
because we don't have the right information at construct time, just
pass the right information at construct time and compute the chain
name then.
2022-03-18 16:10:33 -04:00
Dan Winship
e3549646ec pkg/proxy: Simplify LocalTrafficDetector
Now that we don't have to always append all of the iptables args into
a single array, there's no reason to have LocalTrafficDetector take in
a set of args to prepend to its own output, and also not much point in
having it write out the "-j CHAIN" by itself either.
2022-03-18 16:09:04 -04:00
Carlos Damázio
fd00b042bf
fix: formatting 2022-03-17 21:27:14 -03:00
Kubernetes Prow Robot
41b29e6542
Merge pull request #99287 from anfernee/clientip
Add HNS Load Balancer Healthchecks for ExternalTrafficPolicy: Local
2022-03-16 22:57:18 -07:00
Yongkun Gui
78a507b256 Fix health check from Google's Load Balancer
This change adds 2 options for windows:
--forward-healthcheck-vip: If true forward service VIP for health check
port
--root-hnsendpoint-name: The name of the hns endpoint name for root
namespace attached to l2bridge, default is cbr0

When --forward-healthcheck-vip is set as true and winkernel is used,
kube-proxy will add an hns load balancer to forward health check request
that was sent to lb_vip:healthcheck_port to the node_ip:healthcheck_port.
Without this forwarding, the health check from google load balancer will
fail, and it will stop forwarding traffic to the windows node.

This change fixes the following 2 cases for service:
- `externalTrafficPolicy: Cluster` (default option): healthcheck_port is
10256 for all services. Without this fix, all traffic won't be directly
forwarded to windows node. It will always go through a linux node and
get forwarded to windows from there.
- `externalTrafficPolicy: Local`: different healthcheck_port for each
service that is configured as local. Without this fix, this feature
won't work on windows node at all. This feature preserves client ip
that tries to connect to their application running in windows pod.

Change-Id: If4513e72900101ef70d86b91155e56a1f8c79719
2022-03-11 22:34:59 -08:00
Khaled (Kal) Henidak
c4a00b7d90 ipvs: remove port opener 2022-03-04 21:10:55 +00:00
Khaled (Kal) Henidak
407dcf5164 iptables: remove port opener 2022-03-03 20:04:08 +00:00
Kubernetes Prow Robot
8f3636e8ac
Merge pull request #108224 from danwinship/kube-proxy-logging
Only log full iptables-restore input at V(9)
2022-02-22 16:42:18 -08:00
Kubernetes Prow Robot
108e8136e2
Merge pull request #107393 from danwinship/filter-endpoints
kube-proxy endpoint filtering unit test refactoring
2022-02-22 08:55:15 -08:00
Dan Winship
9483c272f4 Log metadata about kube-proxy iptables-restore calls
For each iptables-restore call, log the number of services, endpoints,
filter chains, filter rules, NAT chains, and NAT rules in the update
at V(2), in addition to logging the actual rules if V(9).
2022-02-22 08:29:25 -05:00
Carlos Damázio
fd6a05396b refactor: adding state check after lb.service call 2022-02-21 15:07:20 -03:00
Dan Winship
d830ef6112 proxy/iptables: add HealthCheckNodePorts to unit tests that need them
To avoid spurious errors in the test output:

  E0114 08:43:27.453974 3718376 service.go:221] "Service has no healthcheck nodeport" service="ns1/svc1"
2022-02-21 09:16:23 -05:00
Dan Winship
d74df127e9 proxy/iptables: Fix up IPs and ports in unit tests
All of the tests used a localDetector that considered the pod IP range
to be 10.0.0.0/24, but lots of the tests used pod IPs in 10.180.0.0/16
or 10.0.1.0/24, meaning the generated iptables rules were somewhat
inconsistent. Fix this by expanding the localDetector's pod IP range
to 10.0.0.0/8. (Changing the pod IPs to all be in 10.0.0.0/24 instead
would be a much larger change since it would result in the SEP chain
names changing.)

Meanwhile, the different tests were also horribly inconsistent about
what values they used for other IPs, and some of them even used the
same IPs (or ports) for different things in the same test case. Fix
these all up and create a consistent set of IP assignments:

// Pod IPs:             10.0.0.0/8
// Service ClusterIPs:  172.30.0.0/16
// Node IPs:            192.168.0.0/24
// Local Node IP:       192.168.0.2
// Service ExternalIPs: 192.168.99.0/24
// LoadBalancer IPs:    1.2.3.4, 5.6.7.8, 9.10.11.12
// Non-cluster IPs:     203.0.113.0/24
// LB Source Range:     203.0.113.0/25
2022-02-21 09:16:22 -05:00
Dan Winship
37ada4b04f proxy/iptables: Don't create unused chains, and enable the unit test for that 2022-02-21 09:16:22 -05:00
Dan Winship
ef4324eaf5 proxy/iptables: refactor unit test code / fix error reporting
Only run assertIPTablesRuleJumps() on the expected output, not on the
actual output, since if there's a problem with the actual output, we'd
rather see it as the diff from the expected output.
2022-02-21 09:16:22 -05:00
Dan Winship
4af471f8be proxy/iptables: move GetChainLines unit tests to the right package
GetChainLines is a utiliptables method, so it should be part of the
unit tests there.
2022-02-21 09:16:22 -05:00
Dan Winship
f5ad58b57b Only log full iptables-restore input at V(9)
In large clusters, the iptables-restore input will be tens of
thousands of lines long, and logging it at V(5) essentially means that
"kube-proxy -v=5" cannot be used in such clusters to see _other_
things that get logged at V(5), because logs will get rolled over far
too quickly. So bump the full-rules logging output down to V(9).
2022-02-21 09:02:36 -05:00
Dan Winship
e7bae9df81 Count iptables lines as we write them 2022-02-19 11:56:14 -05:00
Kubernetes Prow Robot
2134e971a6
Merge pull request #107684 from aojea/nodePortsOnLocalhost
kube-proxy: only set route_localnet if required
2022-02-17 16:14:48 -08:00
Antonio Ojea
8b5fa408e0 kube-proxy: only set route_localnet if required
kube-proxy sets the sysctl net.ipv4.conf.all.route_localnet=1
so NodePort services can be accessed on the loopback addresses in
IPv4, but this may present security issues.

Leverage the --nodeport-addresses flag to opt-out of this feature,
if the list is not empty and none of the IP ranges contains an IPv4
loopback address this sysctl is not set.

In addition, add a warning to inform users about this behavior.
2022-02-17 20:20:31 +01:00
Dan Winship
88a3c6924e topology_test.go: merge tests into a single test
Move all of the tests into TestFilterEndpoints, rather than separately
testing some of its internal helper functions (which will be going
away).
2022-02-14 10:17:03 -05:00
Dan Winship
6caa18a6b7 topology_test.go: remove unnecessary helper type
Remove the `endpoint` type, and just use `Endpoint` directly in the
testCases.
2022-02-14 10:16:59 -05:00