-
-
Save h1kkan/56e856207783564fe084c2f30303a739 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# It locates on /etc/systemd/system/ | |
[Unit] | |
Description=Cleaning unnecessary cadvisor system resources. See issue https://github.com/kubernetes/kubernetes/issues/64137. | |
[Service] | |
Slice=cadvisor-gc.slice | |
ExecStart=/opt/cadvisor-gc/cadvisor-gc.sh | |
[Install] | |
WantedBy=multi-user.target |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# It locates on /opt/cadvisor-gc/ | |
count=0 | |
increaseCount() { | |
count=$((count + 1)) | |
} | |
for i in $(ls /sys/fs/cgroup/systemd/system.slice | grep "^run-r"); do | |
pod=$(systemctl list-units --type scope --state running $i | cat | sed -n 's/\(.*\)Kubernetes transient mount for \/var\/lib\/kubelet\/pods\/\(.*\)\/volumes\(.*\)/\2/p') | |
if [ ! -f "/var/lib/kubelet/pods/'$pod'" ]; then | |
echo -n "Try to stop '$i' systemd scope... " | |
systemctl stop $i | |
echo "Stopped." | |
increaseCount | |
fi | |
done | |
echo -e "==========\nTotal ${count} systemd scope stopped." |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# It locates on /etc/systemd/system/ | |
[Unit] | |
Description=Limited resources Slice | |
DefaultDependencies=no | |
Before=slices.target | |
[Slice] | |
CPUQuota=5% | |
MemoryLimit=0.1G |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# It locates on /etc/systemd/system/ | |
[Unit] | |
Description=Run cadvisor-gc every day | |
[Timer] | |
Unit=cadvisor-gc.service | |
OnCalendar=*-*-* 16:00:00 | |
[Install] | |
WantedBy=timers.target |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment