Coder Social home page Coder Social logo

mauri870 / k8s-controller-heartbeat Goto Github PK

View Code? Open in Web Editor NEW
3.0 3.0 0.0 105 KB

A Kubernetes controller that exposes monitoring endpoints via HTTP to check the availability of deployments running in the cluster

License: MIT License

Dockerfile 2.36% Go 97.64%
status-active status-page kubernetes

k8s-controller-heartbeat's Introduction

k8s-controller-heartbeat

A Kubernetes Controller that exposes an HTTP API to check the availability of deployments running in a kubernetes cluster.

Alt text

Nixstats Dashboard reflecting the status of deployments

Why

This project was designed out of the need to actively monitor deployments running in a kubernetes cluster. A remote status page or third-party application can then retrieve the status by polling the endpoint related to a specific deployment, as I have done with the NixStats status page for example.

This type of active monitoring does not require that you - the developer or cluster administrator - have to implement this logic manually sometimes having to develop some weird email integration or provide the storage to keep track of which service is down and whatnot.

If the deployment, or actually, the pods running for that deployment are degraded by some sort of outage the endpoint will automatically reflect that and when the service resumes it's normal execution the next request will succeed and the upstream monitoring tool can automagically close the incident for you.

Usage

Please ensure that your deployments have a livenessProbe with the appropriate checks

First of all we need permission to list and get events, pods and deployments. For that create the required clusterrole and clusterrolebinding:

kubectl create -f config/clusterrole.yaml

A kubernetes config example to deploy this project can be found in the config directory. Remember to change your authorization token before using this in production.

kubectl create -f config/k8s-hearbeat.yaml

You can use an ingress or service to expose the deployment. In minikube run the following commands:

kubectl expose deployment k8s-heartbeat --type=NodePort --port=8080
minikube service k8s-heartbeat --url

After that you should be able to query the status with an HTTP GET or HEAD request. Let's try to get the status of the project we just deployed:

curl --head http://IP:PORT/api/healthz/default/deployment/k8s-heartbeat?token=dGVzdDp0ZXN0

In order to prevent malicious actors from disclosing private data about your cluster a Basic auth and rate limiting middleware are implemented, please check the Environment variables available.

Endpoints

The server has the following endpoints:

GET or HEAD /health - The server's own health checking

curl http://IP:PORT/healthz

GET or HEAD /api/healthz/{namespace}/deployment/{component}?token=xxx - Health check for a given deployment

curl http://IP:PORT/api/healthz/default/deployment/k8s-heartbeat?token=dGVzdDp0ZXN0

Environment variables

# the server's port
PORT=8080

# The log level for messages.
LOG_LEVEL=INFO

# Rate limiting, 3600 requests per hour
RATE_LIMIT=3600
RATE_LIMIT_PERIOD=1h

# Auth token for authorization, either send by the client via a "token" query param
# or Authorization Basic header. The server just compares the values, you may use secrets for this
# and using HTTPS is highly recommended.
AUTH_TOKEN_BASIC=

# Path to the kubernetes cluster config file, leave empty for in-cluster autodiscovery.
KUBECONFIG

k8s-controller-heartbeat's People

Contributors

mauri870 avatar

Stargazers

 avatar  avatar  avatar

Watchers

 avatar  avatar  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.