0Pricing
gRPC & High Performance APIs · Lekcja

Sprawdzanie stanu i sondy gotowości

Korzystaj ze standardowego protokołu sprawdzania stanu gRPC, aby load balancery i orkiestratory wiedziały, kiedy usługa jest gotowa do obsługi ruchu.

Sprawdzanie stanu i sondy gotowości to bezpłatna lekcja gRPC & High Performance APIs na CoddyKit. To lekcja 4 z 4. Możesz przeczytać całą lekcję poniżej za darmo — a potem ćwiczyć ją interaktywnie w przeglądarce z wbudowanym edytorem kodu i tutorem AI dostępnym 24/7. To część ścieżki edukacyjnej gRPC & High Performance APIs, a Twój postęp synchronizuje się między webem a aplikacją CoddyKit. Kurs gRPC & High Performance APIs zawiera 4 lekcji w sumie.

Części tej lekcji nie zostały jeszcze przetłumaczone i są wyświetlane po angielsku.

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 query
  • Watch — 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.Orders

Probing 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.Orders

Watch 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 Health service offers Check and Watch
  • Status is per-service: SERVING, NOT_SERVING, UNKNOWN
  • Map health to readiness; pair with liveness probes
  • Kubernetes and grpc_health_probe consume it
  • Flip to NOT_SERVING for graceful drain and failed dependencies

Często zadawane pytania

Czy lekcja „Sprawdzanie stanu i sondy gotowości” jest bezpłatna?

Tak — pełny tekst „Sprawdzanie stanu i sondy gotowości” jest dostępny za darmo tutaj w sieci. Aby ćwiczyć ją interaktywnie (wbudowany edytor kodu i tutor AI dostępny 24/7) i odblokować resztę kursu gRPC & High Performance APIs, przejdź na CoddyKit PRO. Kurs gRPC & High Performance APIs zawiera 4 lekcji w sumie.

Co nauczysz się w „Sprawdzanie stanu i sondy gotowości”?

Korzystaj ze standardowego protokołu sprawdzania stanu gRPC, aby load balancery i orkiestratory wiedziały, kiedy usługa jest gotowa do obsługi ruchu. Ćwiczysz gRPC & High Performance APIs z praktycznym kodem, który uruchamiasz bezpośrednio w przeglądarce, a tutor AI dostępny 24/7 odpowiada na Twoje pytania podczas pracy nad lekcją.

Czy potrzebuję doświadczenia, aby zacząć gRPC & High Performance APIs?

Nie wymagamy żadnego doświadczenia. gRPC & High Performance APIs w CoddyKit jest strukturyzowany dla początkujących i zaawansowanych użytkowników, więc możesz zacząć tutaj lub od początku i uczyć się w swoim tempie. To lekcja 4 z 4.

Ile czasu zajmuje lekcja „Sprawdzanie stanu i sondy gotowości”?

Większość lekcji CoddyKit trwa około 5–10 minut. Każda lekcja to mały, interaktywny krok, dzięki czemu robisz systematyczne postępy i zawsze wracasz dokładnie do tego samego miejsca — na webie i w aplikacji.

Czy mogę pisać i uruchamiać kod w tej lekcji gRPC & High Performance APIs?

Tak. Każda lekcja gRPC & High Performance APIs zawiera wbudowany edytor kodu, więc piszesz i uruchamiasz prawdziwy kod bezpośrednio w przeglądarce i od razu otrzymujesz sprzężenie zwrotne od AI — bez konfiguracji na komputerze.

Wszystkie lekcje w tym kursie

  1. Rejestrowanie interakcji gRPC
  2. Śledzenie za pomocą OpenTelemetry
  3. Monitorowanie metryk gRPC
  4. Sprawdzanie stanu i sondy gotowości
← Powrót do gRPC & High Performance APIs