0Pricing
MLOps Academy · レッスン

/healthレディネスチェックを追加する

サービスがリクエストを処理できる状態になったことをオーケストレーターに知らせます。

「/healthレディネスチェックを追加する」はCoddyKit上の無料MLOps Academyレッスンです。 これはレッスン4/4です。 下記で完全なレッスンを無料で読むことができます。その後、ブラウザ内の組み込みコードエディタと24時間対応のAIチューターでハンズオン演習できます。 これはMLOps Academy学習パスの一部であり、ウェブとCoddyKitアプリ全体で進捗が同期されます。 MLOps Academyコースには全4レッスンが含まれています。

このレッスンの一部はまだ翻訳されておらず、英語で表示されています。

How Does the Cluster Know?

Orchestrators like Kubernetes need a way to ask your service: are you alive, and are you ready to take traffic? A health endpoint answers that. 🩺

Liveness vs Readiness

Liveness asks if the process is running. Readiness asks if it can actually serve requests yet. They are two different questions.

A Trivial Health Route

The simplest check is a GET /health that returns ok. If the process can reply at all, it is at least alive.

@app.get("/health")
def health():
    return {"status": "ok"}

Readiness Needs the Model

For ML, alive is not enough. A real readiness check confirms the model finished loading before you accept prediction traffic.

Check the Loaded Model

You inspect app.state to see if the model is present. If it is still None, the service is not ready yet.

ready = app.state.model is not None

Signal Not-Ready with 503

When the model is not loaded, return a 503 status so the orchestrator holds traffic back until you are ready.

from fastapi import HTTPException

raise HTTPException(status_code=503)

Put It Together

A /ready route checks the model and returns ready or raises 503. The check stays fast and free of heavy work.

@app.get("/ready")
def ready(req: Request):
    if req.app.state.model is None:
        raise HTTPException(503)
    return {"ready": True}

Wire Up the Probes

In Kubernetes you point a readinessProbe at /ready and a livenessProbe at /health. The platform polls them on a schedule.

Keep Checks Lightweight

Probes run often, so a health check must be cheap. Never run a real model inference or hit a slow database inside it.

Smooth Zero-Downtime Deploys

Readiness checks enable rolling updates: new pods only get traffic once ready, so users never hit a half-started instance. 🚦

Why It Matters

Health and readiness endpoints make your model service a good citizen in any cluster, enabling safe scaling, restarts, and deploys. ✅

Quick Check

Your model is still loading and a readiness probe hits /ready. What should the endpoint return?

Recap

You split liveness from readiness, returned 503 until the model loads, and wired probes for safe deploys. Your service is cluster-ready! 🙌

よくある質問

「/healthレディネスチェックを追加する」レッスンは無料ですか?

はい。「/healthレディネスチェックを追加する」の完全なテキストはこのウェブで無料で読めます。インタラクティブに演習し(組み込みコードエディタと24時間対応のAIチューター)、MLOps Academyコースの残りをアンロックするには、CoddyKit PROにアップグレードしてください。 MLOps Academyコースには全4レッスンが含まれています。

「/healthレディネスチェックを追加する」で何を学びますか?

サービスがリクエストを処理できる状態になったことをオーケストレーターに知らせます。 ブラウザで直接実行するハンズオンコードでMLOps Academyを演習し、24時間対応のAIチューターがレッスンを進める中での質問に答えます。

MLOps Academyを始めるのに経験は必要ですか?

事前経験は必要ありません。CoddyKitのMLOps Academyは初級者から上級者向けに構成されているため、ここから始めるか最初から始めて、自分のペースで進むことができます。 これはレッスン4/4です。

「/healthレディネスチェックを追加する」レッスンにはどのくらい時間がかかりますか?

ほとんどのCoddyKitレッスンは約5~10分かかります。各レッスンはコンパクトでインタラクティブなので、着実に進歩し、ウェブとアプリ全体で正確に前回の場所から再開できます。

このMLOps Academyレッスンでコードを書いて実行できますか?

はい。すべてのMLOps Academyレッスンに組み込みコードエディタが含まれているため、ブラウザでリアルコードを書いて実行し、即座のAIフィードバックを取得できます。ローカル設定は不要です。

このコースのすべてのレッスン

  1. 最初の/predictエンドポイント
  2. Pydanticでリクエストを検証する
  3. 起動時にモデルを一度だけ読み込む
  4. /healthレディネスチェックを追加する
← MLOps Academyに戻る