Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reject Rules for ExternalIP and svc port if no ep #44547

Merged
merged 1 commit into from Apr 22, 2017

Conversation

ketkulka
Copy link
Contributor

What this PR does / why we need it:
Explained in issue #44516
Which issue this PR fixes (optional, in fixes #<issue number>(, fixes #<issue_number>, ...) format, will close that issue when PR gets merged): fixes #
Fixes #44516

Special notes for your reviewer:
Similar to #43415
Feedback welcome. Will be happy to improve the patch.
Unit Test done and passing.

Release note:

@k8s-ci-robot k8s-ci-robot added the cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. label Apr 17, 2017
@k8s-reviewable
Copy link

This change is Reviewable

@k8s-ci-robot k8s-ci-robot added the needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. label Apr 17, 2017
@k8s-ci-robot
Copy link
Contributor

Hi @ketkulka. Thanks for your PR.

I'm waiting for a kubernetes member to verify that this patch is reasonable to test. If it is, they should reply with @k8s-bot ok to test on its own line. Until that is done, I will not automatically test new commits in this PR, but the usual testing commands by org members will still work. Regular contributors should join the org to skip this step.

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository. I understand the commands that are listed here.

@k8s-github-robot k8s-github-robot added size/M Denotes a PR that changes 30-99 lines, ignoring generated files. release-note-label-needed labels Apr 17, 2017
@ketkulka
Copy link
Contributor Author

/approve @bprashanth @justinsb @thockin

@thockin
Copy link
Member

thockin commented Apr 17, 2017

@k8s-bot ok to test

@k8s-ci-robot k8s-ci-robot removed the needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. label Apr 17, 2017
Copy link
Member

@thockin thockin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We talked about adding a utility KUBE-MARK-REJECT rule (like KUBE-MARK-DROP) and simply inserting that into the service-chain, which would simplify and catch all these cases.

@freehan did we kill that idea?

@@ -1017,6 +1017,20 @@ func (proxier *Proxier) syncProxyRules(reason syncReason) {
// Allow traffic bound for external IPs that happen to be recognized as local IPs to stay local.
// This covers cases like GCE load-balancers which get added to the local routing table.
writeLine(natRules, append(dstLocalOnlyArgs, "-j", string(svcChain))...)

// If the service has no endpoints then reject packets coming from externalIP
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

s/from/via

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed in new version

if len(newEndpoints[svcName]) == 0 {
writeLine(filterRules,
"-A", string(kubeServicesChain),
"-m", "comment", "--comment", fmt.Sprintf(`"%s has no endpoints from externalIPs"`, svcNameString),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

s/from externalIPs// - simpler is better

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed in new version

writeLine(filterRules,
"-A", string(kubeServicesChain),
"-m", "comment", "--comment", fmt.Sprintf(`"%s has no endpoints from externalIPs"`, svcNameString),
"-m", "addrtype", "--dst-type", "LOCAL",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why are you checking addrtype?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

removed addrtype. fixed in new version

@thockin thockin assigned freehan and unassigned bprashanth Apr 17, 2017
@thockin thockin added release-note-none Denotes a PR that doesn't merit a release note. and removed release-note-label-needed labels Apr 17, 2017
@cblecker
Copy link
Member

@ketkulka:

I0417 12:41:49.583] Verifying hack/make-rules/../../hack/verify-gofmt.sh
I0417 12:42:02.606] diff ./pkg/proxy/iptables/proxier_test.go gofmt/./pkg/proxy/iptables/proxier_test.go
I0417 12:42:02.606] --- /tmp/gofmt965435796	2017-04-17 12:41:50.807482217 -0700
I0417 12:42:02.606] +++ /tmp/gofmt953671651	2017-04-17 12:41:50.807482217 -0700
I0417 12:42:02.606] @@ -775,9 +775,9 @@
I0417 12:42:02.607]  			svc.Spec.ClusterIP = svcIP
I0417 12:42:02.607]  			svc.Spec.ExternalIPs = []string{svcExternalIPs}
I0417 12:42:02.607]  			svc.Spec.Ports = []api.ServicePort{{
I0417 12:42:02.607] -				Name: svcPortName.Port,
I0417 12:42:02.607] -				Port: int32(svcPort),
I0417 12:42:02.607] -				Protocol: api.ProtocolTCP,
I0417 12:42:02.607] +				Name:       svcPortName.Port,
I0417 12:42:02.607] +				Port:       int32(svcPort),
I0417 12:42:02.607] +				Protocol:   api.ProtocolTCP,
I0417 12:42:02.607]  				TargetPort: intstr.FromInt(svcPort),
I0417 12:42:02.608]  			}}
I0417 12:42:02.608]  		}),
I0417 12:42:02.608] FAILED   hack/make-rules/../../hack/verify-gofmt.sh	13s

Needs a gofmt -w -s pkg/proxy/iptables/proxier_test.go run.

@thockin
Copy link
Member

thockin commented Apr 17, 2017

/approve

@freehan or @dcbw for final

@k8s-github-robot k8s-github-robot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Apr 17, 2017
@ketkulka
Copy link
Contributor Author

ping @freehan @dcbw

