Job Example
Download the YAML configuration file for the Job example
Create the Job
Applies the configuration from the YAML file to create the Job.
Get the Jobs List
Lists all Jobs in the current namespace.
Get More Info
Shows detailed information about the Job.
Get the Pod Name
Lists all pods. Look for a pod starting with hello-.
Get the Container's Log
Shows the container's log. You should see Hello from the Job.
Cleanup
Deletes all resources defined in the YAML configuration file.
YAML Configuration File
apiVersion: batch/v1
kind: Job
metadata:
name: hello
spec:
template:
spec:
containers:
- name: busybox
image: busybox
command: ["echo", "Hello from the Job"]
restartPolicy: Never
YAML Configuration Explanation:
Job Structure:
- apiVersion: batch/v1 → Specifies the Kubernetes API version for batch resources
- kind: Job → Defines this as a Job resource
- metadata.name: hello → Names the Job "hello"
Job Specification:
- spec.template → Defines the pod template that the Job will create
- spec.template.spec → Specifies the pod specification
Container Definition:
- name: busybox → Names the container "busybox"
- image: busybox → Uses the lightweight BusyBox image
- command: ["echo", "Hello from the Job"] → Specifies the command to run in the container
Restart Policy:
- restartPolicy: Never → Specifies that the container should not be restarted if it exits
- This is important for Jobs, as we typically want them to run to completion without restarting
How It Works:
When you create this Job, Kubernetes will create a pod that runs the specified command. The Job ensures that the pod runs to completion. Once the command executes successfully (echoing "Hello from the Job"), the Job is considered complete. Unlike Deployments or ReplicaSets, Jobs are designed for batch processing tasks that need to run once and then terminate.