shell - 删除k8s宿主机历史日志

2021-07-05
#!/bin/bash
namespaces='pr pro'
for namespace in ${namespaces}
do
    temp_shell="/tmp/delete-invalid-pod.sh"
    cat /dev/null > ${temp_shell}
    /usr/local/bin/kubectl --kubeconfig /root/.kube/all-config/${namespace} -n ${namespace} get replicasets.apps|grep ws- | grep '0         0         0' | awk '{print $1}' | while read line
    do
        wsappid=`echo $line |awk -F'-' '{print $1"-"$2}'`
        echo rm -rf /opt/web/${namespace}/${wsappid}/${line}* >> ${temp_shell}
    done

    /usr/local/bin/kubectl --kubeconfig /root/.kube/all-config/${namespace} get node -o wide |grep Ready |grep -v master |awk '{print $6}' |while read host
    do
        scp -r ${temp_shell} root@${host}:/tmp/
        ssh -n -o stricthostkeychecking=no root@${host} "bash ${temp_shell}"
    done
done

标题:shell - 删除k8s宿主机历史日志
地址:https://blog.njqhome.com:8443/articles/2021/07/05/1625473371270.html