@freehan
Copy link
Contributor

freehan commented Apr 20, 2017

Thanks! /lgtm

@ketkulka
Copy link
Contributor Author

ketkulka commented Apr 20, 2017 via email

@cblecker
Copy link
Member

/lgtm
Adding on @freehan's behalf :)

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Apr 20, 2017
@freehan
Copy link
Contributor

freehan commented Apr 21, 2017

@k8s-bot test this

@cblecker
Copy link
Member

I0421 17:41:49.199] k8s.io/kubernetes/pkg/proxy/iptables/proxier.go:1105: undefined: newEndpoints

@ketkulka
Copy link
Contributor Author

got conflict with 2f25043
will submit a corrected patch.

@k8s-github-robot k8s-github-robot removed the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Apr 21, 2017
@ketkulka
Copy link
Contributor Author

uploaded a new patch. hopefully this passes.

@freehan
Copy link
Contributor

freehan commented Apr 21, 2017

/lgtm

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Apr 21, 2017
@ketkulka
Copy link
Contributor Author

Thanks!

@ketkulka ketkulka closed this Apr 21, 2017
@ketkulka ketkulka reopened this Apr 21, 2017
@cblecker
Copy link
Member

@ketkulka I'd make sure you've rebased off master, and that go test ./pkg/proxy/iptables works locally.

@ketkulka
Copy link
Contributor Author

actually i think that's what i did and it passed locally.

git remote add upstream https://github.com/kubernetes/kubernetes.git
git fetch upstream
git rebase upstream/master

i will do it once again.
let me know if i am mistaken

@freehan
Copy link
Contributor

freehan commented Apr 21, 2017

@k8s-bot cvm gce e2e test this
@k8s-bot unit test this
@k8s-bot bazel test this

@ketkulka
Copy link
Contributor Author

ketkulka commented Apr 21, 2017 via email

- Install ICMP Reject Rules for externalIP and svc port
  if no endpoints are present
- Includes Unit Test case
- Fixes kubernetes#44516
@k8s-github-robot k8s-github-robot removed the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Apr 21, 2017
@ketkulka
Copy link
Contributor Author

ketkulka commented Apr 21, 2017 via email

@cblecker
Copy link
Member

okay, main tests are passing now, and it looks good locally for me too
/lgtm

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Apr 22, 2017
@k8s-github-robot
Copy link

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: cblecker, freehan, ketkulka, thockin

Needs approval from an approver in each of these OWNERS Files:

You can indicate your approval by writing /approve in a comment
You can cancel your approval by writing /approve cancel in a comment

@k8s-github-robot
Copy link

Automatic merge from submit-queue

@k8s-github-robot k8s-github-robot merged commit 12c6b0c into kubernetes:master Apr 22, 2017
@ketkulka
Copy link
Contributor Author

ketkulka commented Jun 1, 2017

should this be picked for upcoming release?

@cblecker
Copy link
Member

cblecker commented Jun 1, 2017

@ketkulka This should make it into 1.7

k8s-github-robot pushed a commit that referenced this pull request Feb 23, 2018
Automatic merge from submit-queue. 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>.

Split KUBE-SERVICES chain to re-shrink the INPUT chain

**What this PR does / why we need it**:
#43972 added an iptables rule "`-A INPUT -j KUBE-SERVICES`" to make NodePort ICMP rejection work. (Previously the KUBE-SERVICES chain was only run from OUTPUT, not INPUT.) #44547 extended that patch for ExternalIP rejection as well.

However, the KUBE-SERVICES chain may potentially have a very large number of ICMP reject rules for plain ClusterIP services (the ones that get run from OUTPUT), and it seems that for some reason the kernel is much more sensitive to the length of the INPUT chain than it is to the length of the OUTPUT chain. So a node that worked fine with kube 1.6 (when KUBE-SERVICES was only run from OUTPUT) might fall over with kube 1.7 (with KUBE-SERVICES being run from both INPUT and OUTPUT).

(Specifically, a node with about 5000 ClusterIP reject rules that ran fine with OpenShift 3.6 [kube 1.6] slowed almost to a complete halt with OpenShift 3.7 [kube 1.7].)

This PR fixes things by splitting out the "new" part of KUBE-SERVICES (NodePort and ExternalIP reject rules) into a separate KUBE-EXTERNAL-SERVICES chain run from INPUT, and moves KUBE-SERVICES back to being only run from OUTPUT. (So, yes, this assumes that you don't have 5000 NodePort/ExternalIP services, but, if you do, there's not much we can do, since those rules *have* to be run on the INPUT side.)

Oh, and I left in the code to clean up the "`-A INPUT -j KUBE-SERVICES`" rule even though we don't generate it any more, so it gets fixed on upgrade.

**Release note**:
```release-note
Reorganized iptables rules to fix a performance regression on clusters with thousands of services.
```

@kubernetes/sig-network-bugs @kubernetes/rh-networking
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. lgtm "Looks good to me", indicates that a PR is ready to be merged. release-note-none Denotes a PR that doesn't merit a release note. size/M Denotes a PR that changes 30-99 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Need ICMP reject rules for externalIPs and port as well
9 participants