DEV Community

Cover image for 9.Create Countdown Job in Kubernetes
Thu Kha Kyawe
Thu Kha Kyawe

Posted on

9.Create Countdown Job in Kubernetes

Lab Information

The Nautilus DevOps team is crafting jobs in the Kubernetes cluster. While they're developing actual scripts/commands, they're currently setting up templates and testing jobs with dummy commands. Please create a job template as per details given below:

Create a job named countdown-xfusion.

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

Utilize image debian with latest tag (ensure to specify as debian:latest), and set the restart policy to Never.

Execute the command sleep 5
Enter fullscreen mode Exit fullscreen mode

Note: The kubectl utility on jump_host is set up to operate with the Kubernetes cluster.

Lab Solutions

Step 1: Create the YAML configuration file

Let's create a YAML file for the job:

cat > countdown-xfusion-job.yaml <<EOF
apiVersion: batch/v1
kind: Job
metadata:
  name: countdown-xfusion
spec:
  template:
    metadata:
      name: countdown-xfusion
    spec:
      containers:
      - name: container-countdown-xfusion
        image: debian:latest
        command: ["sleep", "5"]
      restartPolicy: Never
EOF
Enter fullscreen mode Exit fullscreen mode

Explanation of what we created:

apiVersion: batch/v1 - Uses the batch API for jobs

kind: Job - Specifies this is a Job resource

name: countdown-xfusion - Job name as required

template.metadata.name: countdown-xfusion - Spec template name as required

name: container-countdown-xfusion - Container name as required

image: debian:latest - Uses debian:latest image

command: ["sleep", "5"] - Executes sleep 5 command

restartPolicy: Never - Sets the restart policy to Never

Step 2: Apply the YAML file to create the job

Now, let's create the job in the Kubernetes cluster:

kubectl apply -f countdown-xfusion-job.yaml
Enter fullscreen mode Exit fullscreen mode

Step 3: Verify the job was created

Check that the job exists:

kubectl get job countdown-xfusion
Enter fullscreen mode Exit fullscreen mode

Step 4: Monitor the job execution

Wait a few seconds for the job to complete (it should take about 5 seconds for the sleep command), then check again:

kubectl get job countdown-xfusion
Enter fullscreen mode Exit fullscreen mode

Step 5: Check the pod created by the job

List the pods to see the one created by our job:

kubectl get pods
Enter fullscreen mode Exit fullscreen mode

Step 6: Verify the pod details

Let's check the pod details to confirm all specifications:

kubectl describe pod countdown-xfusion-s52nf
Enter fullscreen mode Exit fullscreen mode

Step 7: Check the job details (optional)

For more detailed information about the job:

kubectl describe job countdown-xfusion
Enter fullscreen mode Exit fullscreen mode


Resources & Next Steps
📦 Full Code Repository: KodeKloud Learning Labs
📖 More Deep Dives: Whispering Cloud Insights - Read other technical articles
💬 Join Discussion: DEV Community - Share your thoughts and questions
💼 Let's Connect: LinkedIn - I'd love to connect with you

Credits
• All labs are from: KodeKloud
• I sincerely appreciate your provision of these valuable resources.

Top comments (0)