PVCWatch - Kubernetes stuck PersistentVolumeClaim watcher
Watches Kubernetes PVCs and alerts on Slack when one gets stuck in Pending.
A Kestra blueprint that watches Kubernetes pods stuck in Pending past a threshold and alerts on Slack with the diagnosed scheduling reason, without spamming.
list_pods (io.kestra.plugin.scripts.shell.Commands) dumps the namespace's pods as JSON with kubectl.find_pending (io.kestra.plugin.scripts.python.Script) keeps pods whose phase is Pending longer than pending_minutes, then reads the PodScheduled=False condition message and translates scheduler jargon into plain causes: no node matching nodeSelector/affinity, insufficient CPU or memory, an unbound PersistentVolumeClaim, or untolerated taints. It compares against the KV state so only newly stuck pods alert.maybe_alert (io.kestra.plugin.core.flow.If) posts the Slack alert only when there is something new, naming the pod, how long it has been pending, and the diagnosed why.save_state (io.kestra.plugin.core.kv.Set) writes back the current stuck list. Scheduled pods drop out on their own, so getting stuck again alerts again, and steady-state reruns stay quiet.Anyone running workloads on Kubernetes who has watched a pod sit in Pending wondering whether it is the node selector, the resources, or the storage. Works on any cluster you can reach with a client certificate: minikube, kind, managed clusters.
kubectl get pods shows you the symptom; this flow adds the diagnosis, the memory, and the notification in one scheduled place. Kestra holds the cluster credentials as secrets, keeps every run's findings where you can audit them, and the KV state means the second run does not page you about the same pod again. It completes the pod trilogy with PodPulse (crashed pods) and ImageWatch (pods that cannot pull): this one catches pods that cannot even be placed.
| Secret | What it is |
|---|---|
CLIENT_CRT |
base64-encoded client certificate from your kubeconfig |
CLIENT_KEY |
base64-encoded client key from your kubeconfig |
MASTERURL |
base64-encoded Kubernetes API server URL, reachable from inside the Kestra container |
SLACK_WEBHOOK |
base64-encoded Slack Incoming Webhook URL |
In Kestra OSS, secrets come from environment variables prefixed with SECRET_ and must be base64-encoded. If the API URL uses 127.0.0.1 or localhost, replace it with host.docker.internal so the Kestra container can reach it.
SECRET_ environment variables. If minikube restarted since your last run, regenerate SECRET_MASTERURL first: the API port changes on every minikube start.pending_minutes: 1 for testing: create a stuck pod with kubectl run pending-demo --image=nginx --overrides='{"spec":{"nodeSelector":{"gpu":"true"}}}' and the Slack alert names it with the affinity reason.kubectl get namespaces output in the shell step.kubectl get events for the stuck pod.pending_minutes for dev namespaces where fast feedback matters.| Input | Type | Default | What it does |
|---|---|---|---|
namespace |
STRING | default |
the namespace whose pods to watch |
pending_minutes |
INT | 10 |
pods pending longer than this count as stuck |
slack_webhook |
STRING | (required) | Incoming webhook URL of the Slack channel for alerts |
pending_minutes exists because every pod is Pending for a few seconds while scheduling. Set it to 1 only for testing; 10 is sane for real use.minikube start. Regenerate SECRET_MASTERURL and restart the Kestra container, or the kubectl step fails to connect.