Create Cronjobs in Kubernetes Kodekloud

 

Question: There are some jobs/tasks that need to be run regularly on different schedules. Currently the Nautilus DevOps team is working on developing some scripts that will be executed on different schedules, but for the time being the team is creating some cron jobs in Kubernetes cluster with some dummy commands (which will be replaced by original scripts later). Create a cronjob as per details given below:

    Create a cronjob named xfusion.

    Set schedule to */4 * * * *.

    Container name should be cron-xfusion.

    Use nginx image with latest tag only and remember to mention the tag i.e nginx:latest.

    Run a dummy command echo Welcome to xfusioncorp!.

    Ensure restart policy is OnFailure.

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

Soution:

Create a cronjob.yaml according to question

apiVersion: batch/v1beta1
kind: CronJob
metadata:
  name: xfusion
spec:
  schedule: "*/4 * * * *"
  jobTemplate:
    spec:
      template:
        spec:
          containers:
            - name: cron-xfusion
              image: nginx:latest
              command:
                - /bin/sh
                - -c
                - echo Welcome to xfusioncorp!
          restartPolicy: OnFailure

Then run 

kubectl apply -f cronjob.yaml

Finally Checks the logs of pod

kubectl logs -f pod-name



Download Coding Interview Book and Get More Tutorials for Coding and Interview Solution: Click Here

Download System Design Interview Book and Get More Tutorials and Interview Solution: Click Here

Do you need more Guidance or Help? Then Book 1:1 Quick Call with Me: Click Here

Share on Google Plus

About Ashadullah Shawon

I am Ashadullah Shawon. I am a Software Engineer. I studied Computer Science and Engineering (CSE) at RUET. I Like To Share Knowledge. Learn More: Click Here
    Blogger Comment
    Facebook Comment

0 comments:

Post a Comment