This is a small utility to aid in cleaning up unused disks in a GKE environment.
Usage:
gke-disk-cleanup [command]
Available Commands:
cleanup cleanup disks in gcloud
help Help about any command
mark mark disks for later deletion
Flags:
--dry-run only log the actions that would be taken (default true)
-h, --help help for gke-disk-cleanup
--project-id string google project id (default "default")
--verbose verbose output
--zone string google compute zone (default "us-east1-a")gke-disk-cleanup operates in two phases:
In the mark phase, disks in the specified project and zone are marked with a label marked-for-deletion:true based on their last attached timestamp.
If the label marked-for-deletion:true is already present and the disk was attached within the specified cutoff period, the label value is updated to marked-for-deletion:false.
If the label marked-for-deletion is present with any value other than true, no further action will be taken.
Note: by default:
- Disks that have not been attached in the last 30 days will be marked. This is configurable with the
--cutoffparameter. - Only disks with the label
goog-gke-volumeare considered. To change this, use the--filterargument. See the gcloud documentation for more information on this topic. - Nothing will happen unless you explicitly pass the option
--dry-run=false.
In the cleanup phase, disks in the project and zone with the label marked-for-deletion:true will be snapshotted and deleted. Snapshot creation can be suppressed with the option --do-snapshot=false.
Note: by default, the cleanup command will do nothing unless you pass the option --dry-run=false.
- Ensure you have application default credentials available:
gcloud auth application-default login - Ensure you have
goinstalled. - Clone the git repository, navigate to it, and run
make build. - Run
./gke-disk-cleanup --helpto see the available options.