Last active
June 11, 2021 22:39
-
-
Save mbaykara/8855337cfa619d4f91e7adc08871e6fb to your computer and use it in GitHub Desktop.
This file contains 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: batch/v1beta1 | |
kind: CronJob | |
metadata: | |
name: terminator-4-runner | |
spec: | |
schedule: "*/30 * * * *" | |
jobTemplate: | |
spec: | |
template: | |
spec: | |
serviceAccountName: terminator-4-runner | |
containers: | |
- name: terminator-4-runner | |
image: bitnami/kubectl | |
command: | |
- /bin/sh | |
- -c | |
- kubectl get pods -o go-template --template '{{range .items}}{{.metadata.name}} {{.metadata.creationTimestamp}}{{"\n"}}{{end}}' | awk '$2 <= "'$(date -d'now-5 hours' -Ins --utc | sed 's/+0000/Z/')'" { print $1 }' | xargs --no-run-if-empty kubectl delete pod; | |
imagePullPolicy: IfNotPresent | |
restartPolicy: OnFailure | |
--- | |
apiVersion: v1 | |
kind: ServiceAccount | |
metadata: | |
name: terminator-4-runner | |
--- | |
apiVersion: rbac.authorization.k8s.io/v1 | |
kind: Role | |
metadata: | |
name: modify-pods | |
rules: | |
- apiGroups: [""] | |
resources: | |
- pods | |
verbs: | |
- get | |
- list | |
- delete | |
--- | |
apiVersion: rbac.authorization.k8s.io/v1 | |
kind: RoleBinding | |
metadata: | |
name: modify-pods-to-sa | |
subjects: | |
- kind: ServiceAccount | |
name: terminator-4-runner | |
roleRef: | |
kind: Role | |
name: modify-pods | |
apiGroup: rbac.authorization.k8s.io |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment