ansble通过脚本定时清理k8s日志
作者:互联网
环境:环境k8s1.17,ansble通过脚本定时清理k8s日志
[root@tidb-21 delete-k8s-logs]# ls
ansib-delete.sh delete-logs.sh
[root@tidb-21 delete-k8s-logs]# more delete-logs.sh #删除日志脚本
#!/bin/bash
for i in `find /var/docker/lib/containers -name *-json.log`;do cat /dev/null > $i;done
[root@tidb-21 delete-k8s-logs]# more ansib-delete.sh #使用ansible下发脚本,并执行脚本
#!/bin/bash
ansible k8s -m copy -a "src=/wj/delete-k8s-logs/delete-logs.sh dest=/tmp/"
ansible k8s -m shell -a 'chmod u+x /tmp/delete-logs.sh && sh /tmp/delete-logs.sh'
echo $(date +"%Y-%m-%d:%T") >> /tmp/delete-k8s-log.txt
[root@tidb-21 delete-k8s-logs]# crontab -l #查看配置定时任务,每周一执行脚本 (设置的话用,crontab -e)
41 8 * * 1 /wj/delete-k8s-logs/ansib-delete.sh
标签:tmp,ansble,logs,sh,tidb,日志,k8s,delete 来源: https://www.cnblogs.com/aozhejin/p/15838898.html