Skip to content

kuberhealthy/javascript

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

JavaScript Kuberhealthy Client

This repository contains a small client library and example external check for Kuberhealthy.

The reusable client lives in the client/ directory and is published as @kuberhealthy/client. It can be imported into your own Node.js applications to report check results back to Kuberhealthy. An example checker using the client is provided in check.js.

Client Library

The package is published to the GitHub Packages npm registry under @kuberhealthy/client.

Install it by configuring npm to use the GitHub Packages registry for the @kuberhealthy scope:

echo "@kuberhealthy:registry=https://npm.pkg.github.com" >> ~/.npmrc
npm install @kuberhealthy/client

Use the client in your code:

const { KuberhealthyClient } = require('@kuberhealthy/client');

const client = new KuberhealthyClient(process.env.KH_REPORTING_URL, process.env.KH_RUN_UUID);
await client.report(true, []);

Node.js 18 or newer is required for the built in fetch API used by the client.

Example Checker

  1. Add your logic: edit check.js and replace the placeholder section in main with your own check logic. Call client.report(true, []) when the check succeeds or client.report(false, ["message"]) on failure.
  2. Build the image: run make build IMAGE=my-registry/my-check:tag to build a container image containing your check.
  3. Push the image: make push IMAGE=my-registry/my-check:tag.
  4. Create a KuberhealthyCheck: write a khcheck resource that references your image and apply it to clusters where Kuberhealthy runs.

The check relies on two environment variables set automatically by Kuberhealthy:

  • KH_REPORTING_URL – the endpoint where status reports are posted.
  • KH_RUN_UUID – the UUID for this check run. It must be sent back in the kh-run-uuid header.

Example khcheck

apiVersion: kuberhealthy.github.io/v2
kind: KuberhealthyCheck
metadata:
  name: example-js-check
  namespace: kuberhealthy
spec:
  runInterval: 1m
  podSpec:
    containers:
      - name: check
        image: my-registry/my-check:tag

Apply the file with kubectl apply -f <file>.

About

Javascript client for Kuberhealthy

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published