Skip to main content

Namespaces

Namespaces provides a mechanism for isolating groups of resources within a single cluster.

  • Names of resources need to be unique within a namespace
  • Namespace-based scoping is applicable only for namespaced objects and not for cluster-wide objects

Namespaces Stuck in Terminatingโ€‹

When deleting a namespace in Kubernetes, the namespace may remain stuck in terminating status.

$ kubectl get ns

NAME STATUS AGE
default Active 2d
kube-public Active 2d
kube-system Active 2d
my-namespace Terminating 7m

Solutionโ€‹

  1. Get the namespace manifest
kubectl get ns my-namespace -o yaml > namespace.yaml 
  1. Edit the manifest file and remove all finalizers
namespace.yaml
apiVersion: v1
kind: Namespace
metadata:
name: my-namespace
spec:
finalizers:
status:
phase: Terminating
  1. Start kubectl proxy
$ kubectl proxy

Starting to serve on 127.0.0.1:8001
  1. Call namespace finalize API:
curl -H "Content-Type: application/yaml" -X PUT --data-binary @namespace.yaml http://127.0.0.1:8001/api/v1/namespaces/my-namespace/finalize 
  1. Confirm if namespace was deleted
$ kubectl get ns

NAME STATUS AGE
default Active 2d
kube-public Active 2d
kube-system Active 2d