k8s-job-notify

command module
v0.0.0-...-47123c5 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 7, 2022 License: MIT Imports: 11 Imported by: 0

README ยถ

Kubernetes Job/CronJob Notifier

GitHub followers Twitter URL

DeepSource

GoReport Docker Pulls GitHub commit activity

This tool sends an alert to slack whenever there is a Kubernetes cronJob/Job failure/success.

No extra setup required to deploy this tool on to your cluster, just apply below K8s deploy manifest ๐ŸŽ‰

This uses InClusterConfig for accessing Kubernetes API.

Limitations

  • Namespace scoped i.e., each namespace should have this deploy separately
  • All the jobs in the namespace are fetched and verified for failures
    • Will add support for selectors in future ๐Ÿ“‹

Development

If you wish to run this locally, clone this repository, set webhook and namespace env variables. This expects kube config to be in ~/.kube/config (default)

$ export webhook="slack_webhook_url" && export namespace="<namespace_name>" && go build &&  ./k8s-job-notify

You can also adjust the notification level to failed instead of all so that it only sends failed notificatinos.

$ export webhook="slack_webhook_url" && export namespace="<namespace_name>" && export notification_level="failed" && go build &&  ./k8s-job-notify

Docker ๐Ÿณ


Docker images are hosted at hub.docker/k8s-job-notify

Releases

  • If you want to use stable releases, please use github release tags. For example, image: sukeesh/k8s-job-notify:1.2
  • If you wish to use unstable, use image: sukeesh/k8s-job-notify:beta (triggered whenever push to master is made)

To start using this

Create and apply below kubernetes deployment in your cluster

apiVersion: apps/v1
kind: Deployment
metadata:
  labels:
    app: kjn
  name: k8s-job-notify
  namespace: <namespace_name>
spec:
  replicas: 1
  selector:
    matchLabels:
      app: kjn
  template:
    metadata:
      annotations:
        sidecar.istio.io/inject: 'false'
      labels:
        app: kjn
    spec:
      #serviceAccountName: k8s-job-notify (optional, see RBAC)
      containers:
        - env:
            - name: webhook
              value: <slack_webhook_url> # creating a secret for this var is recommended
            - name: namespace
              valueFrom:
                fieldRef:
                  fieldPath: metadata.namespace
            - name: incluster
              value: '1'
            - name: "notification_level"
              value: 'all'  # or 'failed'
          image: sukeesh/k8s-job-notify:<tag>
          name: k8s-job-notify
          resources:
            limits:
              cpu: 500m
              memory: 256Mi
            requests:
              cpu: 500m
              memory: 128Mi

If your kubernetes uses RBAC, you should apply the following manifest as well:

---
apiVersion: v1
kind: ServiceAccount
metadata:
  name: k8s-job-notify
  namespace: <namespace_name>

---
apiVersion: rbac.authorization.k8s.io/v1
kind: Role
metadata:
  namespace: <namespace_name>
  name: job-reader
rules:
  - apiGroups: ['batch'] # "" indicates the core API group
    resources:
      - jobs
    verbs:
      - get
      - list
      - watch

---
apiVersion: rbac.authorization.k8s.io/v1
kind: RoleBinding
metadata:
  name: k8s-job-notify
  namespace: <namespace_name>
roleRef:
  apiGroup: rbac.authorization.k8s.io
  kind: Role
  name: job-reader
subjects:
  - kind: ServiceAccount
    name: k8s-job-notify
    namespace: <namespace_name>

If you want to show cluster name in message:

containers:
  image: sukeesh/k8s-job-notify:<tag>
  name: k8s-job-notify
  args: ['--cluster-name=<your-cluster-name>']

Contributing ๐Ÿค

Contributions, issues and feature requests are welcome.

Author

๐Ÿ‘ค Sukeesh

Please feel free to โญ๏ธ this repository if this project helped you! ๐Ÿ˜‰

๐Ÿ“ License

Copyright ยฉ 2019 Sukeesh.
This project is MIT licensed.

Documentation ยถ

The Go Gopher

There is no documentation for this package.

Directories ยถ

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL