Skip to main content

Delete objects (advanced)

Be careful

This documentation provide guidelines to delete various types of objects in the OpenShift DSRI. Be careful when you are deleting object in your project, as it could be an object required to run an application.

It is recommend to use the oc tool to delete OpenShift objects, as it will allow to properly delete all objects related to specific deployments.

Project

Make sure you are connected to the right project:

oc project my-project

Delete an application

The best way to make sure all objects related to your application have been deleted is to use the command line providing your application name.

Different selectors can be used to easily delete all objects generated by an application deployment. 2 selectors can easily be found in the template configuration:

  • app : the name you gave when creating your application
  • template : the name of the template you used to create the application. Use it only if you want to delete all applications created by a specific template.
oc delete all,secret,configmaps,serviceaccount,rolebinding --selector app=my-application

Delete storage if necessary from the OpenShift web UI.

Force deletion

You can force the deletion if the objects are not deleting properly:

oc delete all,secret,configmaps,serviceaccount,rolebinding --force --grace-period=0 --selector app=my-application

Delete pod

Get the ID of the specific pod you want to delete:

oc get pod

Use the pod ID retrieved to delete the pod:

oc delete pod <POD_ID>
Force deletion

If the pod is not properly deleted, you can force its deletion:

oc delete pod --force --grace-period=0 <POD_ID>

Delete a project

Be careful

All objects and persistent storages in this project will be deleted and cannot be retrieved.

  1. To properly delete a project you need to first delete all objects in this project:
oc delete all,configmap,pvc,serviceaccount,rolebinding,secret,serviceinstance --all -n <PROJECT_ID>
  1. Then delete the project:
oc delete project <PROJECT_ID>

Delete persistent storage

Be careful

All data stored in this persistent storage will be lost and cannot be retrieved.

oc delete pvc storage-name

Fix stuck deletions

Stuck provisioned service

If a provisioned service is stuck on Marked for deletion you might need to set finalizers to null in the YAML.

This can be done using the OpenShift web UI:

  • Go to the Provisionned Service in the OpenShift UI overview

  • Click on Edit YAML

  • Remove the finalizers:

      finalizers:
    - kubernetes-incubator/service-catalog

You can also do it using the oc CLI:

oc get serviceinstance

# Delete problematic line from serviceinstance to delete them
oc get serviceinstance -o yaml | grep Terminating | sed "/kubernetes-incubator/d"| oc apply -f -
No global catalog

The OpenShift Catalog does not handle deploying templates globally properly (on all projects). If a template is deployed globally, OpenShift will try to create unnecessary objects such as provisioned service (aka. ServiceInstance), or ClusterClasses. Those services are not used, and some of them cannot be deleted easily.

Catalog per project

At the moment it is more reliable to create the template in directly in your project if you need to use it multiple time.

Delete stuck project

Project can get stuck as marked for deletion. Usually due to Objects still present in the project that are not terminated or finalizers left in the some objects YAML file.

The following commands will allow you to clean up all the projects stuck in terminating state you have access to .

Force deletion of terminating projects:

for i in $(oc get projects  | grep Terminating| awk '{print $1}'); do echo $i; oc delete project --force --grace-period=0 $i ; done

Delete all objects in terminating projects:

for i in $(oc get projects  | grep Terminating| awk '{print $1}'); do echo $i; oc delete all,configmap,pvc,serviceaccount,rolebinding,secret,serviceinstance --force --grace-period=0 --all -n $i ; done

Remove Kubernetes finalizers from terminating projects:

for i in $(oc get projects  | grep Terminating| awk '{print $1}'); do echo $i; oc get project $i -o yaml | sed "/kubernetes/d" | sed "/finalizers:/d" | oc apply -f - ; done
Fix deletion

If ServiceInstances refuses to get deleted, try to remove kubernetes finalizers:

for i in $(oc get projects  | grep Terminating| awk '{print $1}'); do echo $i; oc get serviceinstance -n $i -o yaml | sed "/kubernetes-incubator/d"| oc apply -f - ; done
Check deletion

Check if there are still objects in a project:

oc get all,configmap,pvc,serviceaccount,secret,rolebinding,serviceinstance