Last active
March 6, 2019 07:59
-
-
Save pashok2398/1f2001ea78b85210dba1e8e88e83fc37 to your computer and use it in GitHub Desktop.
Delete oldest pod k8s cronJob
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: your-cron | |
spec: | |
schedule: "0 0 */2 * *" | |
concurrencyPolicy: Forbid | |
jobTemplate: | |
spec: | |
template: | |
metadata: | |
labels: | |
app: memoryLeak | |
spec: | |
containers: | |
- name: kubectl | |
image: bitnami/kubectl:1.11 | |
imagePullPolicy: IfNotPresent | |
command: ["/bin/sh"] | |
args: ["-c", "kubectl delete pod $(kubectl get pod -l app=redis --sort-by=.metadata.creationTimestamp -o custom-columns=:metadata.name| tail -1)"] | |
securityContext: | |
privileged: false | |
allowPrivilegeEscalation: false | |
restartPolicy: OnFailure | |
serviceAccountName: pod-deleter-sa | |
--- | |
kind: Role | |
apiVersion: rbac.authorization.k8s.io/v1 | |
metadata: | |
name: pod-delete | |
namespace: default | |
labels: | |
app: memoryLeak | |
rules: | |
- apiGroups: [""] | |
resources: ["pods"] | |
verbs: ["delete", "get", "list"] | |
--- | |
apiVersion: rbac.authorization.k8s.io/v1 | |
kind: RoleBinding | |
metadata: | |
name: pod-delete-binding | |
namespace: default | |
labels: | |
app: memoryLeak | |
roleRef: | |
apiGroup: rbac.authorization.k8s.io | |
kind: Role | |
name: pod-delete | |
subjects: | |
- kind: ServiceAccount | |
name: pod-deleter-sa | |
namespace: default | |
--- | |
apiVersion: v1 | |
kind: ServiceAccount | |
metadata: | |
name: pod-deleter-sa | |
namespace: default | |
labels: | |
app: memoryLeak |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment