to remove a deployment and check associated components - unix1998/technical_notes GitHub Wiki

When want to fully remove a deployment from an OpenShift cluster, we need to remove several components explicitly. Simply removing the deployment does not automatically remove all associated resources such as services, routes, and persistent volume claims. Here's a comprehensive guide to ensure all related components are removed:

Components to Remove

  1. Deployment
  2. Pods (associated with the deployment)
  3. Services
  4. Routes
  5. ConfigMaps
  6. Secrets
  7. PersistentVolumeClaims (PVCs) (if any)
  8. Ingress (if any)
  9. Other related resources

Step-by-Step Guide

  1. Remove the Deployment:

    oc delete deployment <deployment-name>

    This will remove the deployment and all associated pods. Note that removing a pod directly would typically trigger a new pod to be created by the deployment controller. By deleting the deployment, you prevent the recreation of the pods.

  2. Remove the Services:

    oc delete svc <service-name>

    If you want to delete all services associated with the deployment, you can list them and delete them. For example:

    oc get svc -l app=<app-label>
    oc delete svc -l app=<app-label>
  3. Remove the Routes:

    oc delete route <route-name>

    Similarly, to delete all routes associated with the deployment:

    oc get routes -l app=<app-label>
    oc delete route -l app=<app-label>
  4. Remove ConfigMaps and Secrets:

    oc delete configmap <configmap-name>
    oc delete secret <secret-name>

    To delete all configmaps and secrets associated with the deployment:

    oc get configmap -l app=<app-label>
    oc delete configmap -l app=<app-label>
    oc get secret -l app=<app-label>
    oc delete secret -l app=<app-label>
  5. Remove PersistentVolumeClaims (PVCs): If your deployment uses PVCs, you'll need to remove those as well:

    oc delete pvc <pvc-name>

    To delete all PVCs associated with the deployment:

    oc get pvc -l app=<app-label>
    oc delete pvc -l app=<app-label>
  6. Remove Ingress (if any):

    oc delete ingress <ingress-name>

    To delete all ingress resources associated with the deployment:

    oc get ingress -l app=<app-label>
    oc delete ingress -l app=<app-label>

Example

Assuming your deployment, service, route, and other components have a common label app=myapp, you can remove all associated resources with the following commands:

  1. Delete the Deployment:

    oc delete deployment myapp
  2. Delete Services:

    oc delete svc -l app=myapp
  3. Delete Routes:

    oc delete route -l app=myapp
  4. Delete ConfigMaps:

    oc delete configmap -l app=myapp
  5. Delete Secrets:

    oc delete secret -l app=myapp
  6. Delete PVCs:

    oc delete pvc -l app=myapp
  7. Delete Ingress (if any):

    oc delete ingress -l app=myapp

By executing these commands, you ensure that all components related to your deployment are fully removed from the OpenShift cluster.

⚠️ **GitHub.com Fallback** ⚠️