Tuesday, August 15, 2023

Create few jobs in Kubernetes cluster


Create few jobs in Kubernetes cluster

Creation of  example job countdown-devops.

The spec template should be named as countdown-devops (under metadata), and the container should be named as container-countdown-devops

Use image centos with latest tag only and remember to mention tag i.e centos:latest, and restart policy should be Never.

Use command sleep 5

Yaml Code 

apiVersion: batch/v1
kind: Job
metadata:
  name: countdown-devops
spec:
  template:
    metadata:
      name: countdown-devops
    spec:
      containers:
      - name: container-countdown-devops
        image: centos:latest
        command: ["sleep", "5"]
      restartPolicy: Never

You can save this as a YAML file, for example, countdown-devops-job.yaml, and then apply it using the kubectl command 

# kubectl apply -f countdown-devops-job.yaml

This will create a job named countdown-devops with a container named container-countdown-devops running the centos:latest image and executing the command sleep 5. The job will not restart automatically (restartPolicy: Never).

To see the status of the job:

# kubectl get jobs

To get more details about the job and its pods:

# kubectl describe job countdown-devops

No comments:

Post a Comment

Troubleshoot issue with Pods - Part 2

  Troubleshoot issue with Pods - Part 2 To verify if there are any port conflicts between the containers and ensure that the container ports...