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

Clear conntrack entries for externalIP and LoadBalancer IP #73323

Merged
merged 4 commits into from
Feb 20, 2019

Conversation

prameshj
Copy link
Contributor

@prameshj prameshj commented Jan 25, 2019

When an endpoint is deleted, the conntrack entries are cleared for
clusterIP but not for externalIP of the service. This change adds
that step.

What type of PR is this?

Uncomment only one /kind <> line, hit enter to put that in a new line, and remove leading whitespaces from that line:

/kind api-change

/kind bug

/kind cleanup
/kind design
/kind documentation
/kind failing-test
/kind feature
/kind flake

What this PR does / why we need it:
When an endpoint is deleted, the conntrack entries are cleared for clusterIP but not for externalIP of the service spec and LoadBalancer ip from service status. This PR adds that step.
Which issue(s) this PR fixes:

Fixes #65228

Special notes for your reviewer:

Does this PR introduce a user-facing change?:

NONE

When an endpoint is deleted, the conntrack entries are cleared for
clusterIP but not for externalIP of the service. This change adds
that step.
@k8s-ci-robot k8s-ci-robot added release-note-none Denotes a PR that doesn't merit a release note. size/S Denotes a PR that changes 10-29 lines, ignoring generated files. kind/bug Categorizes issue or PR as related to a bug. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. needs-sig Indicates an issue or PR lacks a `sig/foo` label and requires one. needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. needs-priority Indicates a PR lacks a `priority/foo` label and requires one. labels Jan 25, 2019
@k8s-ci-robot k8s-ci-robot added sig/network Categorizes an issue or PR as relevant to SIG Network. and removed needs-sig Indicates an issue or PR lacks a `sig/foo` label and requires one. labels Jan 25, 2019
@k8s-ci-robot k8s-ci-robot removed the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Jan 25, 2019
@prameshj
Copy link
Contributor Author

/assign @freehan

@steven-sheehy
Copy link

Thanks @prameshj for the fix. I can try to test locally if you have a docker image pushed somewhere.

Also, the fixes statement in the description has an extra slash, so referenced ticket won't get closed automatically.

@@ -613,6 +613,12 @@ func (proxier *Proxier) deleteEndpointConnections(connectionMap []proxy.ServiceE
if err != nil {
klog.Errorf("Failed to delete %s endpoint connections, error: %v", epSvcPair.ServicePortName.String(), err)
}
for _, extIP := range svcInfo.ExternalIPStrings() {
err := conntrack.ClearEntriesForNAT(proxier.exec, extIP, endpointIP, v1.ProtocolUDP)

Choose a reason for hiding this comment

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

This has the potential to indiscriminantly remove all sessions matching external IP to endpointIP regardless if it's stale or not. Can this be written to be more selective especially if we know the port(s) involved in the stale session?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

There is a check above(L608) to delete stale connections based on the NodePort. If user is not using NodePort and has specified TargetPort by name, that could have a different value for each endPoint. ServiceEndpoint currently does not expose this value.

Copy link

@hiep-huynh hiep-huynh left a comment

Choose a reason for hiding this comment

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

I repeatedly tested our apps using latest test build with your fix. I deleted the pods with UDP services in order to reproduce/cause stale sessions and verified that the stale sessions were removed immediately. I also verified that new UDP sessions and traffic were able to be created to the new pod instances.

In doing so I realized that my concerns about inadvertent removal of sessions for matching extIP, endpointIP, and of UDP type doesn't apply for the reason that pod instance endpointIP are unique and in deleting the instance, it's desirable to clear all sessions related to this endpointIP to prevent routing black holes. I'm able to verify that your code accomplishes this by clearing sessions from all possible extIPs to the removed pod instance endpointIP.

@prameshj
Copy link
Contributor Author

prameshj commented Feb 11, 2019

I repeatedly tested our apps using latest test build with your fix. I deleted the pods with UDP services in order to reproduce/cause stale sessions and verified that the stale sessions were removed immediately. I also verified that new UDP sessions and traffic were able to be created to the new pod instances.

In doing so I realized that my concerns about inadvertent removal of sessions for matching extIP, endpointIP, and of UDP type doesn't apply for the reason that pod instance endpointIP are unique and in deleting the instance, it's desirable to clear all sessions related to this endpointIP to prevent routing black holes. I'm able to verify that your code accomplishes this by clearing sessions from all possible extIPs to the removed pod instance endpointIP.

Thanks for verifying! There could still be a conflict if someone is using 2 different UDP-based services with the same pods as endpoints right? But since this endpoint is stale anyway, it should be ok to delete those connections as well.

@freehan
Copy link
Contributor

freehan commented Feb 12, 2019

It would be great this PR can also cover the IP from LoadbalancerStatus. Just need to mirror the logic for that case

@k8s-ci-robot k8s-ci-robot added size/M Denotes a PR that changes 30-99 lines, ignoring generated files. and removed size/S Denotes a PR that changes 10-29 lines, ignoring generated files. labels Feb 13, 2019
@steven-sheehy
Copy link

Need to update PR title & description to reflect LB change. Also, is there a relevant ticket for LB @freehan ?

@prameshj prameshj changed the title Clear conntrack entries for externalIP Clear conntrack entries for externalIP and LoadBalancer IP Feb 13, 2019
@prameshj
Copy link
Contributor Author

Need to update PR title & description to reflect LB change. Also, is there a relevant ticket for LB Minhan Xia ?
Can we reuse the same ticket for this too? We are just clearing conntrack entries for all IPs used to refer to the service, in addition to clusterIP

@steven-sheehy
Copy link

If you're asking me, I think it's fine to reuse ticket. I just wasn't sure if there was an existing issue for the LB IP that we can also link to.

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Feb 15, 2019
Copy link
Contributor

@freehan freehan left a comment

Choose a reason for hiding this comment

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

/lgtm
/approve

@prameshj
Copy link
Contributor Author

/assign @thockin

@freehan
Copy link
Contributor

freehan commented Feb 15, 2019

If you're asking me, I think it's fine to reuse ticket. I just wasn't sure if there was an existing issue for the LB IP that we can also link to.

I do not think there is an existing issue for LB IP. But I would imagine the same problem will hit UDP LBs.

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.

/lgtm
/approve

@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

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

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@k8s-ci-robot k8s-ci-robot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Feb 19, 2019
@prameshj
Copy link
Contributor Author

/retest

@k8s-ci-robot k8s-ci-robot merged commit 059d605 into kubernetes:master Feb 20, 2019
k8s-ci-robot added a commit that referenced this pull request Aug 30, 2019
…23-upstream-release-1.13

Automated cherry pick of #73323: Clear conntrack entries for externalIP
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. kind/bug Categorizes issue or PR as related to a bug. lgtm "Looks good to me", indicates that a PR is ready to be merged. needs-priority Indicates a PR lacks a `priority/foo` label and requires one. release-note-none Denotes a PR that doesn't merit a release note. sig/network Categorizes an issue or PR as relevant to SIG Network. 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.

Delete stale UDP conntrack entries with external ip usage
6 participants