Bird
0
0

Which YAML snippet correctly defines a Kubernetes Job that runs a single pod to completion?

easy📝 Configuration Q3 of 15
Kubernetes - Scheduling
Which YAML snippet correctly defines a Kubernetes Job that runs a single pod to completion?
AapiVersion: batch/v1 kind: Job metadata: name: example-job spec: template: spec: containers: - name: pi image: perl command: ["perl", "-Mbignum=bpi", "-wle", "print bpi(2000)"] restartPolicy: Never
BapiVersion: batch/v1 kind: Job metadata: name: example-job spec: schedule: "*/5 * * * *" template: spec: containers: - name: pi image: perl restartPolicy: Always
CapiVersion: batch/v1 kind: Job metadata: name: example-job spec: replicas: 1 template: spec: containers: - name: pi image: perl restartPolicy: Always
DapiVersion: batch/v1 kind: Job metadata: name: example-job spec: parallelism: 3 template: spec: containers: - name: pi image: perl restartPolicy: Always
Step-by-Step Solution
Solution:
  1. Step 1: Identify the correct apiVersion and kind

    The Job resource uses apiVersion 'batch/v1' and kind 'Job'.
  2. Step 2: Check the spec structure

    The Job spec must include a pod template under 'spec.template' with container specs and a restartPolicy.
  3. Step 3: Validate restartPolicy

    For Jobs, restartPolicy should be 'Never' or 'OnFailure' to avoid infinite restarts.
  4. Final Answer:

    apiVersion: batch/v1 kind: Job metadata: name: example-job spec: template: spec: containers: - name: pi image: perl command: ["perl", "-Mbignum=bpi", "-wle", "print bpi(2000)"] restartPolicy: Never correctly defines a minimal Job YAML with a single pod that runs to completion.
  5. Quick Check:

    Job spec requires 'template' with pod spec and restartPolicy 'Never' or 'OnFailure' [OK]
Quick Trick: Job YAML needs 'template' with pod spec and restartPolicy Never [OK]
Common Mistakes:
  • Using 'schedule' field in Job spec (only for CronJob)
  • Setting restartPolicy to Always in Job pods
  • Using 'replicas' field which is for Deployments
  • Confusing Job with CronJob resource kinds

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Kubernetes Quizzes