如何删除Cronjob资源?

时间:2018-06-13 08:44:14

标签: kubernetes

我用

创建了一个CronJob资源
kubectl create -f cronjob.yaml

现在我的comp太乱了,cronjob试图每次创建一个节点

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

如何执行相反的操作? 如何删除资源?

1 个答案:

答案 0 :(得分:1)

您可以使用以下命令删除它:

kubectl delete -f cronjob.yaml

也可以直接按名称删除它:

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

我不确定使用此命令是否也会删除生成的Pod和Jobs。你可以删除它们:

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

此解决方案假定您使用的是default命名空间。如果不这样做,则必须将--namespace $NAMESPACE参数添加到kubectl