Skip to content

Rust based Custom Resouce and Controller for Kubernetes. This creates a custom resource (PodMonitor) to get notify via email/webhook for any pod failure.

License

Notifications You must be signed in to change notification settings

abhisheksuran/PodMonitor

Repository files navigation

PodMonitor Kubernetes Controller

.github/workflows/podmonitor_ci.yaml

This project provides a Rust-based custom resource and controller for Kubernetes. It introduces a custom resource, PodMonitor, which sends email notifications or triggers webhook upon pod failures.

Steps to Deploy

1. Install the Controller

Apply the Kubernetes YAML configuration to set up the necessary components, including the namespace, service account, cluster role, role binding, and controller deployment:

Use PodMonitor.yaml from release

kubectl apply -f PodMonitor.yaml

Alternatively, you can run the Rust code directly:

nohup RUST_LOG=info  cargo run &

Or use the precompiled binary:

nohup RUST_LOG=info ./binary/podmon &

2. Initialize the Custom Resource Definition (CRD)

Once the controller is running, it will automatically create the CRD and operate in the background to manage instances of the custom resource.

3. Create a PodMonitor Instance

Define a new instance of the PodMonitor custom resource using the following YAML template:

All Options

apiVersion: "kk.dev/v1"
kind: PodMonitor
metadata:
  name: mymonitor
spec:
  target_pods:
  - pod1
  - pod2
  mail:
    from: "sender"
    to: "receiver"
    smtp_server: 127.0.0.1
    smtp_port: 25
    tls: "false"
    username: "username"
    password: "password"
  webhook:
    url: "http://127.0.0.1/"

target_pods is optional and if not defined will monitor all the pods in namespacess The username and password fields are optional and depend on your SMTP server's configuration.

CRD fields

Optional Fields: mail, webhook, target_pods
Optional Fields [mail]: username, password

4. Receive Notifications

Whenever a pod fails in the specified namespace, you will receive an email notification according to the configuration set in the PodMonitor instance.

Email Sample

alt text

Features And ToDo

  • ✔️ Monitor Pod within a target namespace
  • ✔️ Monitor specific or all pods in a namespace
  • ✔️ Trigger Email on pod failure
  • ✔️ TSL option ("true", "false") and Authentication to smtp server
  • ✔️ Trigger webhook url with data using post request on pod failure
  • Enable use of kubernetes secret
  • Enable authentication to webhook
  • Enable Kubectl logs podmonitor

License

This project is licensed under the MIT License. See LICENSE for details.

References:

  1. https://www.pavel.cool/posts/rust-kubernetes-operators/
  2. https://www.youtube.com/watch?v=feBYxeO-3cY

About

Rust based Custom Resouce and Controller for Kubernetes. This creates a custom resource (PodMonitor) to get notify via email/webhook for any pod failure.

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages