Skip to main content

TASK 96: Countdown job in Kubernetes

Requirements

The Nautilus DevOps team is working on to create few jobs in Kubernetes cluster. They might come up with some real scripts/commands to use, but for now they are preparing the templates and testing the jobs with dummy commands. Please create a job template as per details given below:

  • Create a job countdown-nautilus.

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

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

  • Use command:

    for i in ten nine eight seven six five four three two one ; do echo $i ; done

Note: The kubectl utility on jump_host has been configured to work with the kubernetes cluster.


Note

This document focuses on the implementation approach. The task statement in Requirements is preserved as the source requirement.

Prerequisites

  • Access to the configured Kubernetes cluster from jump_host.
  • kubectl is configured and points to the correct context.
  • Use the task-specified namespace, resource names, and images exactly.

Steps

As best practice, retrieve all resources first.

$ kubectl get all

NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
service/kubernetes ClusterIP 10.96.0.1 <none> 443/TCP 111m

Create the manifest for the resource definitions based on the requirements.

# countdown.yml
apiVersion: batch/v1
kind: Job
metadata:
name: countdown-nautilus
spec:
template:
metadata:
name: countdown-nautilus
spec:
containers:
- name: container-countdown-nautilus
image: ubuntu:latest
command: ["/bin/sh", "-c"]
args:
[
"for i in ten nine eight seven six five four three two one ; do echo $i ; done",
]
restartPolicy: Never

Apply.

kubectl apply -f .

Verify by checking the resources again and checking the logs.

$ kubectl get pods
NAME READY STATUS RESTARTS AGE
countdown-nautilus-9ffjb 0/1 Completed 0 21s
$ kubectl get jobs
NAME COMPLETIONS DURATION AGE
countdown-nautilus 1/1 9s 39s
$ kubectl logs -f countdown-nautilus-9ffjb
ten
nine
eight
seven
six
five
four
three
two
one

Verification

  • Confirm the required pods/services/deployments/jobs are in the expected state.
  • Run kubectl get commands for the affected resource types and namespace.

Resources