在Kubernetes CronJob中运行'find'命令

在Kubernetes CronJob中运行'find'命令,kubernetes,Kubernetes,无法从装入的卷中删除超过一天的文件。我的yaml: apiVersion: batch/v1beta1 kind: CronJob metadata: name: cfs-cleanup spec: concurrencyPolicy: Forbid schedule: '0 4 * * *' successfulJobsHistoryLimit: 0 failedJobsHistoryLimit: 10 jobTemplate: spec: back

无法从装入的卷中删除超过一天的文件。我的yaml:

apiVersion: batch/v1beta1
kind: CronJob
metadata:
  name: cfs-cleanup
spec:
  concurrencyPolicy: Forbid
  schedule: '0 4 * * *'
  successfulJobsHistoryLimit: 0
  failedJobsHistoryLimit: 10
  jobTemplate:
    spec:
      backoffLimit: 2
      activeDeadlineSeconds: 600
      template:
        metadata:
          annotations:
            sidecar.istio.io/inject: "false"
        spec:
          restartPolicy: Never
          containers:
            - name: cfs-cleanup
              image: alpine:3.13.2
              command: ["find", "/root/volumes/nginx-cache/cfs* -type f -mtime +1 -exec rm -f {} \;"]
              volumeMounts:
                - name: cache
                  mountPath: /root/volumes/nginx-cache

          volumes:
            - name: cache
              hostPath:
                path: /root/volumes/nginx-cache
                type: DirectoryOrCreate

容器失败,没有错误,什么也不做。是否在装入卷之前执行了该命令?

我只是猜测,但在您的命令中

command: ["find", "/root/volumes/nginx-cache/cfs* -type f -mtime +1 -exec rm -f {} \;"]
路径
/root/volumes/nginx cache/cfs*
将无法展开

要验证它,只需尝试
命令:[“ls”,“/root/volumes/nginx cache/cfs*”]

您可以尝试将命令包装在
sh-c…
like中

command: ["sh", "-c", "find /root/volumes/nginx-cache/cfs* -type f -mtime +1 -exec rm -f {} \;"]

此外,您的命令可能完全错误。您将
find
可执行文件的所有参数合并到一个字符串中(当通过
sh-c…

调用时,这应该不会是问题。您可以检查
kubectl Descripte pod
中的任何信息吗?
是否在装入卷之前执行命令?
-不,pod只有在装入所有卷等后才进入运行状态,在装入卷之前它处于
挂起
状态安装已成功完成。