Code Monkey home page Code Monkey logo

k8s-job-trace's Introduction

k8s-job-trace

This script tracks the execution of Kubernetes Jobs and report their completion success/failure. It requires kubectl to communicate with k8s cluster and wait for the job to complete. Logs generated from pod(s) running the job are piped to stdout/stderr in the current process, it's mean to shield off the details of which pods are running this job. When all you care about is a run to completion process.

Installing

npm install k8s-job-trace

Prerequisites

You will need to [install] kubectl on the system where this script is to run.

Also make sure your kubectl have been setup to access the desired cluster(s), this might need contacting the admin of your cluster if it's not managed by you.

You should have at least the permissions to view the jobs running in the cluster, verify by kubectl get jobs -n <namespace>, it should give a list of jobs (if any has created) like the following example:

$ kubectl get jobs
NAME        DESIRED   SUCCESSFUL   AGE
my-job           1             0            5s

Getting Started

First, we should have a deployment of the job desired to run in someway, being it's deployed via kubectl or installed via helm isn't really important. As soon as you have permission to run the deploy and is acknowledged about it's successful deployment.

Generally you should run this script immediately following the deployment/helm install/helm upgrade, specifying the job name as argument:

# This is the command that deploys the job to cluster... 

# Trace job run to completion 
k8s-job-trace $YOUR_JOB_NAME

# The exit code should reflect success/failure
if [ $? -eq 0 ]
then
  echo "The job ran ok"
  exit 0
else
  echo "The job failed" >&2
  exit 1
fi

Running the tests

To run test you need a (local) Kubernetes cluster where you have permission to deploy arbitrary job.

npm run test

This has been tested by running the script against different types of job specs, currently tested with the following cases:

  • success job run
  • failed job run
  • job pod timed out (specified in activeDeadlineSeconds)
  • job pod has image pull-error: (either ImagePullBackOff or ErrImagePull)

If you find a case not working for you, create an new issue and leave comments on how to reproduce it.

Code Style

JavaScript source are lint checked with ESLint & formatted by Prettier

npm run lint

License

This project is licensed under the MIT License - see the LICENSE.md file for details

Acknowledgments

  • Hat tip to anyone whose code was used
  • Inspiration
  • etc

k8s-job-trace's People

Contributors

garryyao avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.