-
Notifications
You must be signed in to change notification settings - Fork 8.3k
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
Ingress Status: Improve checking for rollover or shutdown. #10686
base: main
Are you sure you want to change the base?
Ingress Status: Improve checking for rollover or shutdown. #10686
Conversation
✅ Deploy Preview for kubernetes-ingress-nginx canceled.
|
This issue is currently awaiting triage. If Ingress contributors determines this is a relevant issue, they will accept it by applying the The 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. |
Welcome @nefelim4ag! |
Hi @nefelim4ag. 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 Once the patch is verified, the new status will be reflected by the I understand the commands that are listed here. 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. |
8c0b5d5
to
9f092d3
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added some suggestions.
fb259e1
to
55619e7
Compare
Looks great! Unfortunately I'm not eligible for approving controller PRs, yet. But if you really wanna go the extra mile, you could have a look at this issue and check if your PR can (at least partly) improve what's not working in there. I know, your change is focus on not having a published service, but maybe you can at least have a look. :) |
@Gacko You are right, this is the same problem here. But I'm not sure they are directly related to each other because helm upgrade path and drop of LB status must be handled by UPD:
They are creating problems. As quick fix, it is possible to make them "common" and add them to the filter. But right solution will be to make some more magic & rewrite that discovery logic completely. Anyway, only maintainers have the right to choose a solution, and this is out of the scope of this PR (IMHO). |
if pod.GetDeletionTimestamp() != nil { | ||
klog.InfoS("POD is terminating", "pod", klog.KObj(&pod), "node", pod.Spec.NodeName) | ||
continue | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Isn't the deletion timestamp set by the API server? So if a pod has finalizers or connections are still draining, I'm not sure if the controller is still running while already having the timestamp set.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's sets equals to delete request time
When you create a resource using a manifest file, you can specify finalizers in the metadata.finalizers field. When you attempt to delete the resource, the API server handling the delete request notices the values in the finalizers field and does the following:
Modifies the object to add a metadata.deletionTimestamp field with the time you started the deletion.
Prevents the object from being removed until all items are removed from its metadata.finalizers field
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, I'm aware of that. But setting deletionTimestamp
does not mean the pod is actually terminating as the actual shutdown is initiated by kubelet
at last and, in case of ingress-nginx
might take longer due to the preStopHook
. So the container itself is unready at that point, which means it's not eligible for new connections, but still running and able to take over leadership until it's getting asked to terminate after either the preStopHook
completion or timeout (240s IIRC).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, but if Nginx doesn't have connections it will exit immediately, so the container itself becomes useless almost instantly.
I1203 00:53:44.834420 8 nginx.go:387] "Stopping admission controller"
E1203 00:53:44.834468 8 nginx.go:326] "Error listening for TLS connections" err="http: Server closed"
I1203 00:53:44.834473 8 nginx.go:395] "Stopping NGINX process"
2023/12/03 00:53:44 [notice] 310#310: signal process started
I1203 00:53:45.867820 8 nginx.go:408] "NGINX process has stopped"
I1203 00:53:45.867839 8 sigterm.go:44] Handled quit, delaying controller exit for 10 seconds
Because of this, I use sleep
before sending signals to process.
Anyway, that is how service endpoints work. Pod with terminating status will be removed from endpoints, ignoring ready status. But because we emulating this logic in this specific case (publishService disabled). The same termination handling must be here, so the container can be in terminating status for some time, ready for the same amount of time (to process connections).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So, usage example for here, where it can have shortlived requests, and current logic will not work.
- Amazon ELB - it awfully slow to update endpoints.
- DNS, where LoadBalancer status is several A records, so I want to wait for record TTL before killing the pod.
Same for K8s services, because of "eventual consistency" but update of IPTables/IPVS requires several seconds, so sleep 15
everywhere makes internal networking work nice (of course it depends on the application, I'm talking about HTTP here).
I mean, this is not an Ingress nginx specific issue, this is how the k8s are designed from the ground up.
Termination handling eventually will be reimplemented everywhere, where pod discovery mimics service discovery logic.
The same issue was in External-dns for quite some time: kubernetes-sigs/external-dns#3447 (comment)
/assign |
55619e7
to
eef2079
Compare
eef2079
to
abdd6ba
Compare
Added tests, and now helm labels will be ignored, which can work as duct tape for: I can squash/rebase on request, np. |
/retitle Ingress Status: Improve checking for rollover or shutdown. |
Hello, how can I assist somehow with this PR? |
abdd6ba
to
200ae7f
Compare
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: nefelim4ag The full list of commands accepted by this bot can be found here.
Needs approval from an approver in each of these files:
Approvers can indicate their approval by writing |
|
200ae7f
to
01f38e4
Compare
@longwuyuan I did not quite understand how I could provide that to someone (testing cluster), I used the patched version this whole time because it fixed my issues on my dev/prod clusters. I described the problems (we talk about the usage of ingress nginx without LB, where this code applies):
There are images: https://gallery.ecr.aws/xflow-ltd/ingress-nginx, so 1.9.4-p2, 1.10.1-p1 Yes, squash sounds good after that amount of time. |
01f38e4
to
f685bd2
Compare
f685bd2
to
3402260
Compare
Signed-off-by: Timofey Titovets <nefelim4ag@gmail.com>
Co-authored-by: Marco Ebert <marco_ebert@icloud.com> Signed-off-by: Timofey Titovets <nefelim4ag@gmail.com>
Signed-off-by: Timofey Titovets <nefelim4ag@gmail.com>
Signed-off-by: Timofey Titovets <nefelim4ag@gmail.com>
3402260
to
8216d4a
Compare
What this PR does / why we need it:
Filter out pods in terminating state from pod discovery.
Reuse common labels filter for pod discovery between ReplicaSets.
Types of changes
Which issue/s this PR fixes
fixes #10680 - incorrect handling of pod rollout without publishService
fixes #10681 - missing handling of pods in terminating state
How Has This Been Tested?
Build image, replace current 1.9.4 image with patched.
Make
kubectl -n ingress-nginx rollout restart deployment ingress-nginx-controller
for RS handling tests.Patch LifeCycle.preStop to:
And monitoring ingress status for correct changes:
Checklist:
Current status_test.go are a little fragile and I currently struggle with just adding pods with new statuses and adding tests. But I'm working on it, any help will be appreciated.
Thanks!