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
.
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.
- Add your logic: edit
check.js
and replace the placeholder section inmain
with your own check logic. Callclient.report(true, [])
when the check succeeds orclient.report(false, ["message"])
on failure. - Build the image: run
make build IMAGE=my-registry/my-check:tag
to build a container image containing your check. - Push the image:
make push IMAGE=my-registry/my-check:tag
. - 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 thekh-run-uuid
header.
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>
.