Questa pagina mostra come risolvere i problemi relativi a uno spazio dei nomi bloccato nello stato
Terminating.
Gli spazi dei nomi utilizzano i finalizer di Kubernetes
per impedire l'eliminazione se esistono ancora una o più risorse all'interno di uno spazio dei nomi.
Quando elimini uno spazio dei nomi utilizzando il comando kubectl delete, lo spazio dei nomi
entra nello stato Terminating.
Lo spazio dei nomi rimane nello stato Terminating finché Kubernetes non elimina le risorse dipendenti e non cancella tutti i finalizzatori. Il controller del ciclo di vita dello spazio dei nomi elenca innanzitutto tutte le risorse nello spazio dei nomi che GKE deve eliminare.
Se GKE non riesce a eliminare una risorsa dipendente
o se il controller del ciclo di vita dello spazio dei nomi non riesce a verificare che lo spazio dei nomi sia vuoto, lo spazio dei nomi
rimane nello stato Terminating finché non risolvi il problema.
Per risolvere un problema con uno spazio dei nomi bloccato nello stato Terminating, identifica
e rimuovi tutti i componenti non integri che bloccano l'eliminazione. Prova queste soluzioni
in ordine:
Controlla se lo stato dello spazio dei nomi è ancora Terminating:
kubectlgetns|grepTerminating
Passaggi successivi
Se non riesci a trovare una soluzione al tuo problema nella documentazione, consulta la sezione
Richiedere assistenza per ulteriore aiuto,
inclusi consigli sui seguenti argomenti:
Ricevere assistenza dalla community
ponendo domande su StackOverflow e utilizzando il tag google-kubernetes-engine per cercare problemi simili. Puoi anche unirti al
canale Slack #kubernetes-engine
per ulteriore assistenza della community.
[[["Facile da capire","easyToUnderstand","thumb-up"],["Il problema è stato risolto","solvedMyProblem","thumb-up"],["Altra","otherUp","thumb-up"]],[["Difficile da capire","hardToUnderstand","thumb-down"],["Informazioni o codice di esempio errati","incorrectInformationOrSampleCode","thumb-down"],["Mancano le informazioni o gli esempi di cui ho bisogno","missingTheInformationSamplesINeed","thumb-down"],["Problema di traduzione","translationIssue","thumb-down"],["Altra","otherDown","thumb-down"]],["Ultimo aggiornamento 2025-09-04 UTC."],[],[],null,["# Troubleshoot namespace stuck in the Terminating state\n\n[Autopilot](/kubernetes-engine/docs/concepts/autopilot-overview) [Standard](/kubernetes-engine/docs/concepts/choose-cluster-mode)\n\n*** ** * ** ***\n\nThis page shows you how to resolve issues with a namespace stuck in the\n`Terminating` state.\n\nNamespaces use Kubernetes [finalizers](https://kubernetes.io/docs/tasks/extend-kubernetes/custom-resources/custom-resource-definitions/#finalizers)\nto prevent deletion if one or more resources within a namespace still exist.\nWhen you delete a namespace using the `kubectl delete` command, the namespace\nenters the `Terminating` state.\nThe namespace stays in the `Terminating` state\nuntil Kubernetes deletes its dependent resources\nand clears all finalizers. The namespace lifecycle controller first lists all\nresources in the namespace that GKE needs to delete.\n\nIf GKE can't delete a dependent resource,\nor if the namespace\nlifecycle controller can't verify that the namespace is empty, then the namespace\nremains in the `Terminating` state until you resolve the issue.\n\nTo resolve a namespace stuck in the `Terminating` state, identify\nand remove any unhealthy components blocking the deletion. Try these solutions\nin order:\n\n1. [Find and remove unavailable API services](#unavailable-api-services).\n2. [Find and remove remaining resources](#remove_resource).\n3. [Force delete the namespace](#force-delete-namespace).\n\nFind and remove unavailable API services\n----------------------------------------\n\n1. List unavailable API services:\n\n kubectl get apiservice | grep False\n\n2. Troubleshoot any unresponsive services:\n\n kubectl describe apiservice \u003cvar translate=\"no\"\u003eAPI_SERVICE\u003c/var\u003e\n\n Replace \u003cvar translate=\"no\"\u003eAPI_SERVICE\u003c/var\u003e with the name of the unresponsive\n service.\n3. Check if the status of the namespace is still `Terminating`:\n\n kubectl get ns | grep Terminating\n\nFind and remove remaining resources\n-----------------------------------\n\n1. List all the resources remaining in the terminating namespace:\n\n kubectl api-resources --verbs=list --namespaced -o name | xargs -n 1 kubectl get -n \u003cvar translate=\"no\"\u003eNAMESPACE\u003c/var\u003e\n\n Replace \u003cvar translate=\"no\"\u003eNAMESPACE\u003c/var\u003e with the name of the namespace you\n want to delete.\n2. Remove any resources displayed in the output.\n\n3. Check if the status of the namespace is still `Terminating`:\n\n kubectl get ns | grep Terminating\n\nForce delete the namespace\n--------------------------\n\n| **Caution:** Use the solution in this section only as a last resort if the previous solutions don't work. Force deleting a namespace could result in resources remaining in your cluster that you can't access.\n\nRemove the finalizers blocking namespace deletion to force the namespace\nto terminate:\n\n1. Save the namespace manifest as a YAML file:\n\n kubectl get ns \u003cvar translate=\"no\"\u003eNAMESPACE\u003c/var\u003e -o yaml \u003e ns-terminating.yml\n\n2. Open the manifest in a text editor and remove all values in the\n `spec.finalizers` field:\n\n vi ns-terminating.yml\n\n3. Verify that the finalizers field is empty:\n\n cat ns-terminating.yml\n\n The output should look similar to the following: \n\n apiVersion: v1\n kind: Namespace\n metadata:\n annotations:\n name: \u003cvar translate=\"no\"\u003e\u003cspan class=\"devsite-syntax-l devsite-syntax-l-Scalar devsite-syntax-l-Scalar-Plain\"\u003eNAMESPACE\u003c/span\u003e\u003c/var\u003e\n spec:\n finalizers:\n status:\n phase: Terminating\n\n4. Start an HTTP proxy to access the Kubernetes API:\n\n kubectl proxy\n\n5. Replace the namespace manifest using `curl`:\n\n curl -H \"Content-Type: application/yaml\" -X PUT --data-binary @ns-terminating.yml http://127.0.0.1:8001/api/v1/namespaces/\u003cvar translate=\"no\"\u003eNAMESPACE\u003c/var\u003e/finalize\n\n6. Check if the status of the namespace is still `Terminating`:\n\n kubectl get ns | grep Terminating\n\nWhat's next\n-----------\n\n- If you can't find a solution to your problem in the documentation, see\n [Get support](/kubernetes-engine/docs/getting-support) for further help,\n including advice on the following topics:\n\n - Opening a support case by contacting [Cloud Customer Care](/support-hub).\n - Getting support from the community by [asking questions on StackOverflow](http://stackoverflow.com/questions/tagged/google-kubernetes-engine) and using the `google-kubernetes-engine` tag to search for similar issues. You can also join the [`#kubernetes-engine` Slack channel](https://googlecloud-community.slack.com/messages/C0B9GKTKJ/) for more community support.\n - Opening bugs or feature requests by using the [public issue tracker](/support/docs/issue-trackers)."]]