Delete Openshift Project

  • Issue, can’t delete a namespace/project and is stuck in a “Terminating” status
oc delete project fishbone

oc get projects fishbone
NAME       DISPLAY NAME   STATUS
fishbone   Fishbone       Terminating

  • Solution
    • Define the namespace/project to delete
    export NAMESPACE=fishbone
    
    
    Cleanup the finalizers section from the namespace definition and define a json file with that
    `shell
     get namespace $NAMESPACE -o=json | jq '.spec = {"finalizers":[]}' > $NAMESPACE.json
    piVersion": "v1",
    ind": "Namespace",
    etadata": {
    nnotations":
    penshift.io/description": "",
    penshift.io/display-name": "Fishbone",
    penshift.io/requester": "system:admin",
    penshift.io/sa.scc.mcs": "s0:c24,c14",
    penshift.io/sa.scc.supplemental-groups": "1000580000/10000",
    penshift.io/sa.scc.uid-range": "1000580000/10000"
    
    reationTimestamp": "2021-02-20T03:29:59Z",
    eletionTimestamp": "2021-02-20T03:31:35Z",
    ame": "fishbone",
    esourceVersion": "270664",
    elfLink": "/api/v1/namespaces/fishbone",
    id": "885c4440-6f05-4e72-a103-28e61705406f"
    
    pec": {
    inalizers": [
    ubernetes"
    
    tatus": {
    onditions": [
    
    hase": "Terminating"
    
    
     Apply the json file from the previous step to delete the finalizers and therefore the deletion of the namespace/project
    `shell
    rl -k -H "authorization: Bearer $(oc whoami --show-token)" -H "Content-Type: application/json" -X PUT --data-binary @$NAMESPACE.json $(oc whoami --show-server)/api/v1/namespaces/$NAMESPACE/finalize
    
    
    Verify that the namspace/project has been deleted
    `shell
     get projects $NAMESPACE
    ror from server (NotFound): namespaces "fishbone" not found
    
    
    

References:

  • Kubernetes Advanced Topics1
  • Kubernetes Namespace Stuck2
  • Red Hat article[^3]
Next