الفلاتر
طريقة البحث
  • الكلمات العادية تجد الأسماء والنصوص والأمثلة.
  • "كلمتان" تجد العبارة بالضبط.
  • --name أو -x تجد خيارًا.
  • #كلمة تبحث داخل الأوامر فقط.
  • @grep تجد الدروس والمعامل التي تستخدم grep.
  • الفلاتر: cat:network · in:labs · level:rhcsa · ch:8 · root:yes. ضع ! قبل كلمة لاستبعادها. OR بين الكلمات تعني إحداها.
  • ↑ ↓ للتنقل · Enter للفتح · Esc للإغلاق · / للبحث

الفصل 5الاسم في الدورة: Model deployment and serving

Serve models as APIs

A model is useful when applications can call it. Package it in a container with a small API (FastAPI), or use a serving platform (KServe) that adds autoscaling, canary releases and GPU scheduling on Kubernetes.

  • 5 الدروس
  • 2 الأوامر

هذا الجزء لم يُترجم بعد. أنت ترى النص الإنجليزي.

$ مستخدم عادي# بصلاحية root (أو مع sudo)

5.1

Build a model API

Load the model once at start, validate input, return predictions.

app.py
from fastapi import FastAPI
from pydantic import BaseModel
import joblib
 
app = FastAPI()
model = joblib.load("model.joblib")
 
 
class Flower(BaseModel):
    features: list[float]
 
 
@app.get("/health")
def health():
    return {"status": "ok"}
 
 
@app.post("/predict")
def predict(f: Flower):
    return {"class": int(model.predict([f.features])[0])}
pip install fastapi uvicorn scikit-learn joblib
uvicorn app:app --host 0.0.0.0 --port 8080
curl -s -X POST localhost:8080/predict -H 'Content-Type: application/json' -d '{"features": [5.1, 3.5, 1.4, 0.2]}'
{"class":0}

الأوامر في هذا الدرس

5.2

Package it in a container

The same rules as any image: small base, non-root, pinned packages, health check.

Dockerfile
FROM python:3.12-slim
WORKDIR /app
COPY requirements.txt .
RUN pip install --no-cache-dir -r requirements.txt
COPY app.py model.joblib ./
USER 1001
EXPOSE 8080
CMD ["uvicorn", "app:app", "--host", "0.0.0.0", "--port", "8080"]

5.3

Choose online or batch

Not every model needs a live API.

ModeWhenHow
Online (real time)An app needs an answer nowAPI behind a load balancer, autoscaling
BatchScore many rows every nightA job (CronJob, pipeline step) writes results to a table
StreamingEvents one by oneA consumer on Kafka / Event Hubs

5.4

Serve on Kubernetes with KServe

An InferenceService object gives a model an endpoint with autoscaling (also to zero) and canary rollout.

inference.yaml
apiVersion: serving.kserve.io/v1beta1
kind: InferenceService
metadata:
  name: iris
  namespace: models
spec:
  predictor:
    model:
      modelFormat: { name: sklearn }
      storageUri: "s3://models/iris/v3"
      resources:
        limits: { cpu: "1", memory: 1Gi }
kubectl apply -f inference.yaml
kubectl get inferenceservice iris -n models

الأوامر في هذا الدرس

5.5

Release models safely

Use the same release patterns as for apps.

PatternUse
ShadowThe new model gets copies of real requests; answers are only logged
Canary5 – 10 % of traffic goes to the new model, then more
A/B testTwo models compared on a business metric
RollbackSwitch the alias / traffic back to the old version

كل الأوامر في هذا الفصل