Search code examples
google-cloud-platformload-balancinggcloudresource-cleanup

how to delete load balancer using gcloud command?


Deleting load balancer from console is easy. Just click on delete icon and wait for the load balancer to disappear.

Is there similar gcloud command to delete load balancer (cascade delete all related frontend, backend, url-map, health check etc. )?

GCP Documents explain how to setup various load balancers but none of them cover how to clean up


Solution

  • There is no single gcloud command to wipe out a loadbalancer. You'll need to delete its constituent parts, one at a time.

    These parts are:

    Backend
    gcloud compute backend-services delete [BACKEND_SERVICE]
    
    Target Proxy
    gcloud compute target-${PROTOCOL}-proxies delete [TARGET_PROXY]
    
    Forwarding Rules (Frontend)
    gcloud compute forwarding-rules delete [FORWARDING_RULE]
    
    Static IP addresses
    gcloud compute addresses delete [IP_ADDRESS]
    
    Health Checks
    gcloud compute health-checks delete [HEALTH_CHECK]
    
    URL Maps
    gcloud compute url-maps delete [URL_MAP]
    

    Depending on your needs, you may or may not want to actually delete your static IPs and health checks, or even have any URL maps to delete.