Skip to main content

CountDownJob

·143 words·1 min
Jack Warner
Author
Jack Warner
A little blog by me
apiVersion: batch/v1
kind: Job
metadata:
  name: countdown-devops
spec:
  template:
    metadata:
      name: countdown-devops
    spec:
      containers:
      - name: container-countdown-devops
        image: ubuntu:latest
        command: ["sleep", "5"]
      restartPolicy: Never

In Kubernetes, the same field name (metadata.name) can appear in different places within a YAML file. Even though the field looks identical, it refers to different resources depending on where it is defined.


1. metadata.name (Top-level)
#

metadata:
  name: countdown-devops
  • This metadata.name is at the top level of the Job resource.
  • It specifies the name of the Job itself.
  • In this example, the Job is named countdown-devops.

2. spec.template.metadata.name (Nested within spec.template)
#

spec:
  template:
    metadata:
      name: countdown-devops
  • This metadata.name is nested within the spec.template section of the Job.
  • It specifies the name of the Pod template that the Job will create when it runs
  • In this example, the Pod created by the Job will also be named countdown-devops.

Related