Skip to content

ziraddingulumjanly/Docker-and-Kubernetes-Container

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Let's assume the scenarios where we are given Project:

  1. Create a customized Docker container from the current version of Python that deploys a Python ML application.
  2. Push the image to DockerHub, Amazon ECR, Google Container Registry, or some other Cloud Container Registry.
  3. Pull the image down and run it on a cloud platform cloud shell: Google Cloud Shell or AWS Cloud9.
  4. Deploy an application to a cloud-managed Kubernetes cluster, like GKE (Google Kubernetes Engine), or EKS (Elastic Kubernetes Service), etc

Acknowledgment

This project is inspired by the portfolio guidance in:

Gift, N., & Deza, A. (2021). Practical MLOps: Operationalizing Machine Learning Models. O'Reilly Media.

Specifically adapted from Appendix E: "Building a Technical Portfolio for MLOps".

Diabetes Classic ML Service (Docker + K8s + CI/CD)

Minimal portfolio project:

  • Classic ML artifact (sklearn pipeline) saved as artifacts/model.joblib
  • FastAPI inference service
  • Docker image build/push
  • Kubernetes deploy (Deployment + LoadBalancer Service)
  • GitHub Actions CI/CD: build → push → rollout

1) Local: create model artifact

This repo expects artifacts/model.joblib.

Option A (recommended): create it via the included training script:

python -m venv .venv
source .venv/bin/activate  # Windows: .venv\Scripts\activate
pip install -r requirements.txt

python scripts/train.py

2) Local: run API

uvicorn app:app --host 0.0.0.0 --port 8000
curl http://localhost:8000/healthz

Predict:

curl -X POST http://localhost:8000/predict \
  -H "Content-Type: application/json" \
  -d '{
    "Pregnancies": 2,
    "Glucose": 120,
    "BloodPressure": 70,
    "SkinThickness": 20,
    "Insulin": 85,
    "BMI": 30.5,
    "DiabetesPedigreeFunction": 0.35,
    "Age": 33
  }'

3) Docker

docker build -t diabetes-ml:local .
docker run --rm -p 8000:8000 diabetes-ml:local

4) Push to DockerHub

docker login
docker tag diabetes-ml:local <DOCKERHUB_USERNAME>/diabetes-ml:1.0.0
docker push <DOCKERHUB_USERNAME>/diabetes-ml:1.0.0

5) Kubernetes deploy

Edit k8s/deployment.yaml image field:

  • image: <DOCKERHUB_USERNAME>/diabetes-ml:1.0.0

Apply:

kubectl apply -f k8s/deployment.yaml
kubectl apply -f k8s/service.yaml
kubectl get svc diabetes-ml-svc

6) CI/CD (GitHub Actions)

Add GitHub repo secrets:

  • DOCKERHUB_USERNAME
  • DOCKERHUB_TOKEN (DockerHub access token)
  • KUBE_CONFIG (base64 kubeconfig)

Create kubeconfig secret:

cat ~/.kube/config | base64

Workflow file: .github/workflows/ci-cd.yml On each push to main, it:

  • Builds image tagged with commit SHA
  • Pushes to DockerHub
  • Applies manifests
  • Updates deployment image (rolling update)

About

Production-ready ML inference service with Docker, Kubernetes, and GitHub Actions CI/CD pipeline.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors