Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Set-Content -Path cron.yml -Value @"
- apiVersion: batch/v1beta1
- kind: CronJob
- metadata:
- name: podreaper
- spec:
- schedule: "0 * * * *"
- jobTemplate:
- spec:
- template:
- spec:
- containers:
- - args:
- - pwsh
- - "-Command"
- - '/opt/configure-kubectl.sh; kubectl get pods -o json --all-namespaces | ConvertFrom-Json | Select -ExpandProperty items | ? {`$_.status.phase -eq "Terminating" -or `$_.status.phase -eq "Unknown" -or `$_.status.reason -eq "NodeLost"} | % {Invoke-WebRequest -Headers @{"Content-type"="application/json"} -Uri #{SlackWebHook} -Method POST -Body ''{"text":"Pod reaper killed pod `$(`$_.metadata.name) from `$(`$_.metadata.namespace)!"}''; kubectl delete pod `$_.metadata.name -n `$_.metadata.namespace --grace-period=30} | % {kubectl delete pod `$_.metadata.name -n `$_.metadata.namespace --grace-period=0 --force}; Write-Host "Done"'
- image: "mcasperson/kubectl:0.0.3"
- name: podreaper
- nodeSelector:
- kubernetes.io/role: master
- restartPolicy: OnFailure
- serviceAccountName: octopus-administrator
- tolerations:
- - effect: NoSchedule
- key: node-role.kubernetes.io/master
- operator: Equal
- value: "true"
- "@
- kubectl apply -f cron.yml
Add Comment
Please, Sign In to add comment