cleanup-old-replicasets.sh 513 B

12345678910111213
  1. #!/bin/bash
  2. # cleanup-old-replicasets.sh
  3. # 定期删除没有running pod的ReplicaSet和Deployment
  4. # 删除所有没有running pod的ReplicaSet
  5. echo "Cleaning up old ReplicaSets..."
  6. kubectl delete rs --field-selector=status.replicas=0 -n default
  7. # 删除所有没有running pod的Deployment
  8. echo "Cleaning up orphaned Deployments..."
  9. kubectl get deployment -n default -o jsonpath='{.items[?(@.spec.replicas==0)].metadata.name}' | xargs -I {} kubectl delete deployment {} -n default
  10. echo "Cleanup completed!"