healthcheck-k8s
Check if the specified Kubernetes node is schedulable and return as HTTP status
code.
Requirements
Installation
$ docker buildx build .
# Port number (required)
export PORT=8080
# Name of header in which client sends a node name (required)
export HEADER_NAME=X-Node
# Path to the kubeconfig, or else falls back to service account token mounted inside the Pod (optional)
export KUBECONFIG=$HOME/.kube/config
# Timeout in milliseconds (optional; zero means infinity)
export TIMEOUT_MS=30000
# IPv4/IPv6 addresses of trusted proxies in CIDR (optional; comma-separated)
export TRUSTED_PROXIES=10.0.0.0/8,172.16.0.0/12,192.168.0.0/16
Testing
Set up
$ make setup-envtest
Run
$ source <(bin/setup-envtest use latest -p env)
$ go test ./...
Usage
$ ./healthcheck-k8s
Normal: node is schedulable
$ curl --dump-header - -H 'X-Node: minikube' localhost:8080
HTTP/1.1 200 OK
Content-Type: text/plain; charset=utf-8
Date: Wed, 01 Jan 2020 00:00:00 GMT
Content-Length: 26
Node(s) are OK: "minikube"
Cordoned: node is unschedulable
$ kubectl cordon minikube
node/minikube uncordoned
$ curl --dump-header - -H 'X-Node: minikube' localhost:8080
HTTP/1.1 503 Service Unavailable
Content-Type: text/plain; charset=utf-8
Date: Wed, 01 Jan 2020 00:00:00 GMT
Content-Length: 52
Node "minikube" is currently undergoing maintenance.
Spec
Status |
Condition |
200 |
Node is schedulable. |
400 |
Header is not present in the request. |
404 |
Node was not found. |
500 |
Unexpected error when retrieving node status. |
503 |
Node is unschedulable. |
504 |
Timed out connecting to kube-apiserver. |