This guide covers various deployment options for the Iris Flower Classification API.
# Install dependencies
make install-dev
# Run the API
make api
The API will be available at http://localhost:8000
# Create virtual environment
python -m venv venv
source venv/bin/activate # On Windows: venv\Scripts\activate
# Install dependencies
pip install -r requirements.txt
pip install -r requirements-api.txt
# Run the API
uvicorn iris_classifier.api:app --reload
# Build the Docker image
make docker-build
# Run the container
make docker-run
Or manually:
docker build -t iris-classifier:latest .
docker run -d -p 8000:8000 --name iris-api iris-classifier:latest
Create a .env file:
cp .env.example .env
# Edit .env with your configuration
Run with environment file:
docker run -d -p 8000:8000 --env-file .env iris-classifier:latest
Docker Compose provides a complete stack with monitoring.
make docker-compose-up
This starts:
# Start services
docker-compose up -d
# Stop services
docker-compose down
# View logs
docker-compose logs -f api
# Restart a service
docker-compose restart api
# Scale the API
docker-compose up -d --scale api=3
# Create namespace
kubectl create namespace iris-classifier
# Apply all configurations
kubectl apply -f k8s/ -n iris-classifier
# Check deployment status
kubectl get pods -n iris-classifier
kubectl get svc -n iris-classifier
# Deploy configuration
kubectl apply -f k8s/configmap.yaml -n iris-classifier
kubectl apply -f k8s/secret.yaml -n iris-classifier
# Deploy storage
kubectl apply -f k8s/pvc.yaml -n iris-classifier
# Deploy application
kubectl apply -f k8s/deployment.yaml -n iris-classifier
kubectl apply -f k8s/service.yaml -n iris-classifier
# Deploy autoscaling
kubectl apply -f k8s/hpa.yaml -n iris-classifier
# Deploy ingress (optional)
kubectl apply -f k8s/ingress.yaml -n iris-classifier
# Update image
kubectl set image deployment/iris-classifier-api \
api=iris-classifier:v2.1.0 -n iris-classifier
# Rollout status
kubectl rollout status deployment/iris-classifier-api -n iris-classifier
# Rollback if needed
kubectl rollout undo deployment/iris-classifier-api -n iris-classifier
# Manual scaling
kubectl scale deployment iris-classifier-api --replicas=5 -n iris-classifier
# Check HPA status
kubectl get hpa -n iris-classifier
# View logs
kubectl logs -f deployment/iris-classifier-api -n iris-classifier
# View metrics
kubectl top pods -n iris-classifier
kubectl top nodes
# Port forward for local access
kubectl port-forward svc/iris-classifier-api 8000:80 -n iris-classifier
# Build and push to ECR
aws ecr get-login-password --region us-east-1 | docker login --username AWS --password-stdin <account-id>.dkr.ecr.us-east-1.amazonaws.com
docker tag iris-classifier:latest <account-id>.dkr.ecr.us-east-1.amazonaws.com/iris-classifier:latest
docker push <account-id>.dkr.ecr.us-east-1.amazonaws.com/iris-classifier:latest
# Deploy using ECS CLI or Console
# Build and push to GCR
gcloud builds submit --tag gcr.io/PROJECT_ID/iris-classifier
# Deploy to Cloud Run
gcloud run deploy iris-classifier \
--image gcr.io/PROJECT_ID/iris-classifier \
--platform managed \
--region us-central1 \
--allow-unauthenticated \
--memory 512Mi \
--cpu 1
# Build and push to ACR
az acr build --registry <registry-name> --image iris-classifier:latest .
# Deploy to ACI
az container create \
--resource-group <resource-group> \
--name iris-classifier \
--image <registry-name>.azurecr.io/iris-classifier:latest \
--cpu 1 --memory 1 \
--registry-login-server <registry-name>.azurecr.io \
--registry-username <username> \
--registry-password <password> \
--dns-name-label iris-classifier \
--ports 8000
Prometheus scrapes metrics from /metrics endpoint.
Configuration in monitoring/prometheus.yml:
scrape_configs:
- job_name: 'iris-api'
static_configs:
- targets: ['api:8000']
Access Prometheus at http://localhost:9090
monitoring/grafana/dashboards/iris_predictions_total: Total predictionsiris_prediction_duration_seconds: Prediction latencyiris_errors_total: Error countmake security)make load-test)# Check container logs
docker logs iris-api
# Check Kubernetes pods
kubectl logs deployment/iris-classifier-api -n iris-classifier
# Check health endpoint
curl http://localhost:8000/health
MODEL_CACHE_SIZE in configurationFor issues and questions: