Skip to content
Snippets Groups Projects
Commit a0bcc831 authored by František Dvořák's avatar František Dvořák
Browse files

More robust pods cleaner script - kill everything in Terminating state

parent 4d54f853
No related branches found
No related tags found
No related merge requests found
......@@ -5,18 +5,17 @@
#
# Example:
#
# k8s-pods-cleaner.sh hub app=jupyterhub,component=singleuser-server --yes
# k8s-pods-cleaner.sh hub --yes
#
if [ -z "$1" ]; then
echo "Usage: $0 NAMESPACE [QUERY [--yes]]"
echo "Usage: $0 NAMESPACE [--yes]"
exit 0
fi
NS="$1"
QUERY="$2"
PERFORM="$3"
for pod in $(kubectl get pod -n "$NS" -l "$QUERY" --field-selector="status.phase==Failed" -ojsonpath='{.items[*].metadata.name}'); do
PERFORM="$2"
for pod in $(kubectl get pod -n "$NS" | awk 'NR>1 && $3=="Terminating" {print $1}'); do
if [ -n "$PERFORM" ]; then
kubectl get pod -n "$NS" "$pod" -oyaml > "/tmp/$NS-$pod.yaml"
kubectl delete pod -n "$NS" "$pod" --force
......
......@@ -133,7 +133,7 @@
name: "Notebooks {{ name }} cleanup"
minute: "*"
hour: "*"
job: "KUBECONFIG=$HOME/.kube/config /usr/local/bin/k8s-pods-cleaner.sh '{{ name }}' app=jupyterhub,component=singleuser-server --yes >/dev/null 2>&1"
job: "KUBECONFIG=$HOME/.kube/config /usr/local/bin/k8s-pods-cleaner.sh '{{ name }}' --yes >/dev/null 2>&1"
user: egi
with_fileglob:
- "../deployments/*.yaml"
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment