Questão de System Administration #019e3a4f
A CronJob is scheduled to run by a user every one hour. What happens in the cluster when it's time for this CronJob to run?
Kubelet watches API Server for CronJob objects. When it's time for a Job to run, it runs the Pod directly.
Kube-scheduler watches API Server for CronJob objects, and this is why it's called kube-scheduler.
CronJob controller component creates a Pod and waits until it finishes to run.
CronJob controller component creates a Job. Then the Job controller creates a Pod and waits until it finishes to run.
Explicação Oficial / Explicações da Comunidade
The correct behavior is that the CronJob controller creates a Job object, and then the Job controller creates a Pod to execute the task. The CronJob controller is responsible for managing the schedule and creating Job objects at the specified times. Each Job represents a single run of the task. The Job controller then creates one or more Pods to complete the Job, and it ensures the Pod runs to completion. The CronJob controller does not directly create Pods; it relies on the Job controller to handle Pod creation and lifecycle.
How it Works:
- The CronJob controller watches for CronJob resources in the API server. When the scheduled time arrives, it creates a Job object based on the CronJob's job template.
- The Job controller, which watches for Job objects, then creates a Pod (or multiple Pods for parallel jobs) to execute the command specified in the Job template.
- The Job controller monitors the Pod until it finishes successfully or fails, and it can retry according to the backoff limit.
- The CronJob controller does not wait for the Job to complete; it only creates the Job and moves on to the next scheduled time.
Why the correct value is right:
The statement "CronJob controller component creates a Job. Then the Job controller creates a Pod and waits until it finishes to run" accurately describes the two-step process: CronJob -> Job -> Pod. The Job controller waits for the Pod to finish, which is part of its responsibility to ensure the Job completes.
Why the incorrect values are wrong:
- The statement "Kubelet watches API Server for CronJob objects. When it's time for a Job to run, it runs the Pod directly" is incorrect because Kubelet does not watch for CronJob objects. Kubelet is an agent that runs on each node and manages Pods assigned to that node. It does not create Pods based on CronJobs; it only runs Pods that are scheduled to its node by the scheduler.
- The statement "Kube-scheduler watches API Server for CronJob objects, and this is why it's called kube-scheduler" is incorrect. The kube-scheduler is responsible for assigning Pods to nodes, not for managing CronJobs. Its name comes from scheduling Pods onto nodes, not from handling CronJob schedules.
- The statement "CronJob controller component creates a Pod and waits until it finishes to run" is incorrect because the CronJob controller does not directly create Pods. It creates Job objects, and the Job controller handles Pod creation. Additionally, the CronJob controller does not wait for the Pod to finish; it only creates the Job and then continues to monitor the schedule for the next run.