Skip to content

Pod created by a Job is now stuck in Completed state in EKS

0

We have a pod in our EKS which we cannot delete.

The pod has a finalizer preventing it to be removed, editing the pod trying to remove the finalizer fails with an error:

# pods "..." was not valid:
# * spec: Forbidden: pod updates may not change fields other than `spec.containers[*].image`,`spec.initContainers[*].image`,`spec.activeDeadlineSeconds`,`spec.tolerations` (only additions to existing tolerations),`spec.terminationGracePeriodSeconds` (allow it to be set to 1 if it was previously negative)

The pod has ownerReference pointing to a Job which doesn't exist anymore, if it changes anything.

Current version of EKS is 1.31, but the Pod was created 190 days ago when we were on earlier version (likely 1.27).

Removing the finalizers with a patch, force deleting the pod with 0 grace period - nothing does the job.

Any advice on how to remove it?

asked 2 years ago872 views

2 Answers
2
Accepted Answer

The problem was with kyverno-resource-mutating-webhook-cfg and its policy — https://kyverno.io/policies/other/add-emptydir-sizelimit/add-emptydir-sizelimit/

the policy was mutating the spec every time I tried to remove the finalizer and the request was failing deleting the policy & patching the pod to remove finalizer worked, the pod is now deleted

answered 2 years ago

EXPERT

reviewed 2 years ago

1

This is a challenging situation with a pod stuck in a Completed state that cannot be deleted. Here are some steps you can try to resolve this issue:

  1. Force deletion with kubectl: Try using the kubectl force delete command with a grace period of 0 seconds: kubectl delete pod <pod-name> --grace-period=0 --force

    If this doesn't work, it's likely due to the finalizer preventing deletion.

  2. Patch to remove finalizers: Attempt to remove the finalizers using a JSON patch: kubectl patch pod <pod-name> -p '{"metadata":{"finalizers":null}}' --type=merge

    If this fails, it's probably because of the API server rejecting changes to the pod spec.

  3. Use the API server directly: As a more advanced option, you can try to delete the pod by directly accessing the API server, bypassing some of the normal kubectl validations: kubectl proxy Then in another terminal: curl -X DELETE localhost:8001/api/v1/namespaces/<namespace>/pods/<pod-name> -d '{"gracePeriodSeconds":0,"propagationPolicy":"Background"}' -H "Content-Type: application/json"

  4. Check for stuck resources: Investigate if there are any other stuck resources related to this pod or its parent Job. Look for any lingering Job objects, PersistentVolumeClaims, or other resources that might be preventing the pod from being cleaned up.

  5. Node issues: If the pod is stuck on a particular node, there might be an issue with that node. Try cordoning the node and draining it to see if that helps resolve the issue.

  6. Cluster-wide check: Run a cluster-wide check for any stuck resources or issues that might be preventing normal cleanup operations.

  7. EKS version upgrade: Since the pod was created on an earlier version of EKS, consider upgrading your cluster to the latest version if you haven't already. Sometimes, version upgrades can resolve issues with stuck resources.

  8. AWS support: If none of these methods work, you may need to contact AWS support for further assistance. They might be able to help resolve the issue at the cluster level.

Remember to be cautious when force deleting resources, as it can potentially lead to inconsistencies in the cluster state. Always ensure you have recent backups before attempting these operations.
Sources
Unable to delete a kubernetes cluster - 1 pods are unevictable | AWS re:Post
Load Balancing - Amazon EKS
Manually quarantine, replace, or reboot a node - Amazon SageMaker

answered 2 years ago

EXPERT

reviewed 2 years ago

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.