การตรวจสอบสุขภาพและโพรบความพร้อมใช้งาน
ใช้โพรโทคอลตรวจสอบสุขภาพ gRPC มาตรฐาน เพื่อให้ตัวกระจายโหลดและตัวจัดการระบบทราบว่าบริการพร้อมรับการรับส่งข้อมูลเมื่อใด
การตรวจสอบสุขภาพและโพรบความพร้อมใช้งาน เป็นบทเรียน gRPC & High Performance APIs ฟรีบน CoddyKit นี่คือบทเรียนที่ 4 จากทั้งหมด 4 บทเรียน คุณสามารถอ่านบทเรียนทั้งหมดด้านล่างฟรี — จากนั้นลองปฏิบัติด้วยตัวคุณเองในเบราว์เซอร์พร้อมตัวแก้ไขโค้ดในตัวและติวเตอร์ AI ตลอด 24/7 บทเรียนนี้เป็นส่วนหนึ่งของเส้นทางการเรียน gRPC & High Performance APIs และความก้าวหน้าของคุณจะซิงค์ข้ามเว็บและแอป CoddyKit คอร์ส gRPC & High Performance APIs มีบทเรียนทั้งหมด 4 บทเรียน
บางส่วนของบทเรียนนี้ยังไม่ได้รับการแปล และแสดงเป็นภาษาอังกฤษ
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
คำถามที่พบบ่อย
บทเรียน “การตรวจสอบสุขภาพและโพรบความพร้อมใช้งาน” ฟรีหรือไม่
ใช่ — ข้อความเต็มของ “การตรวจสอบสุขภาพและโพรบความพร้อมใช้งาน” ฟรีให้อ่านที่นี่บนเว็บ เพื่อปฏิบัติแบบโต้ตอบ (ตัวแก้ไขโค้ดในตัวและติวเตอร์ AI ตลอด 24/7) และปลดล็อคส่วนที่เหลือของคอร์ส gRPC & High Performance APIs ให้อัปเกรดเป็น CoddyKit PRO คอร์ส gRPC & High Performance APIs มีบทเรียนทั้งหมด 4 บทเรียน
คุณจะเรียนรู้อะไรในบทเรียน “การตรวจสอบสุขภาพและโพรบความพร้อมใช้งาน”
ใช้โพรโทคอลตรวจสอบสุขภาพ gRPC มาตรฐาน เพื่อให้ตัวกระจายโหลดและตัวจัดการระบบทราบว่าบริการพร้อมรับการรับส่งข้อมูลเมื่อใด คุณปฏิบัติ gRPC & High Performance APIs ด้วยโค้ดที่ใช้งานได้จริงที่คุณเรียกใช้โดยตรงในเบราว์เซอร์ และติวเตอร์ AI ตลอด 24/7 ตอบคำถามของคุณขณะที่คุณไปผ่านบทเรียน
คุณต้องมีประสบการณ์ก่อนที่จะเริ่มเรียน gRPC & High Performance APIs หรือไม่
ไม่จำเป็นต้องมีประสบการณ์มาก่อน gRPC & High Performance APIs บน CoddyKit ออกแบบมาสำหรับผู้เริ่มต้นไปจนถึงผู้เรียนขั้นสูง คุณสามารถเริ่มต้นที่นี่หรือเริ่มจากตัวแรกและเรียนด้วยความเร็วของคุณเอง นี่คือบทเรียนที่ 4 จากทั้งหมด 4 บทเรียน
บทเรียน “การตรวจสอบสุขภาพและโพรบความพร้อมใช้งาน” ใช้เวลานานแค่ไหน
บทเรียน CoddyKit ส่วนใหญ่ใช้เวลาประมาณ 5–10 นาที แต่ละบทเรียนจึงสั้นและเป็นแบบโต้ตอบ คุณสามารถก้าวหน้าอย่างต่อเนื่องและกลับมาเรียนต่อจากตรงที่เพิ่งหยุดบนเว็บและแอปได้เลย
ฉันเขียนและรันโค้ดในบทเรียน gRPC & High Performance APIs นี้ได้ไหม
ได้ บทเรียน gRPC & High Performance APIs ทุกบทมีตัวแก้ไขโค้ดในตัว คุณจึงเขียนและรันโค้ดจริงได้เลยในเบราว์เซอร์ และได้รับข้อเสนอแนะจาก AI ในทันที — ไม่ต้องติดตั้งในเครื่องของคุณ
บทเรียนทั้งหมดในหลักสูตรนี้
- การบันทึกการโต้ตอบกับ gRPC
- การติดตามด้วย OpenTelemetry
- การตรวจสอบเมตริก gRPC
- การตรวจสอบสุขภาพและโพรบความพร้อมใช้งาน