[go: up one dir, main page]

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

Storage protection feature does not integrate well with StatefulSet PVC recreation #74374

Closed
msau42 opened this issue Feb 21, 2019 · 58 comments
Closed
Assignees
Labels
help wanted Denotes an issue that needs help from a contributor. Must meet "help wanted" guidelines. kind/bug Categorizes issue or PR as related to a bug. lifecycle/rotten Denotes an issue or PR that has aged beyond stale and will be auto-closed. sig/apps Categorizes an issue or PR as relevant to SIG Apps. sig/storage Categorizes an issue or PR as relevant to SIG Storage.

Comments

@msau42
Copy link
Member
msau42 commented Feb 21, 2019

What happened:
The storage protection feature prevents PVC deletion until all Pods referencing it are deleted. This doesn't work well with Statefulsets when you want to delete the PVC and have the StatefulSet controller recreate it. The StatefulSet controller only creates missing PVCs when creating a new Pod. So you could have a sequence like this:

  1. Try to delete PVC. Deletion is pending due to the storage protection finalizer.
  2. Delete the Pod.
  3. StatefulSet controller notices that the pod is deleted and creates the replacement pod. But the PVC already exists, so a new one is not created.
  4. Storage protection controller removes the finalizer and the PVC is deleted
  5. New pod is pending. First because PVC deletion is pending, and then 2nd because PVC is deleted.

Nothing tries to recreate the PVC again and the Pod is stuck in pending forever.

What you expected to happen:
We could potentially add logic in the statefulset controller to check if the PVC is terminating here. However, it uses an informer so the race may still exist.

Another option is to make the StatefulSet controller actively reconcile PVC creation. This would probably require more substantial changes to the controller.

@kubernetes/sig-storage-bugs
@kubernetes/sig-apps-bugs

@msau42 msau42 added the kind/bug Categorizes issue or PR as related to a bug. label Feb 21, 2019
@k8s-ci-robot k8s-ci-robot added sig/storage Categorizes an issue or PR as relevant to SIG Storage. sig/apps Categorizes an issue or PR as relevant to SIG Apps. labels Feb 21, 2019
@msau42 msau42 changed the title Storage protection feature does not integrate well with StatefulSet pod recreation Storage protection feature does not integrate well with StatefulSet PVC recreation Feb 21, 2019
@msau42
Copy link
Member Author
msau42 commented Feb 21, 2019

A workaround in the meantime is to delete the StatefulSet pod a second time if it's stuck in pending due to missing PVC.

@kow3ns
Copy link
Member
kow3ns commented Feb 25, 2019

/assign

@kow3ns
Copy link
Member
kow3ns commented Feb 25, 2019

/assign msau42

@cscetbon
Copy link
cscetbon commented Mar 10, 2019

Hey @msau42 thank you for having opened the issue and the temporary workaround

any news on that bug ? ??

@KevinTHU
Copy link
KevinTHU commented Jun 5, 2019

I think this need to be fixed, but not just workaround. a second delete of pod is not a graceful operation.

@msau42
Copy link
Member Author
msau42 commented Jun 5, 2019

I would be happy to help guide someone to come up with a possible design and implementation for a fix.

/help

@k8s-ci-robot
Copy link
Contributor

@msau42:
This request has been marked as needing help from a contributor.

Please ensure the request meets the requirements listed here.

If this request no longer meets these requirements, the label can be removed
by commenting with the /remove-help command.

In response to this:

I would be happy to help guide someone to come up with a possible design and implementation for a fix.

/help

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.

@k8s-ci-robot k8s-ci-robot added the help wanted Denotes an issue that needs help from a contributor. Must meet "help wanted" guidelines. label Jun 5, 2019
@zhangxiaoyu-zidif
Copy link
Contributor

when recreate pod, check if the PVC was label with deletion. maybe we could delete the PVC immediately by force and create a new PVC before Pod creation.

@mucahitkurt
Copy link
Contributor

Hey @msau42,

I would like to work on this issue. As far as I understand StatefulSetController check the different state of the pods and take some action according to pod states when syncing statefulset.

