This tool can still be useful if you are on older versions of Kubernetes,
or using advanced configuration (such as custom metadata, TLS or finer timeout tuning),
or not using Kubernetes at all.
This command-line utility makes a RPC to /grpc.health.v1.Health/Check. If it
responds with a SERVING status, the grpc_health_probe will exit with
success, otherwise it will exit with a non-zero exit code (documented below).
$ grpc_health_probe -addr=localhost:9999 -connect-timeout 250ms -rpc-timeout 100ms
failed to connect service at "localhost:9999": context deadline exceeded
exit status 2
Installation
It is recommended to use a version-stamped binary distribution:
Run: go get github.com/grpc-ecosystem/grpc-health-probe
This will compile the binary into your $GOPATH/bin (or $HOME/go/bin).
Using the gRPC Health Checking Protocol
To make use of the grpc_health_probe, your application must implement the
gRPC Health Checking Protocol v1. This means you must to register the
Health service and implement the rpc Check that returns a SERVING status.
Since the Health Checking protocol is part of the gRPC core, it has
packages/libraries available for the languages supported by gRPC:
Most of the languages listed above provide helper functions that hides
implementation details. This eliminates the need for you to implement the
Check rpc yourself.
Example: gRPC health checking on Kubernetes
Kubernetes does not natively support gRPC health checking since it does not
favor one RPC framework over another. Similarly, HTTP health probes Kubernetes
has is not sufficient to craft a valid gRPC request. As a solution,
grpc_health_probecan be used for Kubernetes to health-check gRPC
servers running in the Pod.
You are recommended to use Kubernetes exec probes and define
liveness and/or readiness checks for your gRPC server pods.
You can bundle the statically compiled grpc_health_probe in your container
image. Choose a binary release and download it in your Dockerfile:
This approach provide proper readiness/liveness checking to your applications
that implement the gRPC Health Checking Protocol.
Health Checking TLS Servers
If a gRPC server is serving traffic over TLS, or uses TLS client authentication
to authorize clients, you can still use grpc_health_probe to check health
with command-line options:
Option
Description
-tls
use TLS (default: false)
-tls-ca-cert
path to file containing CA certificates (to override system root CAs)
-tls-client-cert
client certificate for authenticating to the server
-tls-client-key
private key for for authenticating to the server
-tls-no-verify
use TLS, but do not verify the certificate presented by the server (INSECURE) (default: false)
-tls-server-name
override the hostname used to verify the server certificate
Health checking TLS Servers with SPIFFE issued credentials
If your gRPC server requires authentication, you can use the following command line options and set the
SPIFFE_ENDPOINT_SOCKET
environment variable.
请发表评论