From c8aabe253241c3c89dfb2e75628c8ebc27d871a2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?M=C3=A1rcio=20Fernandes?= Date: Sun, 19 Jul 2026 10:54:44 +0000 Subject: [PATCH] modified: README.md --- README.md | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/README.md b/README.md index 8b4edc6..5a21391 100644 --- a/README.md +++ b/README.md @@ -18,6 +18,7 @@ Kubernetes is an open‑source platform that automates the deployment, scaling, - [find persistent volume used pvc](#find-persistent-volume-used-pvc) - [Patch pv - change to retain policy](#patch-pv---change-to-retain-policy) - [Patch pv - remove finalizers](#patch-pv---remove-finalizers) + - [check orphans](#check-orphans) - [persistent volume claims](#persistent-volume-claims) - [Create an pod with PVC](#create-an-pod-with-pvc) - [kubectl](#kubectl) @@ -346,6 +347,39 @@ kubectl patch pv $PV_NAME \ -p '{"metadata":{"finalizers": null}}' ``` +### check orphans + +**Execute on host:** + +``` bash +#/bin/bash +STORAGE_DIR="/var/lib/rancher/k3s/storage" +# clean if already been used +unset PV_PATHS +declare -A PV_PATHS +ORPHANS=() + +for name in $(kubectl get pv -o jsonpath='{.items[*].metadata.name}'); do + path=$(kubectl get pv ${name} -o jsonpath='{.spec.local.path}' 2>/dev/null) + # check if path is no empty + [[ -n "${path}" ]] && PV_PATHS["${path}"]="1" +done + +for dir in "$STORAGE_DIR"/*; do + [ -d "$dir" ] || continue + if [[ -z "${PV_PATHS[$dir]}" ]]; then + ORPHANS+=("$dir") + fi +done + +if [[ ${#ORPHANS[@]} -eq 0 ]]; then + echo "No orphans found." +else + echo "orphans:" + printf "%s\n" "${ORPHANS[@]}" +fi +``` + ### persistent volume claims ``` yaml