May be I add the pod Pending state here and then check if the pod's pvc exist or not, if not then create the missing pvc.

wdyt?

@KevinTHU
Copy link

the most hard part is that finding the status of pvc(creating pod process), and the deletion of pvc(pvc-protection finalizer) is in different goroutines. there will be concourrent problem.

@cwdsuzhou
Copy link
Member

@msau42 @kow3ns I have sent a PR #79164.
I have ran it in my cluster, it works.

@mucahitkurt
Copy link
Contributor

Hey @msau42,

I would like to work on this issue. As far as I understand StatefulSetController check the different state of the pods and take some action according to pod states when syncing statefulset.

May be I add the pod Pending state here and then check if the pod's pvc exist or not, if not then create the missing pvc.

wdyt?

Alternative solution might be like https://github.com/mucahitkurt/kubernetes/tree/fix/enable-statefulset-pvc-recreation-for-pending-pod

@cscetbon
Copy link

I think you mean mucahitkurt@1ab4b97

@cscetbon
Copy link
cscetbon commented Jun 19, 2019

@mucahitkurt if I understand your code well, if a Pod is in PodPending state you try to recreate the PVC. What if a Pod is just restarted by k8s on the same host ? would the recreation just fail ? what if the previous PVC is still in terminating (same name in our case) ?

@cwdsuzhou
Copy link
Member

@mucahitkurt we may need know if the pod keeps in pending or just pending transitorily.

  1. If it keeps in pending, we need try to recreate the pvc ( there also may be many other reasons lead to pending)
  2. If it is pending transitorily, we should do nothing

@mucahitkurt
Copy link
Contributor

@mucahitkurt if I understand your code well, if a Pod is in PodPending state you try to recreate the PVC. What if a Pod is just restarted by k8s on the same host ? would the recreate just fail ? what if the previous PVC is still in terminating (same name in our case) ?

@cscetbon I'll test these scenarios on my local cluster, but CreatePersistentVolumeClaims does not directly create the PVC, firstly it checks the pod's pvc is missing or not, if the pvc is not found then it tries to create the pvc. So If a statefulset pod is restarting and there is no missing pvc this solution won't do anything.

If the previous PVC is still terminating, I expect that pvc lister returns this pvc and CreatePersistentVolumeClaims won't try to recreate the pvc.

@cwdsuzhou actualy CreatePersistentVolumeClaims try to create the PVC if it's missing, if the pod is in pending state and reason is another thing other than missing PVC, this solution's cost will be querying the same pvcs again and again (spc.pvcLister.PersistentVolumeClaims(claim.Namespace).Get(claim.Name)). So if a pod in pending state and there is no missing pvc the solution won't do anything that has side effect.

@msau42
Copy link
Member Author
msau42 commented Jun 21, 2019

I wonder if we actually need to check pod state? Regardless of pod state, can we just check if any of its pvcs are missing?

@cscetbon
Copy link

@msau42 what if we check that it exists and it does in deleting state ?

@mucahitkurt
Copy link
Contributor
mucahitkurt commented Jun 21, 2019

I wonder if we actually need to check pod state? Regardless of pod state, can we just check if any of its pvcs are missing?

@msau42 ,

Most probably there won't be any side effect checking the missing PVCs with CreatePersistentVolumeClaims method regarless of pod state, because as far as I understand this method works in a idempotent way.

Checking pod's PVCs existence at every sync operation can create some performance effect.

I don't know about the different scenarios that we need to check the existence of pod's PVCs at every statefulset sync. Do you have any scenario?

@janetkuo
Copy link
Member
janetkuo commented Jun 22, 2019

We could potentially add logic in the statefulset controller to check if the PVC is terminating. However, it uses an informer so the race may still exist.

An alternative is to get PVC directly from API server instead of cache to avoid the race. The logic would be straightforward and the code change is small.

We'll only do this when creating a Pod with an existing PVC. Therefore, the chance of hitting this case would be pretty low, and the impact to API server would be small too.

@mucahitkurt
Copy link
Contributor

