Deployment reliability and degraded mode
Separate startup, liveness and readiness
Startup asks whether initialization has completed. Liveness asks whether the process can make progress; readiness asks whether the service can accept traffic now. A Kubernetes startup probe can delay the other probes until initialization succeeds; a readiness failure removes the workload from matching service traffic rather than automatically restarting it [4]. Avoid tying liveness to a remote model outage: this can cause restart loops. A service may remain ready in an explicitly supported degraded mode. In this toy health function the application is live only after startup and while responsive. It is ready only when accepting traffic and either its model or its approved fallback is available. The sample reports normal, degraded and draining/offline states. During actual startup, use the platform startup probe to prevent premature liveness checks; probe cadence and thresholds require measured tuning.
def health(started, responsive, model_loaded, accepting, fallback_ready): # Trusted boolean observations supplied by the host. if not all(type(v) is bool for v in (started, responsive, model_loaded, accepting, fallback_ready)): raise ValueError("boolean observations required") live = started and responsive ready = live and accepting and (model_loaded or fallback_ready) return {"live": live, "ready": ready, "mode": ("model" if model_loaded else "degraded") if ready else "offline"}
print(health(True, True, True, True, False))print(health(True, True, False, True, True))print(health(True, True, True, False, True))Deploy with bounded infrastructure
A Docker image packages application code and dependencies, not a proof of isolation. Build from a trusted, pinned base, review dependencies, run as a non-root user, apply CPU/memory and process limits, and avoid privileged containers, broad host mounts and the host Docker socket [5]. Inject secrets through an approved secret store and avoid embedding credentials in images or logs. Kubernetes can manage replicas, service routing, resource requests/limits, health probes and rolling updates; do not presume a GPU is available just because a deployment requests it. Hosted/cloud services need approved identity, network boundaries, regional data policy and billing limits. Local and edge installations need update signing, monitoring, and a safe offline policy. No container, cluster or cloud resource is started in this lesson. The ByteMind Docker, Kubernetes and Cloud Computing prompts are related tracks; live route links are unavailable.
Implement an explicit degraded contract
Degraded mode is an intentional smaller service, not a fabricated normal result. For a catalog tag request, a trusted existing tag may be returned instead of new model inference, with status degraded and source catalog. A tenant-scoped lookup must occur before passing known_tag to this function; a denied request returns no tag even when the caller already supplied a candidate. A model result must be one of two allowed labels; malformed or missing output is treated as unusable. Offline mode never returns a tag. A missing fallback yields unavailable rather than a guess. The example assumes the fallback has been approved and is available when mode is model or degraded; in an actual service pass a separate availability flag or a missing value. This is a local response classifier, not an authorization mechanism or a deployed service.
def serve(authorized, mode, known_tag, model_result): # Only a trusted, tenant-scoped catalog tag may be returned in degraded mode. tags = {"kitchen", "other"} if not authorized: return {"status": "denied", "tag": None, "source": None} if mode == "model" and type(model_result) is str and model_result in tags: return {"status": "complete", "tag": model_result, "source": "mock_model"} if mode in ("model", "degraded") and type(known_tag) is str and known_tag in tags: return {"status": "degraded", "tag": known_tag, "source": "catalog"} return {"status": "unavailable", "tag": None, "source": None}
print(serve(True, "model", "other", "kitchen"))print(serve(True, "degraded", "other", None))print(serve(False, "degraded", "other", None))print(serve(True, "degraded", None, None))Observe failures and roll back safely
Record request IDs, contract and model versions, safe tenant pseudonyms where necessary, duration, queue depth, outcome, degraded fraction, timeouts and resource use. Keep raw prompts and secrets out of general logs. Sample traces under retention and access policies. Establish a known-good version before rollout; compare a small canary on the same quality suite and operational thresholds. If failure or latency exceeds a declared limit, stop promotion, drain safely and switch back only to a compatible, approved version. Include schema migrations and queue payload compatibility in rollback planning. If no approved version is available, disable inference and use only the authorized reduced contract or an unavailable response. Track degraded output separately so healthy uptime does not hide loss of AI quality. Use human review for unresolved cases and document recovery evidence before restoring full traffic.
Practice failure recovery
Run the health example with startup incomplete, an unresponsive process and a draining service. Confirm a model outage with fallback available produces ready/degraded while an outage without fallback produces unready. Test the response example with malformed tags, unauthorized tenants and unknown modes; verify no hidden tag is returned on denial. Sketch a rollback checklist including version, compatibility, approval, drain, trace review and revalidation. A ready flag is not proof of model quality; a successful fallback is not equivalent to new inference. The worksheet uses fixed mock values and never writes to a catalog. Actual REST/gRPC transport, container isolation, live concurrency, authorization and cancellation behavior require separate approved integration tests.
Check Your Understanding
Solidify your learning with the interactive assessment directly below this lesson.
Concept Quiz & Questions
Deployment reliability and degraded mode quiz
Assess integration contracts, deadlines, health, fallback and rollback.
What does a readiness failure normally affect in Kubernetes?
What is returned for an unauthorized request even with a known tag?
Why label catalog fallback as degraded?
What should happen before rolling back?
Which signal should be tracked separately from normal success?