🛠️ Lab 12 — Serverless and Kubernetes Model Serving, Side by Side (50 pts)
Goal: Build the same simple prediction service two ways — once as a serverless AWS Lambda function, and once as a containerized app on a local Kubernetes cluster — so you can directly compare the developer experience, scaling behavior, and operational model of each, at zero cloud cost. Steps:
- Set up AWS Lambda (free tier). Follow AWS's official "Run a Serverless Hello World with AWS Lambda" tutorial to create your first function in the console. AWS's free tier includes 1 million requests and 400,000 GB-seconds of compute per month, forever — this lab stays well within that.
- Invoke it manually. Use the Lambda console's "Test" feature to manually invoke your Hello World function with a sample event payload. Confirm you can see the execution result and the CloudWatch log output.
- Extend the function to serve a prediction. Train a tiny scikit-learn model locally (e.g., a small classifier on the Iris dataset), serialize it with
joblib, and package it as a Lambda deployment (zip or container image). Modify your handler to accept a payload of feature values, load the model, and return a JSON prediction. - Test the extended Lambda. Invoke it with two or three sample payloads and record the JSON responses.
- Install Minikube. Install Minikube (free, open source) locally and follow the official Kubernetes "Hello Minikube" tutorial to confirm your cluster starts and you can deploy a basic app with
kubectl. - Containerize a model-serving app. Reuse (or adapt) a FastAPI + scikit-learn serving app from earlier in this course. Add a
/health endpoint that returns a 200 status, and a /predict endpoint that mirrors the Lambda's prediction logic. Build it into a Docker image. - Deploy to Minikube. Write a Kubernetes Deployment manifest (with a liveness/readiness probe pointed at
/health) and a Service manifest, then apply both with kubectl apply -f. Confirm the pod reaches Running and passes its health check. - (Optional stretch) Try Knative on kind. Set up a local cluster with
kind, install Knative Serving with the Kourier networking layer, and redeploy your containerized model as a Knative Service. Observe how Knative scales your pod to zero when idle and back up on a request — serverless behavior, on your own Kubernetes cluster. - Write your comparison. In 300–400 words, compare the two approaches: What did you configure by hand in each case? Which one scaled to zero more naturally? Where did the operational burden (patching, health checks, scaling rules) fall on you versus the platform?
Deliverables: Submit your Lambda function code (with sample invocation payloads and responses), your Kubernetes manifests (Deployment + Service, and Knative YAML if attempted), a screenshot or terminal output showing your pod passing its health check, and your written comparison (300–400 words).