We could potentially add logic in the statefulset controller to check if the PVC is terminating. However, it uses an informer so the race may still exist.

An alternative is to get PVC directly from API server instead of cache to avoid the race. The logic would be straightforward and the code change is small.

We'll only do this when creating a Pod with an existing PVC. Therefore, the chance of hitting this case would be pretty low, and the impact to API server would be small too.

@janetkuo
Do you have any concern with my solution alternative that has no race condition I think?

@andyxning
Copy link
Member

/sub

@santhoshs123
Copy link

Is this issue fixed in k8s version 1.20? I used to hit this issue 100% of the times in 1.19, in 1.20 pod remains in pending until the pvc gets recreated, without any PVC not found events, once the pvc is recreated pod goes to running.

@fejta-bot
Copy link

Issues go stale after 90d of inactivity.
Mark the issue as fresh with /remove-lifecycle stale.
Stale issues rot after an additional 30d of inactivity and eventually close.

If this issue is safe to close now please do so with /close.

Send feedback to sig-contributor-experience at kubernetes/community.
/lifecycle stale

@k8s-ci-robot k8s-ci-robot added the lifecycle/stale Denotes an issue or PR has remained open with no activity and has become stale. label Jun 20, 2021
@fejta-bot
Copy link

Stale issues rot after 30d of inactivity.
Mark the issue as fresh with /remove-lifecycle rotten.
Rotten issues close after an additional 30d of inactivity.

If this issue is safe to close now please do so with /close.

Send feedback to sig-contributor-experience at kubernetes/community.
/lifecycle rotten

@k8s-ci-robot k8s-ci-robot added lifecycle/rotten Denotes an issue or PR that has aged beyond stale and will be auto-closed. and removed lifecycle/stale Denotes an issue or PR has remained open with no activity and has become stale. labels Jul 20, 2021
@ThisIsQasim
Copy link

/remove-lifecycle rotten

@k8s-ci-robot k8s-ci-robot removed the lifecycle/rotten Denotes an issue or PR that has aged beyond stale and will be auto-closed. label Jul 21, 2021
@k8s-triage-robot
Copy link

The Kubernetes project currently lacks enough contributors to adequately respond to all issues and PRs.

This bot triages issues and PRs according to the following rules:

  • After 90d of inactivity, lifecycle/stale is applied
  • After 30d of inactivity since lifecycle/stale was applied, lifecycle/rotten is applied
  • After 30d of inactivity since lifecycle/rotten was applied, the issue is closed

You can:

  • Mark this issue or PR as fresh with /remove-lifecycle stale
  • Mark this issue or PR as rotten with /lifecycle rotten
  • Close this issue or PR with /close
  • Offer to help out with Issue Triage

Please send feedback to sig-contributor-experience at kubernetes/community.

/lifecycle stale

@k8s-ci-robot k8s-ci-robot added the lifecycle/stale Denotes an issue or PR has remained open with no activity and has become stale. label Oct 19, 2021
@nikola-n6c
Copy link

Is the deletion order of Pod -> PVC -> PV still prone to this bug/race-condition? I still see this behavior in 1.20.5

@ymmt2005
Copy link
Contributor

Yes, PVC should be marked deleted before Pod.

@k8s-triage-robot
Copy link

The Kubernetes project currently lacks enough active contributors to adequately respond to all issues and PRs.

This bot triages issues and PRs according to the following rules:

  • After 90d of inactivity, lifecycle/stale is applied
  • After 30d of inactivity since lifecycle/stale was applied, lifecycle/rotten is applied
  • After 30d of inactivity since lifecycle/rotten was applied, the issue is closed

You can:

  • Mark this issue or PR as fresh with /remove-lifecycle rotten
  • Close this issue or PR with /close
  • Offer to help out with Issue Triage

Please send feedback to sig-contributor-experience at kubernetes/community.

/lifecycle rotten

@k8s-ci-robot k8s-ci-robot added lifecycle/rotten Denotes an issue or PR that has aged beyond stale and will be auto-closed. and removed lifecycle/stale Denotes an issue or PR has remained open with no activity and has become stale. labels Nov 28, 2021
@jingxu97
Copy link
Contributor

