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

Install a REJECT rule for nodeport with no backend #43415

Merged
merged 1 commit into from
Mar 21, 2017

Conversation

thockin
Copy link
Member

@thockin thockin commented Mar 20, 2017

Rather than actually accepting the connection, REJECT. This will avoid
CLOSE_WAIT.

Fixes #43212

@justinsb @felipejfc @Spiddy

@thockin thockin added this to the v1.6 milestone Mar 20, 2017
@k8s-ci-robot k8s-ci-robot added cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. labels Mar 20, 2017
@k8s-github-robot k8s-github-robot added approved Indicates a PR has been approved by an approver from all required OWNERS files. size/M Denotes a PR that changes 30-99 lines, ignoring generated files. release-note-label-needed labels Mar 20, 2017
@k8s-reviewable
Copy link

This change is Reviewable

@thockin thockin added release-note-none Denotes a PR that doesn't merit a release note. and removed release-note-label-needed labels Mar 20, 2017
Copy link
Member

@justinsb justinsb left a comment

Choose a reason for hiding this comment

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

Some nits, but I haven't figured out how >= 0 is correct yet (but e2e didn't fail catastrophically, so...)

@@ -1108,6 +1108,18 @@ func (proxier *Proxier) syncProxyRules() {
// Currently we only create it for loadbalancers (#33586).
writeLine(natRules, append(args, "-j", string(svcXlbChain))...)
}

// If the service has no endpoints then reject packets.
if len(proxier.endpointsMap[svcName]) >= 0 {
Copy link
Member

Choose a reason for hiding this comment

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

Do you mean == 0 ?

Copy link
Member Author

Choose a reason for hiding this comment

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

dangit, vestigial from something else I tried.

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

Choose a reason for hiding this comment

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

The comment here is inconsistent with >= 0

Copy link
Member Author

Choose a reason for hiding this comment

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

hush, you!

Copy link
Member

Choose a reason for hiding this comment

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

Just wasn't sure which one was wrong :-)

@@ -1108,6 +1108,18 @@ func (proxier *Proxier) syncProxyRules() {
// Currently we only create it for loadbalancers (#33586).
writeLine(natRules, append(args, "-j", string(svcXlbChain))...)
}

Copy link
Member

Choose a reason for hiding this comment

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

We could do the "no endpoints" check before writing the MARK/SVC or XLB rules. But I presume we want to keep the rules less volatile?

Copy link
Member Author

Choose a reason for hiding this comment

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

I have an idea for future refactoring that will make this nice, so I made the smallest change I could.

Copy link
Member

Choose a reason for hiding this comment

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

You're saying you have a cunning plan? 👍

@@ -1108,6 +1108,18 @@ func (proxier *Proxier) syncProxyRules() {
// Currently we only create it for loadbalancers (#33586).
writeLine(natRules, append(args, "-j", string(svcXlbChain))...)
}

// If the service has no endpoints then reject packets.
Copy link
Member

@justinsb justinsb Mar 21, 2017

Choose a reason for hiding this comment

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

It took me a while to figure out that this is the analog of the nodeport entry chain below (e.g. I was wondering why you were changing kubeServicesChain and not the NodePort chain). Expanding the comment to that effect may be helpful.

e.g.

If the service has no endpoints then reject packets.
We add a rule to the service chain that is the equivalent of the "tail-call to nodeports chain",
but immediately rejects the packet.

Copy link
Member Author

Choose a reason for hiding this comment

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

will add words

@thockin
Copy link
Member Author

thockin commented Mar 21, 2017

new push is up

@justinsb
Copy link
Member

Sorry ... I see a new commit, but I don't see anything different?

@justinsb
Copy link
Member

BTW any idea why all the e2e tests aren't failing? Aren't we blocking all NodePorts?

Rather than actually accepting the connection, REJECT.  This will avoid
CLOSE_WAIT.
@thockin
Copy link
Member Author

thockin commented Mar 21, 2017

I botched the amend. Fixed.

It didn't trigger the e2es because the nat PREROUTING table triggers first, so the original packet never hits the filter table.

@justinsb
Copy link
Member

/lgtm

Nice - and the explanation for how the e2e tests are not blowing up makes sense now you've explained it!

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

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: justinsb, 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 1e5fa8f into kubernetes:master Mar 21, 2017
@justinsb
Copy link
Member

Going to propose this for cherry picking to 1.4 and 1.5.

@justinsb
Copy link
Member

justinsb commented Apr 3, 2017

So I'm afraid I think this is still happening in 1.6.0. I can scale down a deployment to size 0 and I see CLOSE_WAIT accumulating , and I don't see any has no endpoints rule, either nodeport or clusterip.

I think that the problem is maybe that we don't set activeNATChains, but I'm trying to get a test to fail.

@justinsb
Copy link
Member

justinsb commented Apr 3, 2017

Edit: It does have the drop rules, in iptables -t filter (not -t nat). But the CLOSE_WAIT sockets are still accumulating. Digging...

@justinsb
Copy link
Member

justinsb commented Apr 3, 2017

Figured it out I think - put details into #43969

@ketkulka
Copy link
Contributor

ketkulka commented Apr 13, 2017

@justinsb @thockin the reject rules should also be installed for externalIPs and ports in addition to service IPs and node port. I am hitting a case where reject with icmp rule get installed for destination=service ip but not for destination=externalIPs. And when no pods are present; kube-proxy accepts the connection coming via externalIPs.

@thockin
Copy link
Member Author

thockin commented Apr 14, 2017 via email

@ketkulka
Copy link
Contributor

Thanks @thockin .
Opened #44516 to track it. I can give a shot for the patch but I must admit I have no way of verifying all cases.

k8s-github-robot pushed a commit that referenced this pull request Apr 22, 2017
Automatic merge from submit-queue

Reject Rules for ExternalIP and svc port if no ep

- Install ICMP Reject Rules for externalIP and svc port
  if no endpoints are present
- Includes Unit Test case
- Fixes #44516 



**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**:

```release-note
```
@thockin thockin deleted the fix-nodeport-close-wait branch August 14, 2019 17:44
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.

None yet

8 participants