Skip to content

Instantly share code, notes, and snippets.

@r10r
Last active February 3, 2021 20:09
Show Gist options
  • Save r10r/72ce519944796d62eef837d0e3e6f23a to your computer and use it in GitHub Desktop.
Save r10r/72ce519944796d62eef837d0e3e6f23a to your computer and use it in GitHub Desktop.
crio-lxc-tools
#!/bin/sh
echo "[truncate runtime logfiles]"
rm -rf /var/log/crio-lxc/*
touch /var/log/crio-lxc/crio-lxc.log
echo > /var/log/calico/cni/cni.log
dmesg -C
echo "------------------"
echo
echo "[vaccum systemd journal]"
journalctl --rotate
journalctl --vacuum-time=1s
echo "------------------"
#find /sys/fs/cgroup/kubepods.slice/ -type d | sort -r | xargs rmdir
#!/bin/sh
# turn arguments into environment variables
# this works fine over SSH
for arg in $@; do export $arg; done
OUT="${OUT:-$(date --utc +%m.%d_%H.%M.%S)}"
mkdir $OUT
cd $OUT
add_file() {
cp -v $1 ${2:-.} >>log.txt 2>&1
}
# system state
add_file /proc/mounts
dmesg >dmesg.txt 2>&1
iptables-save >iptables.save 2>&1
add_file /etc/hosts
# TODO set audit
# auditd logs ?
# crio-lxc runtime state
add_file /etc/default/crio-lxc crio-lxc.env
# current runtime state and logs are merged into a single directory
tar -cf crio-lxc.tar --exclude syncfifo -C /run crio-lxc >>log.txt 2>&1
tar -rf crio-lxc.tar --exclude syncfifo -C /var/log crio-lxc >> log.txt 2>&1
# cri-o runtime state
journalctl --utc -u crio -a >crio.service.log 2>&1
add_file /etc/crio/crio.conf
tar -cf pods.tar -C /var/log pods >>log.txt 2>&1
ls -l /run/crio >crio.run.txt 2>&1
crictl ps -a > crio.containers.txt
crictl images > crictl.images.txt
# CNI logs
add_file /var/log/calico/cni/cni.log
journalctl --utc -u kubelet -a >kubelet.service.log 2>&1
kubectl get all -o json -A >kubectl.all 2>&1
kubectl get all -A -o wide >kubectl.txt 2>&1
for f in $(find /sys/fs/cgroup -name cgroup.procs -o -name cgroup.subtree_control); do
echo "$f $(cat $f | xargs)" >> cgroups.txt 2>&1
done
pacman -Qe > pacman.txt 2>&1
/bin/sh >misc.txt 2>&1 <<EOF
hostnamectl
uptime --pretty
EOF
/bin/sh >versions.txt 2>&1 <<EOF
echo
crio-lxc --version
echo
crio --version
echo
conmon --version
echo
echo "liblxc $(cat /usr/local/lib/liblxc.version.txt)"
EOF
sonobuoy retrieve >>log.txt 2>&1
pwd
#!/bin/sh
kubeadm reset --force
#rm -rf /etc/kubernetes/manifests/
#crictl rm -a
#crictl rmp -a
systemctl stop kubelet
systemctl stop crio
echo
echo "[removing kubelet configuration]"
rm -v /root/.kube/config
rm -v /etc/cni/net.d/calico-kubeconfig
echo "------------------"
echo
# Warn if crio runtime directory contains any container references.
# this usually indicates to a problem with crio-lxc not deleting containers properly
echo "[removing runtime state]"
rm -v -rf /run/crio/*
rm -v -rf /run/crio-lxc
echo "------------------"
echo
echo "[removing container logs]"
rm -rf /var/log/containers
rm -rf /var/log/pods
$(dirname $(readlink -f $0))/clear-logs.sh
systemctl start crio
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment