kubernetes-Jobs

  A Job creates one or more Pods and ensures that a specified number of them successfully terminate. As pods successfully complete, the Job tracks the successful completions. When a specified number of successful completions is reached, the task (ie, Job) is complete. Deleting a Job will clean up the Pods it created.

A simple case is to create one Job object in order to reliably run one Pod to completion. The Job object will start a new Pod if the first Pod fails or is deleted (for example due to a node hardware failure or a node reboot).

You can also use a Job to run multiple Pods in parallel.

LAB

1. Job manifest file: 


apiVersion: batch/v1
kind: Job
metadata:
  name: countdown
spec:
  template:
    metadata:
      name: countdown
    spec:
      containers:
      - name: counter
        image: centos:7
        command:
         - "bin/bash"
         - "-c"
         - "for i in 9 8 7 6 5 4 3 2 1 ; do echo $i ; done"
      restartPolicy: Never



*************************************************************************************************************************************************

2. Create & Display


kubectl create -f countdown-jobs.yaml

kubectl get jobs

kubectl get po

kubectl describe jobs countdown



*************************************************************************************************************************************************

3. Test


kubectl logs [POD_NAME] 



*************************************************************************************************************************************************

4. Cleanup


kubectl delete jobs countdown

kubectl get po



*************************************************************************************************************************************************

**************Cron Job***********************

#cronjob.yaml
apiVersion: batch/v1beta1
kind: CronJob
metadata:
   name: cronjob
spec:
   schedule: "* * * * *"
   successfulJobsHistoryLimit: 2
   failedJobsHistoryLimit: 1
   suspend: true
   jobTemplate:
     spec:
       template:
         spec:
           containers:
           - name: busybox
             image: busybox
             command: ["echo", "Hello world"]
           restartPolicy: Never


kubectl create -f cronjob.yaml


kubectl patch cronjob cronjob -p '{"spec":{"suspend":false}}'


concurrencyPolicy:   Allow,Forbid,Replace

Allow to allow multiple jobs runs at a time

Forbid to wait a running job to finish first and then execute another instance of the job

Replace to replace an existing job.

Comments

Popular posts from this blog

Terraform

Different Types of Reports in Scrum - Agile

Scrum Master Interview help - Bootcamp