feat: add Pimox worker disk diagnostics
This commit is contained in:
parent
e7f4ff8fa9
commit
219f5eda0f
2
jeannie
2
jeannie
|
|
@ -78,7 +78,7 @@ Cluster Lifecycle
|
|||
stop-cluster Stop Kubernetes and worker VMs without destroy.
|
||||
start-cluster Start Kubernetes and desired worker VMs.
|
||||
cleanup-debian-k8s Remove old Debian kubeadm runtime after Pimox offload.
|
||||
workers <list|tailnet|start|stop|restart|drain|uncordon|recreate-plan|rebalance>
|
||||
workers <list|tailnet|start|stop|restart|drain|uncordon|recreate-plan|rebalance|disk-status|disk-cleanup>
|
||||
Manage Pimox/Kubernetes workers.
|
||||
move-prometheus-stack-workers Move monitoring workloads to worker nodes.
|
||||
doctor-versions [--all|--details|--verbose|--json]
|
||||
|
|
|
|||
107
scripts/workers
107
scripts/workers
|
|
@ -26,6 +26,9 @@ Commands:
|
|||
uncordon <node> Mark a Kubernetes worker node schedulable
|
||||
recreate-plan [index|all] Print the safe recreate sequence for Pimox worker(s)
|
||||
rebalance Restart evicted/pending pods and show scheduling pressure
|
||||
disk-status [index|all] Read-only filesystem and container-runtime pressure report
|
||||
disk-cleanup [index|all] [--yes]
|
||||
Prune unused images and old pod logs on selected worker(s)
|
||||
EOF
|
||||
}
|
||||
|
||||
|
|
@ -76,9 +79,21 @@ kubectl_cmd() {
|
|||
target_indexes() {
|
||||
local target="${1:-all}"
|
||||
local index
|
||||
local count="${WORKER_COUNT}"
|
||||
local spec_file="${REPO_ROOT}/.lab/pimox-workers.tsv"
|
||||
|
||||
if [ "${target}" = "all" ] && [ -s "${spec_file}" ]; then
|
||||
count="$(awk -F'\t' '
|
||||
$1 ~ /[0-9]+$/ { value = $1; sub(/^[^0-9]*/, "", value); if ((value + 0) > max) max = value + 0 }
|
||||
END { print max + 0 }
|
||||
' "${spec_file}")"
|
||||
if ! [[ "${count}" =~ ^[0-9]+$ ]] || [ "${count}" -lt "${WORKER_COUNT}" ]; then
|
||||
count="${WORKER_COUNT}"
|
||||
fi
|
||||
fi
|
||||
|
||||
if [ "$target" = "all" ]; then
|
||||
for ((index = 1; index <= WORKER_COUNT; index++)); do
|
||||
for ((index = 1; index <= count; index++)); do
|
||||
if ! is_skipped "$index"; then
|
||||
echo "$index"
|
||||
fi
|
||||
|
|
@ -237,6 +252,90 @@ rebalance() {
|
|||
echo "Restarting pending/failed pods is intentionally manual. Use kubectl delete pod for specific pods after checking events."
|
||||
}
|
||||
|
||||
worker_entry() {
|
||||
local index="$1"
|
||||
local spec_file="${REPO_ROOT}/.lab/pimox-workers.tsv"
|
||||
local static_ips=(192.168.100.66 192.168.100.67 192.168.100.76)
|
||||
local host user key node
|
||||
|
||||
validate_index "${index}"
|
||||
if [[ -s "${spec_file}" ]]; then
|
||||
if awk -F'\t' -v wanted="${index}" '
|
||||
$1 ~ /[0-9]+$/ {
|
||||
value = $1
|
||||
sub(/^[^0-9]*/, "", value)
|
||||
if (value == wanted) { print $2 "\t" $3 "\t" $5 "\t" $4; found = 1; exit }
|
||||
}
|
||||
END { exit(found ? 0 : 1) }
|
||||
' "${spec_file}"; then
|
||||
return 0
|
||||
fi
|
||||
fi
|
||||
host="${static_ips[$((index - 1))]:-}"
|
||||
if [[ -z "${host}" ]]; then
|
||||
echo "No connection details found for worker index ${index}; set LAB_PIMOX_WORKER_STATIC_IPS or generate .lab/pimox-workers.tsv." >&2
|
||||
return 1
|
||||
fi
|
||||
user="${LAB_PIMOX_WORKER_USER:-jv}"
|
||||
key="${LAB_PIMOX_WORKER_SSH_KEY_PATH:-${HOME}/.ssh/id_ed25519}"
|
||||
node="$(node_for_index "${index}")"
|
||||
printf '%s\t%s\t%s\t%s\n' "${host}" "${user}" "${key}" "${node}"
|
||||
}
|
||||
|
||||
disk_status() {
|
||||
local target="${1:-all}"
|
||||
local index host user key node
|
||||
|
||||
for index in $(target_indexes "${target}"); do
|
||||
IFS=$'\t' read -r host user key node < <(worker_entry "${index}")
|
||||
echo "===== worker ${index} (${node}, ${host}) ====="
|
||||
ssh -i "${key}" -o BatchMode=yes -o ConnectTimeout=10 -o StrictHostKeyChecking=accept-new "${user}@${host}" 'bash -s' <<'REMOTE'
|
||||
set +e
|
||||
echo "-- filesystem"
|
||||
df -hP / /var/lib/containerd /var/lib/kubelet /var/log 2>/dev/null || true
|
||||
echo "-- container runtime image filesystem"
|
||||
sudo crictl imagefsinfo 2>/dev/null || true
|
||||
echo "-- runtime services"
|
||||
systemctl is-active containerd 2>/dev/null || true
|
||||
systemctl is-active kubelet 2>/dev/null || true
|
||||
echo "-- largest relevant paths"
|
||||
sudo du -xhd1 /var/lib/containerd /var/lib/kubelet /var/log/pods /var/log/containers 2>/dev/null | sort -h | tail -n 20 || true
|
||||
echo "-- node pressure"
|
||||
sudo journalctl -u kubelet --since '24 hours ago' --no-pager 2>/dev/null | grep -Ei 'DiskPressure|evict|imagegc|freedisk|no space|threshold' | tail -n 30 || true
|
||||
REMOTE
|
||||
done
|
||||
}
|
||||
|
||||
disk_cleanup() {
|
||||
local target="${1:-all}"
|
||||
local confirm="${2:-}"
|
||||
local index host user key node
|
||||
|
||||
if [[ "${target}" == "--yes" ]]; then
|
||||
target="all"
|
||||
confirm="--yes"
|
||||
fi
|
||||
if [[ "${confirm}" != "--yes" ]]; then
|
||||
echo "Dry run: no worker files or images were changed."
|
||||
disk_status "${target}"
|
||||
echo "Re-run with workers disk-cleanup ${target} --yes to prune unused images and pod logs older than 3 days."
|
||||
return 0
|
||||
fi
|
||||
for index in $(target_indexes "${target}"); do
|
||||
IFS=$'\t' read -r host user key node < <(worker_entry "${index}")
|
||||
echo "===== cleaning worker ${index} (${node}, ${host}) ====="
|
||||
ssh -i "${key}" -o BatchMode=yes -o ConnectTimeout=10 -o StrictHostKeyChecking=accept-new "${user}@${host}" 'bash -s' <<'REMOTE'
|
||||
set -u
|
||||
echo "-- pruning unused container images"
|
||||
sudo crictl rmi --prune 2>&1 || true
|
||||
echo "-- deleting pod/container logs older than 3 days"
|
||||
sudo find /var/log/pods /var/log/containers -xdev -type f -mtime +3 -print -delete 2>/dev/null || true
|
||||
echo "-- filesystem after cleanup"
|
||||
df -hP / /var/lib/containerd /var/lib/kubelet /var/log 2>/dev/null || true
|
||||
REMOTE
|
||||
done
|
||||
}
|
||||
|
||||
tailnet_setup() {
|
||||
local var_file="${LAB_CLUSTER_VAR_FILE:-${REPO_ROOT}/.lab/cluster-workers.auto.tfvars.json}"
|
||||
local auth_key_file="${LAB_PIMOX_WORKER_TAILSCALE_AUTH_KEY_FILE:-${HOME}/.config/homelab/tailscale-pimox-worker.authkey}"
|
||||
|
|
@ -325,6 +424,12 @@ case "${1:-}" in
|
|||
rebalance)
|
||||
rebalance
|
||||
;;
|
||||
disk-status)
|
||||
disk_status "${2:-all}"
|
||||
;;
|
||||
disk-cleanup)
|
||||
disk_cleanup "${2:-all}" "${3:-}"
|
||||
;;
|
||||
-h|--help|help|"")
|
||||
usage
|
||||
;;
|
||||
|
|
|
|||
Loading…
Reference in New Issue