How to remove Cronjob resource?

6/13/2018

I created a CronJob resource with

kubectl create -f cronjob.yaml

Now I have too much mess on my comp,cronjob attempts to create one node every

15 minutes
batch-job-every-fifteen-minutes-1528876800-h8dsj   0/1       Pending              0          39m
batch-job-every-fifteen-minutes-1528877700-d8g9d   0/1       Pending              0          24m
batch-job-every-fifteen-minutes-1528878600-kbdmb   0/1       Pending              0          9m

How to perform the opposite operation? How to delete the resource?

-- Richard Rublev
kubernetes

1 Answer

6/13/2018

You can delete it with this command:

kubectl delete -f cronjob.yaml

It is also possible to delete it directly by name:

kubectl delete cronjob batch-job-every-fifteen-minutes

I am not sure whether the generated Pods and Jobs also get deleted with this command. You can delete them like this:

kubectl delete job batch-job-every-fifteen-minutes-1528876800
kubectl delete job batch-job-every-fifteen-minutes-1528877700
kubectl delete job batch-job-every-fifteen-minutes-1528878600

kubectl delete pod batch-job-every-fifteen-minutes-1528876800-h8dsj
kubectl delete pod batch-job-every-fifteen-minutes-1528877700-d8g9d
kubectl delete pod batch-job-every-fifteen-minutes-1528878600-kbdmb

This solution assumes you are using the default namespace. If you do not, you have to add the --namespace $NAMESPACE argument to kubectl.

-- svenwltr
Source: StackOverflow