@cofyc Is this issue completely resolved or still need some fixes after your change?

@cofyc
Copy link
Member
cofyc commented Nov 30, 2021

/remove-lifecycle rotten
not resolved completely, but the impact is minor (I guess).

@k8s-ci-robot k8s-ci-robot removed the lifecycle/rotten Denotes an issue or PR that has aged beyond stale and will be auto-closed. label Nov 30, 2021
@k8s-triage-robot
Copy link

The Kubernetes project currently lacks enough contributors to adequately respond to all issues and PRs.

This bot triages issues and PRs according to the following rules:

  • After 90d of inactivity, lifecycle/stale is applied
  • After 30d of inactivity since lifecycle/stale was applied, lifecycle/rotten is applied
  • After 30d of inactivity since lifecycle/rotten was applied, the issue is closed

You can:

  • Mark this issue or PR as fresh with /remove-lifecycle stale
  • Mark this issue or PR as rotten with /lifecycle rotten
  • Close this issue or PR with /close
  • Offer to help out with Issue Triage

Please send feedback to sig-contributor-experience at kubernetes/community.

/lifecycle stale

@k8s-ci-robot k8s-ci-robot added the lifecycle/stale Denotes an issue or PR has remained open with no activity and has become stale. label Feb 28, 2022
@k8s-triage-robot
Copy link

The Kubernetes project currently lacks enough active contributors to adequately respond to all issues and PRs.

This bot triages issues and PRs according to the following rules:

  • After 90d of inactivity, lifecycle/stale is applied
  • After 30d of inactivity since lifecycle/stale was applied, lifecycle/rotten is applied
  • After 30d of inactivity since lifecycle/rotten was applied, the issue is closed

You can:

  • Mark this issue or PR as fresh with /remove-lifecycle rotten
  • Close this issue or PR with /close
  • Offer to help out with Issue Triage

Please send feedback to sig-contributor-experience at kubernetes/community.

/lifecycle rotten

@k8s-ci-robot k8s-ci-robot added lifecycle/rotten Denotes an issue or PR that has aged beyond stale and will be auto-closed. and removed lifecycle/stale Denotes an issue or PR has remained open with no activity and has become stale. labels Mar 30, 2022
@k8s-triage-robot
Copy link

The Kubernetes project currently lacks enough active contributors to adequately respond to all issues and PRs.

This bot triages issues and PRs according to the following rules:

  • After 90d of inactivity, lifecycle/stale is applied
  • After 30d of inactivity since lifecycle/stale was applied, lifecycle/rotten is applied
  • After 30d of inactivity since lifecycle/rotten was applied, the issue is closed

You can:

  • Reopen this issue or PR with /reopen
  • Mark this issue or PR as fresh with /remove-lifecycle rotten
  • Offer to help out with Issue Triage

Please send feedback to sig-contributor-experience at kubernetes/community.

/close

@k8s-ci-robot
Copy link
Contributor

@k8s-triage-robot: Closing this issue.

In response to this:

The Kubernetes project currently lacks enough active contributors to adequately respond to all issues and PRs.

This bot triages issues and PRs according to the following rules:

  • After 90d of inactivity, lifecycle/stale is applied
  • After 30d of inactivity since lifecycle/stale was applied, lifecycle/rotten is applied
  • After 30d of inactivity since lifecycle/rotten was applied, the issue is closed

You can:

  • Reopen this issue or PR with /reopen
  • Mark this issue or PR as fresh with /remove-lifecycle rotten
  • Offer to help out with Issue Triage

Please send feedback to sig-contributor-experience at kubernetes/community.

/close

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help wanted Denotes an issue that needs help from a contributor. Must meet "help wanted" guidelines. kind/bug Categorizes issue or PR as related to a bug. lifecycle/rotten Denotes an issue or PR that has aged beyond stale and will be auto-closed. sig/apps Categorizes an issue or PR as relevant to SIG Apps. sig/storage Categorizes an issue or PR as relevant to SIG Storage.
Projects
None yet