Detailed explanation of Kubernetes object job

1. Job usage scenarios

Containers can be divided into two categories according to their continuous running time: service containers and work containers.

Service containers usually provide services continuously and need to run all the time, such as http server, mysql db, etc. A worker container is a one-time task, such as a batch program, that exits after completion.

Deployment, ReplicaSet, and DaemonSet in k8s are all used to manage service containers. For work containers, Job can be used.

2. job application

First create a job-based yml file with the following content:

apiVersion:  batch/v1
kind: Job
metadata:
  name: myjob
spec:
  template:
     spec:
        containers:
            - name: job
              image: busybox
              command: ["echo","hello k8s"]
        restartPolicy: Never

 

in:

  • batch/v1 is the apiVersion of the current Job.
  • kind indicates that the type of the current resource is Job.

restartPolicy is used to specify when the container needs to be restarted:

  • Never means that the kubelet will not restart the container regardless of the state
  • OnFailure indicates that the container terminates and restarts when the exit code is not 0
  • Always indicates that when the container fails, kubelet automatically restarts the container

Guess you like

Origin blog.csdn.net/qq_35029061/article/details/132201027