How to remove Kubernetes namespaces stuck in a Terminating state
This document (000021065) is provided subject to the disclaimer at the end of this document.
Environment
Situation
To mitigate a namespace stuck in a terminating state, the following steps should be performed:
1) Check if any apiservice is unavailable.
2) Find all resources that still exist for this namespace and remove the finalizers.
Resolution
Check if any apiservice is unavailable and hence does not serve its resources.
kubectl get apiservice|grep False
2) Find resources and remove finalizers
Find all resources that still exist where "$your-ns-to-delete" is the name of the namespace stuck in a terminating state, and remove any finalizer on those resources that can no longer be met.
kubectl api-resources --verbs=list --namespaced -o name | xargs -n 1 kubectl get -n $your-ns-to-delete
To remove the finalizers, you can use the following patch on the resource.
kubectl -n <namespace> patch <RessourceObject> <Object-name> -p '{"metadata":{"finalizers":null}}' --type=merge
Additional Information
Disclaimer
This Support Knowledgebase provides a valuable tool for SUSE customers and parties interested in our products and solutions to acquire information, ideas and learn from one another. Materials are provided for informational, personal or non-commercial use within your organization and are presented "AS IS" WITHOUT WARRANTY OF ANY KIND.
- Document ID:000021065
- Creation Date: 09-May-2023
- Modified Date:17-Jul-2024
-
- SUSE Rancher
For questions or concerns with the SUSE Knowledgebase please contact: tidfeedback[at]suse.com