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: NeverIn 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.nameis 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.nameis nested within thespec.templatesection 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.