7

I have sample k8s job as soon as you do kubectl apply the job gets triggered and the pods are created . How to control the pod creation?

apiVersion: batch/v1
kind: Job
metadata:
  name: pi-with-timeout
spec:
  backoffLimit: 5
  activeDeadlineSeconds: 100
  template:
    spec:
      containers:
      - name: pi
        image: perl
        command: ["perl",  "-Mbignum=bpi", "-wle", "print bpi(2000)"]
      restartPolicy: Never
mohan08p
  • 5,002
  • 1
  • 28
  • 36

2 Answers2

4

If you want to manually control the pod creation, you can achieve it through parallelism.

Documentation says:

The requested parallelism (.spec.parallelism) can be set to any non-negative value. If it is unspecified, it defaults to 1. If it is specified as 0, then the Job is effectively paused until it is increased.

You can set it to 0 while doing the kubectl apply. Configuration looks something like below

apiVersion: batch/v1
kind: Job
metadata:
  name: pi-with-timeout
spec:
  backoffLimit: 5
  parallelism: 0
  activeDeadlineSeconds: 100
  template:
    spec:
      containers:
      - name: pi
        image: perl
        command: ["perl",  "-Mbignum=bpi", "-wle", "print bpi(2000)"]
      restartPolicy: Never

You can set it to 1 whenever you decide to run.

  • 1
    wow this helped thanks . I think we can patch a job by kubectl patch job pi-with-timeout --type='json' -p='[{"op": "replace", "path": "/spec/parallelism", "value":1}]' – krishnanand nb Feb 07 '20 at 05:51
1

The trigger is running kubectl apply. When you create the Job, it runs. You might be looking for a more fully featured background task system like Airflow or Argo.

coderanger
  • 52,400
  • 4
  • 52
  • 75