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