使用Kubernetes cron作业,可以定期执行(批处理)作业。 有了显示器仪表板,更容易看出哪些作业正在运行,以及它们的最新状态是“成功”还是“失败”。

前端源于令人敬畏的Jenkins Build Monitor插件。 该应用程序使用kubectl在容器内部
从Kubernetes检索数据。

@[TOC]

Kubernetes job monitor

Installation

Kubeconfig secret

The Kubernetes job monitor uses kubectl to retrieve data from the Kubernetes cluster, which requires authentication.
The configuration for the admin user that is located at /etc/kubernetes/admin.conf on the Kubernetes master can be
used. It’s off course also possible to create a user that only has read access to jobs (of one namespace or
all namespaces).

Convert the user configuration to one base64 encoded line:

cat /etc/kubernetes/admin.conf | base64 | tr -d '\n'

Create the secret.yaml manifest:

---
apiVersion: v1
kind: Secret
metadata:
  name: kubeconfig
type: Opaque
data:
  config: thebase64encodedlinehere

Apply in the same namespace as the Kubernetes job monitor:

kubectl apply -f secret.yaml

This secret will be mounted inside the container so that kubectl can use it.

Deployment

kubectl apply -f https://raw.githubusercontent.com/pietervogelaar/kubernetes-job-monitor/master/.kubernetes/kubernetes-job-monitor.yaml

Note: You should review the manifest above, to configure the correct host and Kubernetes dashboard URL for
deep linking.

Usage

By default the Kubernetes job monitor shows the latest status of all jobs (created by cron jobs) it can find. A couple
of query parameters are available.

Parameter Description
title The title of the monitor dashboard, which is displayed at the top and used as page title
namespace Show only jobs in this namespace
selector Show only jobs that match this selector (e.g. key1=value1,key2=value2)

Examples

  • kubernetes-job-monitor.local/namespace=namespace-a
  • kubernetes-job-monitor.local/title=My Job Monitor&namespace=namespace-a&selector=group=one
  • kubernetes-job-monitor.local/title=My Job Monitor&selector=group=two

Demo

kubectl create namespace namespace-a
kubectl create namespace namespace-b
kubectl apply -f https://raw.githubusercontent.com/pietervogelaar/kubernetes-job-monitor/master/.kubernetes/test-cron-jobs.yaml

References

  1. https://hub.docker.com/r/pietervogelaar/kubernetes-job-monitor/
  2. https://github.com/pietervogelaar/kubernetes-job-monitor