How to scale down cron-job in Kubernetes

251 Views Asked by At

How to scale down a cron-job without deleting. Is there any command like this?

My cron-job failed and created 1422 pods. I suspend them using suspend: true but I need to scale 1422 pods it to 0. My CronJob pods status is pending

Any command like this?

kubectl scale cronjob tms-cron --replicas=0 -n develop

UPDATE

I tried to delete Pending pods after suspend CronJob kubectl get pod -n develop | grep 'tms-cron-2833' | grep Pending | awk '{print $1}' | xargs kubectl delete pod -n develop But deleted pods re-created

My cron-job yaml is here

--
apiVersion: batch/v1
kind: CronJob
metadata:
  name: tms-cron
  namespace: develop
spec:
  schedule: "*/1 * * * *"
  jobTemplate:
    spec:
      template:
        spec:
          imagePullSecrets:
            - name: s-jenkins
          containers:
            - name: tms-cronjob
              image: docker-c2.example.com/netcore/netcore-v:v0.BUILDVERSION
              imagePullPolicy: IfNotPresent
              envFrom:
                - secretRef:
                    name: netcore-secrets
                - configMapRef:
                    name: netcore-configmap
              command:
                - php
              args:
                - artisan
                - schedule:run
          restartPolicy: OnFailure
1

There are 1 best solutions below

0
On

I delete all pending jobs after suspending CronJob(not deleting) which starts with support-cron-dev

They key is here kubectl delete job not kubectl delete pod

when I used kubectl delete pod pods re-created. whena I used kubectl delete job they gone successfully

kubectl get jobs -n develop | grep 'support-cron-dev-' | awk '{print $1}' | xargs kubectl delete job -n develop