Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

331
Views
Run `find` command inside Kubernetes CronJob

Unable to remove files older than one day from the mounted volume. My 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

the container fails without an error and does nothing. Could it be that command gets executed before volume is mounted?

over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

I'm just guessing, but in your command

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

path /root/volumes/nginx-cache/cfs* won't get expanded.

To verify it, just try command: ["ls", "/root/volumes/nginx-cache/cfs*"]

You can try to wrap your command in sh -c ... like

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

Also, your command is possibly wrong altogether. You merged all arguments of find executable into single string (which shouldn't be problem when invoked via sh -c ....

over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!