Last active
June 9, 2024 02:47
-
-
Save davidmroth/b0abb8c5f246dd57f0d7e0cd8f538009 to your computer and use it in GitHub Desktop.
Remove Failed Pods
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
apiVersion: v1 | |
kind: ServiceAccount | |
metadata: | |
name: pod-deleter-sa | |
namespace: kube-system | |
--- | |
apiVersion: rbac.authorization.k8s.io/v1 | |
kind: ClusterRole | |
metadata: | |
name: pod-deleter-sa | |
rules: | |
- apiGroups: | |
- "" | |
resources: | |
- pods | |
verbs: | |
- get | |
- watch | |
- list | |
- delete | |
--- | |
apiVersion: rbac.authorization.k8s.io/v1 | |
kind: ClusterRoleBinding | |
metadata: | |
name: pod-deleter-sa | |
subjects: | |
- kind: ServiceAccount | |
name: kubectl | |
namespace: default | |
roleRef: | |
kind: ClusterRole | |
name: kube-system | |
apiGroup: rbac.authorization.k8s.io | |
--- | |
apiVersion: batch/v1 | |
kind: CronJob | |
metadata: | |
name: delete-failed-pods | |
namespace: kube-system | |
spec: | |
concurrencyPolicy: Allow | |
failedJobsHistoryLimit: 1 | |
spec: | |
template: | |
spec: | |
containers: | |
- command: | |
- sh | |
- -c | |
- kubectl delete pods --ignore-not-found=true --field-selector 'status.phase=Failed' | |
-A; exit 0 | |
image: bitnami/kubectl:latest | |
imagePullPolicy: Always | |
name: kubectl-runner | |
dnsPolicy: ClusterFirst | |
restartPolicy: OnFailure | |
schedulerName: default-scheduler | |
serviceAccount: pod-deleter-sa | |
serviceAccountName: pod-deleter-sa | |
terminationGracePeriodSeconds: 30 | |
schedule: '*/30 * * * *' | |
successfulJobsHistoryLimit: 1 | |
suspend: false |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment