Controlli di integrità e probe di readiness
Utilizzi il protocollo standard di health checking di gRPC, così bilanciatori del carico e orchestratori sanno quando un servizio è pronto a gestire il traffico.
Controlli di integrità e probe di readiness è una lezione gRPC & High Performance APIs gratuita su CoddyKit. Questa è la lezione 4 di 4. Puoi leggere la lezione completa qui gratuitamente — poi esercitati direttamente nel browser con un editor di codice integrato e un tutor IA disponibile 24/7. Fa parte del percorso di apprendimento gRPC & High Performance APIs, e i tuoi progressi si sincronizzano tra il web e l'app CoddyKit. Il corso gRPC & High Performance APIs include 4 lezioni in totale.
Parti di questa lezione non sono ancora state tradotte e vengono mostrate in inglese.
Why Health Checks Matter
An orchestrator must know whether a service instance can handle requests. Sending traffic to a starting, overloaded, or broken instance causes errors.
The gRPC health checking protocol answers: is this service healthy?
The Standard Health Service
gRPC defines grpc.health.v1.Health with two methods:
Check— a one-shot status queryWatch— a stream of status updates
Status is SERVING, NOT_SERVING, or UNKNOWN.
Per-Service Status
A health request names a service. An empty name asks about the whole server; a specific name asks about one service, so you can report each independently.
Registering the Health Server (Go)
The health package provides a ready implementation you register on your server.
import 'google.golang.org/grpc/health'
import hpb 'google.golang.org/grpc/health/grpc_health_v1'
hs := health.NewServer()
hpb.RegisterHealthServer(s, hs)Setting Status
Update status as your service transitions. Mark NOT_SERVING during startup or shutdown, then SERVING when ready.
hs.SetServingStatus('', hpb.HealthCheckResponse_SERVING)
hs.SetServingStatus('my.pkg.Orders', hpb.HealthCheckResponse_SERVING)Readiness vs Liveness
Two distinct ideas:
- Liveness: is the process alive? Restart if not.
- Readiness: can it serve now? Remove from rotation if not, but do not restart.
Health status maps cleanly to readiness.
Kubernetes gRPC Probes
Kubernetes supports native gRPC probes. Point them at your health service.
readinessProbe:
grpc:
port: 9090
service: my.pkg.OrdersProbing with grpc_health_probe
The grpc_health_probe binary lets you check health from a shell or older Kubernetes versions.
grpc_health_probe -addr=localhost:9090 -service=my.pkg.OrdersWatch for Live Updates
Smart load balancers use Watch to receive a stream of status changes, reacting instantly when an instance flips to NOT_SERVING instead of polling.
Graceful Shutdown
Before stopping, set status to NOT_SERVING and wait. Load balancers drain you out, in-flight requests finish, and clients avoid hitting a dying instance.
Tying Health to Dependencies
Report NOT_SERVING when a critical dependency (database, cache) is unreachable, so traffic routes only to instances that can actually do work.
Quick Check
Test your health-check knowledge.
Recap
You learned gRPC health checking:
- The standard
Healthservice offersCheckandWatch - Status is per-service:
SERVING,NOT_SERVING,UNKNOWN - Map health to readiness; pair with liveness probes
- Kubernetes and
grpc_health_probeconsume it - Flip to
NOT_SERVINGfor graceful drain and failed dependencies
Domande Frequenti
La lezione «Controlli di integrità e probe di readiness» è gratuita?
Sì — il testo completo di «Controlli di integrità e probe di readiness» è gratuito qui sul web. Per esercitarvi in modo interattivo (un editor di codice integrato e un tutor IA 24/7) e sbloccare il resto del corso gRPC & High Performance APIs, passa a CoddyKit PRO. Il corso gRPC & High Performance APIs include 4 lezioni in totale.
Cosa imparerò in «Controlli di integrità e probe di readiness»?
Utilizzi il protocollo standard di health checking di gRPC, così bilanciatori del carico e orchestratori sanno quando un servizio è pronto a gestire il traffico. Eserciti gRPC & High Performance APIs con codice pratico che esegui direttamente nel browser, e un tutor IA 24/7 risponde alle tue domande mentre lavori sulla lezione.
Ho bisogno di esperienza per iniziare gRPC & High Performance APIs?
Non è richiesta alcuna esperienza precedente. gRPC & High Performance APIs su CoddyKit è strutturato per principianti e studenti avanzati, quindi puoi iniziare da qui o dall'inizio e procedere al tuo ritmo. Questa è la lezione 4 di 4.
Quanto tempo richiede la lezione «Controlli di integrità e probe di readiness»?
La maggior parte delle lezioni CoddyKit richiede circa 5–10 minuti. Ogni lezione è breve e interattiva, quindi fai progressi costanti e riprendi esattamente da dove hai lasciato su web e app.
Posso scrivere ed eseguire codice in questa lezione gRPC & High Performance APIs?
Sì. Ogni lezione gRPC & High Performance APIs include un editor di codice integrato, quindi scrivi ed esegui codice reale direttamente nel tuo browser e ricevi feedback istantaneo dall'IA — nessuna configurazione locale necessaria.
Tutte le lezioni di questo corso
- Logging delle interazioni gRPC
- Tracing con OpenTelemetry
- Monitoraggio delle metriche gRPC
- Controlli di integrità e probe di readiness