How do I manually trigger a kubernates job (not a cron) in k8s

2/6/2020

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
-- krishnanand nb
kubernetes
kubernetes-jobs

2 Answers

2/6/2020

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
Source: StackOverflow

2/7/2020

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.

-- ragav ramachandran
Source: StackOverflow