This repository provides a minimal Java client for reporting check results to Kuberhealthy and an example check that uses it. The ExampleCheck
program reads the KH_REPORTING_URL
and KH_RUN_UUID
environment variables that Kuberhealthy injects into checker pods and posts a JSON status report.
Applications can depend on the client published to GitHub Packages:
<dependency>
<groupId>io.kuberhealthy</groupId>
<artifactId>kuberhealthy-client</artifactId>
<version>0.1.0-SNAPSHOT</version>
</dependency>
Add https://maven.pkg.github.com/OWNER/REPO
as a Maven repository and authenticate with a GitHub token that has permission to read packages.
Within your code, create a KuberhealthyClient
and call report
:
import io.kuberhealthy.client.KuberhealthyClient;
KuberhealthyClient client = new KuberhealthyClient(url, uuid);
client.report(true, "");
Add your own logic inside ExampleCheck.java
before reporting the result. The file defaults to reporting success and includes commented-out lines that show how to report a failure:
// ok = false;
// error = "something went wrong";
Call report
with ok=true
when the check succeeds or ok=false
with an error message when it fails. Non-200 responses from Kuberhealthy cause the program to exit with an error so rejected payloads surface immediately.
Build and push the container image:
make build IMAGE=registry.example.com/java-example:latest
make push IMAGE=registry.example.com/java-example:latest
Create a KuberhealthyCheck
that uses the pushed image:
apiVersion: khcheck.kuberhealthy.io/v1
kind: KuberhealthyCheck
metadata:
name: java-example
spec:
runInterval: 15m
timeout: 5m
podSpec:
containers:
- name: checker
image: registry.example.com/java-example:latest
imagePullPolicy: Always
Apply the manifest to a cluster running Kuberhealthy:
kubectl apply -f khcheck.yaml
The pod will receive the required KH_REPORTING_URL
and KH_RUN_UUID
variables and the check will report success or failure back to Kuberhealthy.