-
Notifications
You must be signed in to change notification settings - Fork 35
Module 7.md
This module demonstrates a simple CI/CD pipeline for deploying ML services using GitHub Actions and Kubernetes. You'll learn how to automatically build Docker images when code changes and deploy them to your local kind cluster.
What You'll Learn:
- Building Docker containers in CI/CD pipelines
- Pushing images to GitHub Container Registry
- Deploying to Kubernetes
- Separating CI (build) from CD (deploy)
Before starting, ensure you have:
- GitHub Account - For running GitHub Actions
- GitHub CLI (gh) - Install here
- Docker Desktop
- kubectl
- kind
cd modules/module-7
./setup-simple.shThis script will:
- ✓ Check all prerequisites
- ✓ Verify kind cluster is running
- ✓ Confirm Git repository is initialized
If you haven't already, create a GitHub repository:
gh repo create ml-con-workshop --public --source=. --remote=origingit add .
git commit -m "Add CI/CD workflow"
git push origin mainMonitor the build process:
# Watch in terminal
gh run watch
# Or open in browser
gh run view --webThe workflow will:
- Build the ML service Docker image
- Build the API gateway Docker image
- Push both images to GitHub Container Registry (ghcr.io)
- Output deployment instructions
After the workflow completes successfully, follow the deployment instructions shown in the GitHub Actions summary. They'll look like this:
# 1. Pull images from GitHub Container Registry
docker pull ghcr.io/<your-username>/ml-con-workshop/sentiment-api:main-abc1234
docker pull ghcr.io/<your-username>/ml-con-workshop/api-gateway:main-abc1234
# 2. Load images into kind cluster
kind load docker-image ghcr.io/<your-username>/ml-con-workshop/sentiment-api:main-abc1234 --name mlops-workshop
kind load docker-image ghcr.io/<your-username>/ml-con-workshop/api-gateway:main-abc1234 --name mlops-workshop
# 3. Update Kubernetes manifests with new image tags
cd modules/module-7/k8s
sed -i.bak "s|image:.*sentiment-api.*|image: ghcr.io/<your-username>/ml-con-workshop/sentiment-api:main-abc1234|" ml-service.yaml
sed -i.bak "s|image:.*api-gateway.*|image: ghcr.io/<your-username>/ml-con-workshop/api-gateway:main-abc1234|" api-gateway.yaml
# 4. Deploy to Kubernetes
kubectl apply -f modules/module-7/k8s/
# 5. Wait for rollout to complete
kubectl rollout status deployment/sentiment-api --timeout=5m
kubectl rollout status deployment/api-gateway --timeout=5m# Check pods are running
kubectl get pods
# Test health endpoint
curl http://localhost:30080/health
# Test sentiment analysis
curl -X POST http://localhost:30080/predict \
-H "Content-Type: application/json" \
-d '{"request": {"text": "This workshop is amazing!"}}'Expected response:
{
"sentiment": "POSITIVE",
"score": 0.9998,
"text": "This workshop is amazing!"
}The .github/workflows/mlops-simple.yaml file defines three jobs:
- Checks out code
- Installs BentoML
- Builds Bento package
- Containerizes with Docker
- Pushes to ghcr.io
- Checks out code
- Builds Go Docker image
- Pushes to ghcr.io
- Outputs commands for manual deployment
- Includes image tags with commit SHA
GitHub Actions runners cannot access your local kind cluster, so the deployment step is manual. In production, you'd use:
- ArgoCD or Flux for GitOps
- Cloud-hosted clusters (EKS, GKE, AKS) accessible from GitHub Actions
- Self-hosted runners with cluster access
Images are tagged with format: {branch}-{short-sha}
Example: main-a1b2c3d
This provides:
- Traceability: Know exactly which commit is deployed
- Uniqueness: Each build has a unique tag
- Readability: Short SHA is easier to work with
After completing this module, you can:
- Modify the Services - Make changes to ML service or gateway
- Push to GitHub - Watch CI/CD automatically rebuild
- Deploy Updates - Follow deployment instructions again
- Add Testing - Extend workflow with unit tests
- Add Monitoring - Integrate with Module 6 (Prometheus/Grafana)
This is a simplified demo. For production, add:
- Automated testing (unit tests, integration tests, linting)
- Security scanning (Trivy, Snyk for vulnerabilities)
- Multi-environment deployments (dev, staging, production)
- Approval gates for production deployments
- Rollback strategies (automated on failure)
- Notifications (Slack, email on build/deploy status)
- GitOps (ArgoCD or Flux for automated deployments)
- Service mesh (Istio, Linkerd for advanced traffic management)
- GitHub Actions Documentation
- Kubernetes Documentation
- kind Documentation
- BentoML Documentation
- Docker Documentation
You've learned:
- ✅ How to build Docker images in GitHub Actions
- ✅ How to push images to GitHub Container Registry
- ✅ How to deploy to Kubernetes
- ✅ How to separate CI (automated) from CD (manual)
- ✅ How to tag images for traceability
This foundation prepares you for more advanced CI/CD patterns used in production MLOps systems!
| Previous | Home | Completion |
|---|---|---|
| ← Module 6: Monitoring & Observability | 🏠 Home | 🎉 Workshop Complete! |
MLOps Workshop | GitHub Repository