Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/kubernetes/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Kubernetes 库伯内特斯没有';t删除Cronjob的已完成作业_Kubernetes_Kubernetes Cronjob - Fatal编程技术网

Kubernetes 库伯内特斯没有';t删除Cronjob的已完成作业

Kubernetes 库伯内特斯没有';t删除Cronjob的已完成作业,kubernetes,kubernetes-cronjob,Kubernetes,Kubernetes Cronjob,当使用较新版本的Kubernetes客户端时设置historylimit时,Kubernetes不会删除手动创建的已完成作业 mycron.yaml: apiVersion: batch/v1beta1 kind: CronJob metadata: name: hello namespace: myjob spec: schedule: "* * 10 * *" successfulJobsHistoryLimit: 0 failedJobsHistor

当使用较新版本的Kubernetes客户端时设置historylimit时,Kubernetes不会删除手动创建的已完成作业

mycron.yaml:

apiVersion: batch/v1beta1
kind: CronJob
metadata:
  name: hello
  namespace: myjob
spec:
  schedule: "* * 10 * *"
  successfulJobsHistoryLimit: 0
  failedJobsHistoryLimit: 1  
  jobTemplate:
    spec:
      template:
        spec:
          containers:
          - name: hello
            image: busybox
            imagePullPolicy: IfNotPresent
            command:
            - /bin/sh
            - -c
            - date; echo Hello from the Kubernetes cluster
          restartPolicy: OnFailure
kubectl create -f mycron.yaml
kubectl create job -n myjob --from=cronjob/hello hello-job
创建cronjob:

apiVersion: batch/v1beta1
kind: CronJob
metadata:
  name: hello
  namespace: myjob
spec:
  schedule: "* * 10 * *"
  successfulJobsHistoryLimit: 0
  failedJobsHistoryLimit: 1  
  jobTemplate:
    spec:
      template:
        spec:
          containers:
          - name: hello
            image: busybox
            imagePullPolicy: IfNotPresent
            command:
            - /bin/sh
            - -c
            - date; echo Hello from the Kubernetes cluster
          restartPolicy: OnFailure
kubectl create -f mycron.yaml
kubectl create job -n myjob --from=cronjob/hello hello-job
手动创建作业:

apiVersion: batch/v1beta1
kind: CronJob
metadata:
  name: hello
  namespace: myjob
spec:
  schedule: "* * 10 * *"
  successfulJobsHistoryLimit: 0
  failedJobsHistoryLimit: 1  
  jobTemplate:
    spec:
      template:
        spec:
          containers:
          - name: hello
            image: busybox
            imagePullPolicy: IfNotPresent
            command:
            - /bin/sh
            - -c
            - date; echo Hello from the Kubernetes cluster
          restartPolicy: OnFailure
kubectl create -f mycron.yaml
kubectl create job -n myjob --from=cronjob/hello hello-job
结果:
作业已完成但未删除

NAME            COMPLETIONS   DURATION   AGE
hello-job           1/1           2s     6m
使用kubernetes服务器+客户端版本1.19.3和1.20.0进行测试

然而,当我对服务器的1.19/1.20版本使用较旧的客户端版本(1.15.5)时,它运行良好。

使用不同的客户端版本时比较差异:

apiVersion: batch/v1beta1
kind: CronJob
metadata:
  name: hello
  namespace: myjob
spec:
  schedule: "* * 10 * *"
  successfulJobsHistoryLimit: 0
  failedJobsHistoryLimit: 1  
  jobTemplate:
    spec:
      template:
        spec:
          containers:
          - name: hello
            image: busybox
            imagePullPolicy: IfNotPresent
            command:
            - /bin/sh
            - -c
            - date; echo Hello from the Kubernetes cluster
          restartPolicy: OnFailure
kubectl create -f mycron.yaml
kubectl create job -n myjob --from=cronjob/hello hello-job
kubernetes控制器日志:
使用客户端v1.15.5时,我在日志中有这一行(但在使用客户端v1.19/1.20时缺少这一行):

工作yaml
完全相同,除了ownerReference部分:
适用于客户端v1.19/1.20

对于客户端v1.15

就这样。日志中没有其他信息,没有错误,没有警告..什么都没有(检查kube系统中的所有pods日志)

摘要:
这似乎是kubectl客户端本身的一个bug,但不是kubernetes服务器的bug。但我不知道如何继续下去

编辑:
当我让cronjob本身执行该作业(即点击表达式中的时间)时,它将成功删除已完成的作业。

我运行了它,它在我的集群上运行(1.20.3)。如果您提供kubectl版本的输出(使用构建哈希),我可以尝试使用您使用的确切版本再复制一次。但是既然你认为它是一个bug,那么更好的选择是在K8S Github RePo上创建一个问题:“Matt昨天创建了一个问题:看起来它不是一个bug,但不受支持的意图很大,看起来它确实是一个“bug”。我的坏习惯是假设它有效。复制它我一定做错了什么。