By Fatskills Exam Guides Team — the exam nerds behind 28,500+ quizzes and 2.1M practice questions across 500+ global exams.
Containerization bundles your code, runtime, libraries, and system tools into a portable image that runs the same everywhere—your laptop, a cloud VM, or a CI/CD server. Orchestration (e.g., Kubernetes) then schedules those containers, scales them, and keeps them healthy. For a data‑science team this means a churn‑prediction model can be trained locally, packaged once, and deployed to a production API that serves millions of requests without “it works on my machine” bugs.
RUN pip install …
docker build -t mymodel:1.0 .
.
mymodel:1.0
docker run -p 8080:80 mymodel:1.0
desiredReplicas = ceil(currentCPUUtilization / targetCPUUtilization * currentReplicas)
kubectl apply -f deployment.yaml
mlflow models build-docker -m run_id -n mymodel:latest
ENTRYPOINT ["python", "serve.py"]
resources: limits: cpu: "2"
maxUnavailable
python # train.py import pandas as pd, joblib, sklearn df = pd.read_csv('train.csv') X, y = df.drop('target', axis=1), df['target'] model = sklearn.ensemble.RandomForestClassifier(n_estimators=200) model.fit(X, y) joblib.dump(model, 'model.pkl')
Dockerfile FROM python:3.11-slim WORKDIR /app COPY requirements.txt . RUN pip install -r requirements.txt COPY model.pkl serve.py . ENTRYPOINT ["python", "serve.py"]
bash docker build -t churn-model:0.1 . docker run -p 8000:8000 churn-model:0.1 # hit http://localhost:8000/predict
bash docker tag churn-model:0.1 myrepo/churn-model:0.1 docker push myrepo/churn-model:0.1
yaml apiVersion: apps/v1 kind: Deployment metadata: name: churn-svc spec: replicas: 2 selector: matchLabels: {app: churn} template: metadata: labels: {app: churn} spec: containers: - name: churn image: myrepo/churn-model:0.1 ports: [{containerPort: 8000}] resources: limits: {cpu: "1", memory: "1Gi"}
bash kubectl apply -f deployment.yaml kubectl autoscale deployment churn-svc --cpu-percent=70 --min=2 --max=10
/home/user/model.pkl
COPY
requirements.txt
readinessProbe
livenessProbe
/health
RUN useradd -m mluser && USER mluser
uvicorn --host 0.0.0.0 --port 8000 serve:app
EXPOSE 8000
Scenario: Your model server crashes after a few requests, but the Docker image runs fine locally. Answer: Check Kubernetes livenessProbe and resource limits; the pod may be OOM‑killed because the memory limit is too low.
Scenario: You need to roll out a new model version without downtime. Answer: Use a RollingUpdate Deployment with maxSurge: 1 and maxUnavailable: 0 so a new pod starts before the old one stops.
maxSurge: 1
maxUnavailable: 0
Scenario: A teammate asks why the model predictions differ between dev and prod. Answer: Likely a dependency version mismatch; containers guarantee identical libraries, eliminating this source of drift.
RUN
docker exec -it <container> bash
ENTRYPOINT
CMD
kubectl rollout status deployment/<name>
EXPOSE
-p host:container
resources.limits
resources.requests
mlflow models build-docker
docker prune -a
Join 4M+ learners. Unlock unlimited quizzes, wrong-answer tracking, flashcards + reminders, study guides, and 1-on-1 challenges.