Skip to content

Prediction Container Deployment

Arsalan edited this page Sep 11, 2025 · 2 revisions

Prediction Container Deployment

Overview

This page documents the prediction endpoint container added to the Avatar Kubernetes deployment as part of PR #308 to address issue #36.

Components Added

  • Prediction container running on port 5000
  • Nginx ConfigMap for reverse proxy routing
  • Updated k8s.yaml with container and volume configurations

Container Details

  • Image: docker.io/jdknuds/prediction:latest
  • Port: 5000
  • Name: prediction-pod
  • Endpoints:
    • /eegrandomforestprediction (POST) - Submit EEG data for prediction
    • /lastprediction (GET) - Retrieve most recent prediction

Production Configuration

WSGI Server

The prediction container uses gunicorn as the production WSGI server instead of Flask's development server for improved performance and reliability.

Gunicorn Configuration:

  • Workers: 2 worker processes
  • Binding: 0.0.0.0:5000 (all interfaces)
  • Command: gunicorn --bind 0.0.0.0:5000 --workers 2 server.server:app

This configuration provides better concurrent request handling and follows production deployment best practices for Python web applications.

Deployment Instructions

  1. Apply the ConfigMap first: kubectl apply -f nginx-configmap.yaml
  2. Apply the main pod: kubectl apply -f k8s.yaml
  3. Verify containers are running: kubectl get pods

Architecture

The nginx container acts as a reverse proxy, routing:

  • Default traffic (/) → Jupyter service (port 8888)
  • Prediction requests → Prediction service (port 5000)

All prediction requests are automatically routed through nginx to the gunicorn-powered prediction service, ensuring proper load balancing and production-ready deployment.

Files Modified

  • server/devops/deployment/k8s.yaml - Added prediction container with gunicorn command and nginx volume mount
  • server/devops/deployment/nginx-configmap.yaml - New ConfigMap for nginx configuration
  • server/devops/nginx/nginx.conf - Nginx reverse proxy configuration

Technical Implementation

The implementation includes:

  • Kubernetes pod configuration with 4 containers (Jupyter, Nginx, Prediction, Rust)
  • ConfigMap-based nginx configuration for flexible routing
  • Production-ready WSGI server setup with gunicorn
  • Proper security contexts and resource management

Related

  • Pull Request: #308
  • Original Issue: #36

Clone this wiki locally