https://github.com/werkspot/k8s-event-listener
Listen for k8s events and triggers a script
https://github.com/werkspot/k8s-event-listener
docker-image go kubernetes
Last synced: 9 days ago
JSON representation
Listen for k8s events and triggers a script
- Host: GitHub
- URL: https://github.com/werkspot/k8s-event-listener
- Owner: Werkspot
- License: mit
- Created: 2019-11-13T11:07:50.000Z (almost 6 years ago)
- Default Branch: master
- Last Pushed: 2023-03-16T07:58:14.000Z (over 2 years ago)
- Last Synced: 2025-04-24T02:12:53.425Z (6 months ago)
- Topics: docker-image, go, kubernetes
- Language: Go
- Homepage:
- Size: 223 KB
- Stars: 17
- Watchers: 17
- Forks: 6
- Open Issues: 8
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# K8s Event listener
[](https://travis-ci.com/Werkspot/k8s-event-listener)
Listen for changes on specified resources and invokes the callback script
Currently supporting:
- certificatesigningrequests
- cronjobs
- ingresses
- pods
- serviceaccounts
- nodes
## Usage
```
$ k8s-event-listener --help
Listen for specific kubernetes events
Usage:
k8s-event-listener [flags]
Flags:
-c, --callback string Callback to be executed
-h, --help help for k8s-event-listener
--kube-config string Path to kubeconfig file
--kube-context string Context to use
-p, --probe-port string HTTP port to listen for liveness/readiness probes (default "8080")
-r, --resource string K8s resource to listen
-v, --verbose string Verbose level (default "0")
```
This application has been designed to live inside the cluster, it uses the injected service-account tokens to interact
with the API.
Optionally can be executed from outside the cluster, `--kube-config` and `--kube-context` are mandatory on those cases.
Matching resource events will be sent to callback script as arguments:
- resourceType
- action (`add`, `update` or `delete`)
- namespace
- name
Is important to mention that this application uses a cache system that needs to be populated, so during bootstrap,
all matching resources will be evaluated as insertions.
## Healthcheck
An HTTP server will be created listening to 8080 (can be overwritten via -p flag) with two available probe URLs
- `/live` to be used in the liveness configuration
- `/ready` to be used in the readiness configuration
Currently only checks for kube-api connectivity.
### Example
```
$ k8s-event-listener -r pod -c ./test.sh
```
Script will start receiving instructions like:
```
pods add instapro-client ic-nl-tests-acc-26937c1b-webserver-7ff884c575-dvwkb
pods add instapro-gd-city-filter r-travaux-com-db-queue-worker-7585fd84c-4gxzc
pods add monitoring datadog-5swgj
```