Kubernetes for eCommerce Scaling: From Traffic Spikes to Global Expansion
Black Friday traffic spikes can increase eCommerce load by 10-50x within minutes. Traditional server infrastructure cannot respond fast enough. Kubernetes provides the auto-scaling, self-healing, and traffic management capabilities that modern eCommerce platforms need to handle unpredictable demand without over-provisioning during quiet periods.
This guide covers Kubernetes architecture specifically for eCommerce workloads, from handling flash sales to building multi-region storefronts that serve customers in under 200ms regardless of location.
Key Takeaways
- Horizontal Pod Autoscaler (HPA) can scale eCommerce services from 2 to 200 pods in under 90 seconds
- Ingress controllers with rate limiting protect backend services during traffic surges
- Stateful workloads (databases, search indexes) require different scaling strategies than stateless services
- Multi-region Kubernetes deployments reduce latency by 60-80% for global customer bases
When Kubernetes Makes Sense for eCommerce
Kubernetes is not always the right answer. It adds operational complexity that must be justified by the scaling requirements.
Decision Matrix
| Factor | Docker Compose Sufficient | Kubernetes Justified |
|---|---|---|
| Monthly orders | <10,000 | 10,000+ |
| Concurrent users | <500 | 500+ |
| Services count | <5 | 5+ |
| Traffic variability | <3x peaks | 3x+ peaks |
| Regions served | Single | Multiple |
| Team size (DevOps) | 0-1 | 2+ |
| Uptime requirement | 99.9% | 99.95%+ |
If your business falls in the Docker Compose column, see our Docker production deployment guide instead.
Kubernetes Architecture for eCommerce
Cluster Layout
An eCommerce Kubernetes cluster typically contains these namespaces:
storefront: Frontend application podsapi: Backend API servicesworkers: Background job processors (order processing, email sending, inventory sync)data: Databases, caches, and search engines (or managed external services)ingress: Ingress controllers and load balancersmonitoring: Prometheus, Grafana, alerting
Deployment Configuration
# storefront-deployment.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
name: storefront
namespace: storefront
spec:
replicas: 3
strategy:
type: RollingUpdate
rollingUpdate:
maxSurge: 1
maxUnavailable: 0
selector:
matchLabels:
app: storefront
template:
metadata:
labels:
app: storefront
spec:
containers:
- name: storefront
image: registry.example.com/storefront:v2.1.0
ports:
- containerPort: 3000
resources:
requests:
cpu: 250m
memory: 256Mi
limits:
cpu: 1000m
memory: 512Mi
readinessProbe:
httpGet:
path: /health
port: 3000
initialDelaySeconds: 5
periodSeconds: 10
livenessProbe:
httpGet:
path: /health
port: 3000
initialDelaySeconds: 15
periodSeconds: 20
env:
- name: API_URL
value: "http://api-service.api.svc.cluster.local:3001"
- name: NODE_ENV
value: "production"
Auto-Scaling Configuration
Horizontal Pod Autoscaler
# storefront-hpa.yaml
apiVersion: autoscaling/v2
kind: HorizontalPodAutoscaler
metadata:
name: storefront-hpa
namespace: storefront
spec:
scaleTargetRef:
apiVersion: apps/v1
kind: Deployment
name: storefront
minReplicas: 3
maxReplicas: 50
metrics:
- type: Resource
resource:
name: cpu
target:
type: Utilization
averageUtilization: 60
- type: Resource
resource:
name: memory
target:
type: Utilization
averageUtilization: 70
behavior:
scaleUp:
stabilizationWindowSeconds: 30
policies:
- type: Percent
value: 100
periodSeconds: 60
scaleDown:
stabilizationWindowSeconds: 300
policies:
- type: Percent
value: 10
periodSeconds: 60
The scaleUp policy allows doubling pods every 60 seconds --- critical for handling sudden traffic spikes. The scaleDown policy is conservative (10% per minute) to prevent thrashing.
Cluster Autoscaler
HPA scales pods, but pods need nodes. The Cluster Autoscaler adds and removes nodes based on pending pod demands:
# cluster-autoscaler configuration
apiVersion: v1
kind: ConfigMap
metadata:
name: cluster-autoscaler-config
data:
balance-similar-node-groups: "true"
skip-nodes-with-local-storage: "false"
scale-down-delay-after-add: "10m"
scale-down-unneeded-time: "10m"
max-node-provision-time: "5m"
For AWS EKS, configure node groups with min/max sizes:
eksctl create nodegroup \
--cluster ecommerce-prod \
--name workers \
--node-type t3.large \
--nodes-min 3 \
--nodes-max 20 \
--node-volume-size 50 \
--managed
Ingress and Traffic Management
Nginx Ingress Controller
# ingress.yaml
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: ecommerce-ingress
annotations:
nginx.ingress.kubernetes.io/rate-limit: "100"
nginx.ingress.kubernetes.io/rate-limit-window: "1m"
nginx.ingress.kubernetes.io/proxy-body-size: "10m"
nginx.ingress.kubernetes.io/ssl-redirect: "true"
nginx.ingress.kubernetes.io/use-regex: "true"
spec:
tls:
- hosts:
- store.example.com
secretName: store-tls
rules:
- host: store.example.com
http:
paths:
- path: /api
pathType: Prefix
backend:
service:
name: api-service
port:
number: 3001
- path: /
pathType: Prefix
backend:
service:
name: storefront-service
port:
number: 3000
Handling Flash Sales
Flash sales require pre-scaling. Do not rely on auto-scaling alone for known high-traffic events:
# Pre-scale 2 hours before a flash sale
kubectl scale deployment storefront --replicas=20 -n storefront
kubectl scale deployment api --replicas=15 -n api
kubectl scale deployment order-worker --replicas=10 -n workers
# After the sale, let HPA scale down naturally
Database Scaling in Kubernetes
Managed vs Self-Hosted Databases
| Approach | Pros | Cons |
|---|---|---|
| Managed (RDS, Cloud SQL) | Automated backups, patching, failover | Higher cost, limited customization |
| Self-hosted (StatefulSet) | Full control, lower cost | Operational burden, backup responsibility |
Recommendation: Use managed databases for production eCommerce. The operational overhead of running PostgreSQL in Kubernetes is not justified for most businesses.
Connection Pooling
# pgbouncer-deployment.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
name: pgbouncer
namespace: data
spec:
replicas: 2
template:
spec:
containers:
- name: pgbouncer
image: edoburu/pgbouncer:1.21.0
ports:
- containerPort: 5432
env:
- name: DATABASE_URL
valueFrom:
secretKeyRef:
name: db-credentials
key: url
- name: MAX_CLIENT_CONN
value: "1000"
- name: DEFAULT_POOL_SIZE
value: "25"
- name: POOL_MODE
value: "transaction"
PgBouncer in transaction pooling mode allows hundreds of application pods to share a limited pool of database connections. Without connection pooling, scaling to 50 API pods would require 50 x 20 = 1,000 database connections, overwhelming most PostgreSQL instances.
For more database scaling strategies, see our database scaling guide.
Multi-Region Deployment
Architecture
A multi-region eCommerce Kubernetes deployment uses:
- Regional clusters: Independent Kubernetes clusters in each region
- Global load balancer: Routes users to the nearest region (AWS Global Accelerator, Cloudflare)
- Database replication: Primary in one region, read replicas in others
- CDN: Static assets served from edge locations worldwide
Latency Impact
| User Location | Single Region (US-East) | Multi-Region |
|---|---|---|
| New York | 20ms | 20ms |
| London | 120ms | 25ms |
| Singapore | 250ms | 30ms |
| Sydney | 300ms | 35ms |
Multi-region deployment reduces latency for international customers by 60-90%, directly improving conversion rates. Studies show that every 100ms of latency reduction increases eCommerce conversion by 1.1%.
Monitoring Kubernetes eCommerce
Essential Dashboards
- Business metrics: Orders per minute, cart conversion rate, revenue per hour
- Application metrics: Request latency (P50, P95, P99), error rate, active sessions
- Infrastructure metrics: Pod CPU/memory, node utilization, HPA activity
- Database metrics: Connection count, query latency, replication lag
# prometheus-servicemonitor.yaml
apiVersion: monitoring.coreos.com/v1
kind: ServiceMonitor
metadata:
name: api-monitor
namespace: monitoring
spec:
selector:
matchLabels:
app: api
endpoints:
- port: metrics
interval: 15s
path: /metrics
Frequently Asked Questions
How much does Kubernetes cost compared to traditional hosting?
Kubernetes infrastructure costs 20-40% more than equivalent bare-metal or simple cloud instances due to control plane costs, load balancer fees, and node overhead. However, auto-scaling typically reduces total spend by 30-50% because you are not paying for peak capacity during off-peak hours. The net effect for most eCommerce businesses with variable traffic is a 10-25% cost reduction.
Can we run Odoo on Kubernetes?
Yes, but with caveats. Odoo's filestore requires shared persistent storage (EFS, NFS) when running multiple replicas. Session affinity is needed unless you externalize sessions to Redis. Database connections must be pooled via PgBouncer. For most Odoo deployments, Docker Compose or ECS is simpler and sufficient. Kubernetes makes sense for large Odoo deployments with 200+ concurrent users.
How do we handle Kubernetes upgrades without downtime?
Use a managed Kubernetes service (EKS, GKE, AKS) that handles control plane upgrades. For node upgrades, use a rolling strategy: cordon a node, drain its pods (they reschedule to other nodes), upgrade the node, uncordon it. With proper pod disruption budgets, this is fully automated and zero-downtime.
What is the minimum cluster size for production eCommerce?
A minimum production cluster for a mid-size eCommerce platform: 3 nodes (t3.large or equivalent) for application workloads, plus a managed database instance. This handles approximately 500 concurrent users with room for auto-scaling during peaks. Total infrastructure cost: approximately $500-800 per month.
What Comes Next
Kubernetes provides the scaling foundation, but it is only one piece of the infrastructure puzzle. Combine it with CI/CD best practices, CDN optimization, and load testing for a complete eCommerce operations platform.
Contact ECOSIRE for Kubernetes consulting and eCommerce scaling strategy, or explore our Shopify integration services for managed headless commerce on Kubernetes.
Published by ECOSIRE -- helping businesses scale eCommerce infrastructure globally.
Written by
ECOSIRE Research and Development Team
Building enterprise-grade digital products at ECOSIRE. Sharing insights on Odoo integrations, e-commerce automation, and AI-powered business solutions.
Related Articles
AI Fraud Detection for eCommerce: Protect Revenue Without Blocking Good Customers
Deploy AI fraud detection that catches 95%+ of fraudulent transactions while reducing false positives by 50-70%. Covers models, rules, and implementation.
AI for Inventory Optimization: Reduce Stockouts and Cut Carrying Costs
Deploy AI-powered inventory optimization to reduce stockouts by 30-50% and cut carrying costs by 15-25%. Covers demand forecasting, safety stock, and reorder logic.
AI Personalization for eCommerce: Individualized Experiences That Convert
Deploy AI personalization for eCommerce with product recommendations, dynamic content, personalized search, and customer journey optimization for 15-30% higher conversions.