Delete Pod which struck with Terminating State:
Apply –grace-period=0 –force
oc delete pod pod-name-1-deploy -n myproject –grace-period=0 –force
warning: Immediate deletion does not wait for confirmation that the running resource has been terminated. The resource may continue to run on the cluster indefinitely.
pod “jenkins-1-deploy” deleted
Delete Project which struck with Terminating State:
oc get namespace
oc get -o yaml namespace/project
However, if you try to edit and save the file directly with the oc edit namespace/PROJECT command, your finalizer is not updated.
oc get namespace DELETABLE_PROJECT -o yaml > BACKUP_NAMESPACE.yaml
Remove the value under finalizers, and that is all there is to it. In the screenshot below, I deleted the line (line 19), where it says - kubernetes.
oc proxy &
curl -k -H "Content-Type: application/yaml" -X PUT --data-binary @BACKUP_NAMESPACE.yaml http://127.0.0.1:8001/api/v1/namespaces/DELETABLE_PROJECT/finalize
oc get namespace DELETABLE_PROJECT
oc kill -9 %
Reference: https://www.redhat.com/sysadmin/openshift-terminating-state
Further Notes:
When a pod or project is stuck in a terminating state in OpenShift v4, it can be a challenging situation. Here are some steps you can try to force delete a stuck pod and project:
Deleting a Stuck Pod:
Identify the Pod:
Identify the name of the stuck pod using the following command:
oc get pods
Force Deletion:
Try to force delete the pod using the following command:
oc delete pod –grace-period=0 –force
This command forces deletion of the pod immediately, bypassing the grace period. If the pod is still not deleting, move on to the next steps.
Check Events:
Check the events related to the pod to understand any errors or issues:
oc describe pod
Scale Down Deployment:
If the pod is part of a deployment, scale down the deployment to zero replicas:
oc scale deployment –replicas=0
Delete Replication Controller:
If the pod is part of a Replication Controller, delete the Replication Controller:
oc delete rc
Deleting a Stuck Project:
Identify Project:
Identify the name of the stuck project:
oc get projects
Force Delete Project:
Try to force delete the project using the following command:
oc delete project –grace-period=0 –force
If the project is still not deleting, you can try the following steps:
Check Project Status:
Check the status of the project to see if there are any ongoing activities or issues:
oc get project -o yaml
Delete Objects within Project:
Delete objects within the project one by one, starting with deployments, services, routes, etc. Use the oc
delete command for each object type.
Force Delete Remaining Objects:
If some objects are not deleting, try to force delete them:
oc delete –grace-period=0 –force –namespace=
Check and Retry:
After deleting objects, check the project status and try to delete the project again.
Manual Cleanup:
If all else fails, you may need to manually clean up resources in the cluster related to the project. Be cautious when doing this, and make sure to back up any important data.
Remember to replace , , , , , and with the actual names in your environment. Additionally, exercise caution when using force delete options, as it may lead to data loss or other issues.
Leave a Reply