Created
          April 15, 2016 23:42 
        
      - 
      
- 
        Save tcotav/5e66d10566df1103309162d51b784d64 to your computer and use it in GitHub Desktop. 
    Script to clean up a kubernetes dev compute environment in GCE
  
        
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | #!/bin/bash | |
| # we run this at night via cron so our instances don't run for no reason overnight | |
| # we then spin 'em back up in the morning via another script | |
| MATCH="jf" # pattern in all your compute nodes so you can easily match later | |
| ZONE="us-central1-f" | |
| # set this to where ever you installed g cloud sdk | |
| GCLOUD=$HOME/google-cloud-sdk/bin/gcloud | |
| for i in $(${GCLOUD} compute instances list | grep ${MATCH} | cut -d " " -f 1);do | |
| # gcloud compute instances stop $i | |
| $GCLOUD compute instances delete $i --zone $ZONE -q | |
| done | |
| # this one is a bit sketchy as you'd kill all routes -- not just a zone... so know | |
| # your config and environment. It works for me :D | |
| for i in $(${GCLOUD} compute routes list | grep ${MATCH} | cut -d " " -f 1);do | |
| # gcloud compute instances stop $i | |
| $GCLOUD compute routes delete $i -q | |
| done | 
  
    Sign up for free
    to join this conversation on GitHub.
    Already have an account?
    Sign in to comment