1.

Let’s say a Kubernetes job should finish in 40 seconds, however on a rare occasion it takes 5 minutes, How can I make sure to stop the application if it exceeds more than 40 seconds?

Answer»

When we create a JOB spec, we can give --activeDeadlineSeconds flag to the command, this flag relates to the DURATION of the job, once the job reaches the threshold specified by the flag, the job will be terminated.

kind: CronJob apiVersion: batch/v1beta1 metadata:   name: mycronjob spec:   schedule: "*/1 * * * *" activeDeadlineSeconds: 200   jobTemplate:     metadata:       name: google-check-job     spec:       template:         metadata:           name: mypod         spec:           restartPolicy: OnFailure           containers:             - name: mycontainer              IMAGE: alpine              command: ["/bin/sh"]              ARGS: ["-C", "ping -w 1 google.com"]


Discussion

No Comment Found

Related InterviewSolutions