Commit Graph

100 Commits

Author SHA1 Message Date
JunYang
856146e67e Fix incorrect log information
Update pkg/util/iptables/iptables.go

Co-authored-by: Dan Winship <danwinship@redhat.com>

Update pkg/util/iptables/iptables.go

Co-authored-by: Dan Winship <danwinship@redhat.com>

Update pkg/util/iptables/iptables.go

Co-authored-by: Dan Winship <danwinship@redhat.com>

Update pkg/util/iptables/iptables.go

Co-authored-by: Dan Winship <danwinship@redhat.com>

Update pkg/util/iptables/iptables.go

Co-authored-by: Dan Winship <danwinship@redhat.com>

Update pkg/util/iptables/iptables.go

Co-authored-by: Dan Winship <danwinship@redhat.com>

Update pkg/util/iptables/iptables.go

Co-authored-by: Dan Winship <danwinship@redhat.com>

Update pkg/util/iptables/iptables.go

Co-authored-by: Dan Winship <danwinship@redhat.com>
2022-10-24 08:36:52 +08:00
cyclinder
97bd6e977d kube-proxy should log the payload when iptables-restore fails
Signed-off-by: cyclinder <qifeng.guo@daocloud.io>
2021-12-23 09:50:56 +08:00
cyclinder
d8a801a7a2 kube-proxy remove todo: call iptables -S first when delete chain
Signed-off-by: cyclinder <qifeng.guo@daocloud.io>
2021-11-17 10:12:57 +08:00
Khaled Henidak (Kal)
a53e2eaeab
move IPv6DualStack feature to stable. (#104691)
* kube-proxy

* endpoints controller

* app: kube-controller-manager

* app: cloud-controller-manager

* kubelet

* app: api-server

* node utils + registry/strategy

* api: validation (comment removal)

* api:pod strategy (util pkg)

* api: docs

* core: integration testing

* kubeadm: change feature gate to GA

* service registry and rest stack

* move feature to GA

* generated
2021-09-24 16:30:22 -07:00
Davanum Srinivas
26cc8e40a8
fix deadcode issues
Signed-off-by: Davanum Srinivas <davanum@gmail.com>
2021-07-14 08:41:21 -04:00
Dan Winship
95c6a488d8 Make kube-proxy check if IPv6 is really supported before assuming dual-stack 2021-02-17 09:11:15 -05:00
knight42
b25af8e3c9
feat(iptables): be able to override iptables-1.4-compatible lock path 2020-09-12 22:43:43 +08:00
Antonio Ojea
924553b7ee iptables don't do reverse DNS lookups
the iptables monitor was using iptables -L to list the chains,
without the -n option, so it was trying to do reverse DNS lookups.
A side effect is that it was holding the lock, so other components
could not use it.
We can use -S instead of -L -n to avoid this, since we only want
to check the chain exists.
2020-07-08 18:39:22 +02:00
Davanum Srinivas
442a69c3bd
switch over k/k to use klog v2
Signed-off-by: Davanum Srinivas <davanum@gmail.com>
2020-05-16 07:54:27 -04:00
Tim Hockin
9551ecb7c3 Cleanup: Change "Ip" to "IP" in func and var names 2020-04-10 15:29:50 -07:00
Tim Hockin
efb24d44c6 Rename iptables IsIpv6 to IsIPv6 2020-04-10 15:29:50 -07:00
Tim Hockin
ef934a2c5e Add Protocol() method to iptables
Enables simpler printing of which IP family the iptables interface is
managing.
2020-04-10 15:29:49 -07:00
SataQiu
51c742c1dd fix staticcheck failures of pkg/util/ipconfig pkg/util/iptables pkg/util/ipvs/testing 2020-01-09 16:05:11 +08:00
Antonio Ojea
51814ae189
Be more agressive acquiring the iptables lock
iptables has two options to modify the behaviour trying to
acquire the lock.

--wait  -w [seconds]    maximum wait to acquire xtables lock
                        before give up
--wait-interval -W [usecs]  wait time to try to acquire xtables
                            lock
                            interval to wait for xtables lock
                            default is 1 second

Kubernetes uses -w 5 that means that wait 5 seconds to try to
acquire the lock. If we are not able to acquire it, kube-proxy
fails and retries in 30 seconds, that is an important penalty
on sensitive applications.
We can be a bit more aggresive and try to acquire the lock every
100 msec, that means that we have to fail 50 times to not being
able to succeed.
2019-12-03 17:38:13 +01:00
gkarthiks
b05749c619 chore(gofmt): go format fix
Signed-off-by: gkarthiks <github.gkarthiks@gmail.com>
2019-11-19 08:30:16 -08:00
Karthikeyan Govindaraj
bdc11c2806
chore(lint): fix iptable.go file lint 2019-11-18 23:43:51 -08:00
Antonio Ojea
1268d1a8ff Improve iptables logging 2019-10-24 15:52:05 +02:00
Dan Winship
2f89c03c63 iptables.Monitor: don't be fooled by "could not get lock" errors 2019-10-02 11:35:12 -04:00
chenyaqi01
3175c9e226 simplify regexp with raw string 2019-09-20 16:53:56 +08:00
Dan Winship
3948f16ff4 Add iptables.Monitor, use it from kubelet and kube-proxy
Kubelet and kube-proxy both had loops to ensure that their iptables
rules didn't get deleted, by repeatedly recreating them. But on
systems with lots of iptables rules (ie, thousands of services), this
can be very slow (and thus might end up holding the iptables lock for
several seconds, blocking other operations, etc).

The specific threat that they need to worry about is
firewall-management commands that flush *all* dynamic iptables rules.
So add a new iptables.Monitor() function that handles this by creating
iptables-flush canaries and only triggering a full rule reload after
noticing that someone has deleted those chains.
2019-09-17 10:19:26 -04:00
Dan Winship
b6c3d5416a Drop iptables firewalld monitoring support
The firewalld monitoring code was not well tested (and not easily
testable), would never be triggered on most platforms, and was only
being taken advantage of from one place (kube-proxy), which didn't
need it anyway since it already has its own resync loop.

Since the firewalld monitoring was the only consumer of pkg/util/dbus,
we can also now delete that.
2019-09-15 15:35:40 -04:00
Dan Winship
75888077d3 Fix iptables version detection code to handle RHEL 7 correctly 2019-09-11 18:47:58 -04:00
Mike Spreitzer
d86d1defa1 Made IPVS and iptables modes of kube-proxy fully randomize masquerading if possible
Work around Linux kernel bug that sometimes causes multiple flows to
get mapped to the same IP:PORT and consequently some suffer packet
drops.

Also made the same update in kubelet.

Also added cross-pointers between the two bodies of code, in comments.

Some day we should eliminate the duplicate code.  But today is not
that day.
2019-09-01 22:07:30 -04:00
Dan Winship
81cd27a51e iptables: simplify version handling 2019-08-01 12:05:31 -04:00
Dan Winship
8bced9b130 iptables: don't do feature detection on the iptables-restore binary
The iptables code was doing version detection on the iptables binary
but feature detection on the iptables-restore binary, to try to
support the version of iptables in RHEL 7, which claims to be 1.4.21
but has certain features from iptables 1.6.

The problem is that this particular set of versions and checks
resulted in the code passing "-w" ("wait forever for the lock") to
iptables, but "-w 5" ("wait at most 5 seconds for the lock") to
iptables-restore. On systems with very very many iptables rules, this
could result in the kubelet periodic resyncs (which use "iptables")
blocking kube-proxy (which uses "iptables-restore") and causing it to
time out.

We already have code to grab the lock file by hand when using a
version of iptables-restore that doesn't support "-w", and it works
fine. So just use that instead, and only pass "-w 5" to
iptables-restore when iptables reports a version that actually
supports it.
2019-08-01 11:49:50 -04:00
Marko Lukša
93a549679f Capture stderr output and write it to buffer on error 2019-05-28 17:09:29 +02:00
Marko Lukša
00e7505618 Discard stderr output when calling iptables-save 2019-05-28 14:43:28 +02:00
Dan Winship
4d77d3e75f Update iptables.IsNotFoundError for iptables-nft error messages 2019-05-01 10:42:30 -04:00
JieJhih Jhang
098a7c5972 fix golint 2019-04-26 15:37:38 +08:00
Andrew Kim
93b086f6ea replace k8s.io/apiserver/pkg/util/trace with k8s.io/utils/trace 2019-01-24 15:34:21 -05:00
Davanum Srinivas
954996e231
Move from glog to klog
- Move from the old github.com/golang/glog to k8s.io/klog
- klog as explicit InitFlags() so we add them as necessary
- we update the other repositories that we vendor that made a similar
change from glog to klog
  * github.com/kubernetes/repo-infra
  * k8s.io/gengo/
  * k8s.io/kube-openapi/
  * github.com/google/cadvisor
- Entirely remove all references to glog
- Fix some tests by explicit InitFlags in their init() methods

Change-Id: I92db545ff36fcec83afe98f550c9e630098b3135
2018-11-10 07:50:31 -05:00
Benjamin Elder
8b56eb8588 hack/update-gofmt.sh 2018-09-24 12:21:29 -07:00
Benjamin Elder
088cf3c37b find & replace version import 2018-09-24 12:03:24 -07:00
Kubernetes Submit Queue
300f4915f3
Merge pull request #65216 from wojtek-t/log_long_iptables_operations
Automatic merge from submit-queue (batch tested with PRs 65152, 65199, 65179, 64598, 65216). If you want to cherry-pick this change to another branch, please follow the instructions <a href="https://github.com/kubernetes/community/blob/master/contributors/devel/cherry-picks.md">here</a>.

Log long operations on iptables

Ref #48107
2018-06-21 18:20:19 -07:00
wojtekt
0f9df22616 Log long operations on iptables 2018-06-20 08:43:42 +02:00
Brendan Burns
7b02b6d98c Address a TODO, move to lazy initialization of the firewallD signal handler. 2018-06-07 22:05:20 -07:00
zhouhaibing089
6dc32c33d7 iptables: add timeout when checking rules
in cases where iptables stucks forever due to some reasons, we lost
the availability of kube-proxy, this is about adding a timeout for
the rule checking operations, as a result, it should give us a more
reliable working iptables proxy.
2018-05-02 16:25:17 +08:00
Dan Winship
34ce573e99 Fix use of "-w" flag to iptables-restore
iptables accepts "-w5" but iptables-restore requires "-w 5"
2018-03-09 08:52:05 -05:00
Chun Chen
c6375c20b7 Add tests to test if legacy chains/rules can be cleaned up 2017-11-15 15:15:04 +08:00
Kubernetes Submit Queue
2f622b2a28
Merge pull request #52569 from tmjd/add-proxy-forward-rules
Automatic merge from submit-queue (batch tested with PRs 55009, 55532, 55601, 52569, 55533). If you want to cherry-pick this change to another branch, please follow the instructions <a href="https://github.com/kubernetes/community/blob/master/contributors/devel/cherry-picks.md">here</a>.

Kube-proxy adds forward rules to ensure NodePorts work

**What this PR does / why we need it**:
Updates kube-proxy to set up proper forwarding so that NodePorts work with docker 1.13 without depending on iptables FORWARD being changed manually/externally.

**Which issue this PR fixes** *(optional, in `fixes #<issue number>(, fixes #<issue_number>, ...)` format, will close that issue when PR gets merged)*: fixes #39823

**Special notes for your reviewer**:
@thockin I used option number 2 that I mentioned in the #39823 issue, please let me know what you think about this change.  If you are happy with the change then I can try to add tests but may need a little direction about what and where to add them.

**Release note**:

```release-note
Add iptables rules to allow Pod traffic even when default iptables policy is to reject.
```
2017-11-14 00:09:57 -08:00
Benjamin Bennett
a5c334046b Add the iptables wait flag change to more places
There were a few places that the last PR https://github.com/kubernetes/kubernetes/pull/54763 missed because the flags that PR covered were of the form -w2.  Some of the code had --wait=2.  This changes that code to use the same global variable for the wait setting so that everything is consistent.
2017-11-07 10:50:28 -05:00
Rajat Chopra
c5740a3737 make iptables wait flag generic; increase the max wait time from 2 seconds to 5 seconds 2017-10-30 14:22:25 -04:00
Erik Stidham
7c108f595d Initial changes for adding forward rules 2017-09-15 13:34:20 -05:00
Dane LeBlanc
b45a406aca Fix kube-proxy to use proper iptables commands for IPv6 operation
For iptables save and restore operations, kube-proxy currently uses
the IPv4 versions of the iptables save and restore utilities
(iptables-save and iptables-restore, respectively). For IPv6 operation,
the IPv6 versions of these utilities needs to be used
(ip6tables-save and ip6tables-restore, respectively).

Both this change and PR #48551 are needed to get Kubernetes services
to work in an IPv6-only Kubernetes cluster (along with setting
'--bind-address ::0' on the kube-proxy command line. This change
was alluded to in a discussion on services for issue #1443.

fixes #50474
2017-08-10 19:24:44 -04:00
ymqytw
3dfc8bf7f3 update import 2017-07-20 11:03:49 -07:00
Minhan Xia
8de419b19f expose lock release error from iptables util 2017-07-05 14:31:24 -07:00
Wojciech Tyczynski
9e6de42745 Remove Save() from iptables interface 2017-05-22 13:23:49 +02:00
Wojciech Tyczynski
a3da8d7300 Fix naming and comments in kube-proxy. 2017-05-19 21:34:05 +02:00
Wojciech Tyczynski
7d44f83441 Descrese logs verbosity for iptables 2017-05-19 20:44:26 +02:00
Wojciech Tyczynski
bcfae7e1ed Extend Iptables interface with SaveInto 2017-05-19 20:44:25 +02:00