清理 Evicted 的 pod
kubectl get pod -o wide --all-namespaces | awk '{if($4=="Evicted"){cmd="kubectl -n "$1" delete pod "$2; system(cmd)}}'
清理 Completed 的 Pod
kubectl get pod -o wide --all-namespaces | awk '{if($4=="Completed"){cmd="kubectl -n "$1" delete pod "$2; system(cmd)}}'
清理 Error 的 Pod
kubectl get pod -o wide --all-namespaces | awk '{if($4=="Error"){cmd="kubectl -n "$1" delete pod "$2; system(cmd)}}'
清理 Terminating 的 Pod
kubectl get pod -o wide --all-namespaces | awk '{if($4=="Terminating"){cmd="kubectl -n "$1" delete pod "$2; system(cmd)}}'
清理非 Running 的 pod
kubectl get pod -o wide --all-namespaces | awk '{if($4!="Running"){cmd="kubectl -n "$1" delete pod "$2; system(cmd)}}'
升级镜像
NAMESPACE="kube-system"WORKLOAD_TYPE="daemonset"WORKLOAD_NAME="ip-masq-agent"CONTAINER_NAME="ip-masq-agent"IMAGE="ccr.ccs.tencentyun.com/library/ip-masq-agent:v2.5.0"
kubectl -n $NAMESPACE patch $WORKLOAD_TYPE $WORKLOAD_NAME --patch '{"spec": {"template": {"spec": {"containers": [{"name": "$CONTAINER_NAME","image": "$IMAGE" }]}}}}'