Node.js & Libuv•Part 5: Production Scale, Deployment & Observability (51 - 60)
Process Management: PM2 vs Kubernetes.
In Simple Words:
- PM2: Excellent for standalone virtual machines (EC2). Manages clustering, log aggregation, and autorestarts on crashes.
- Kubernetes: Standard for cloud-native enterprise deployments. Handles pod replication, horizontal autoscaling (HPA), rolling updates, and self-healing across nodes.
javascript
// PM2 ecosystem.config.js for zero-downtime clustering on VMs:
module.exports = {
apps: [{
name: 'api-server',
script: 'dist/server.js',
instances: 'max', // One process per CPU core
exec_mode: 'cluster',
max_memory_restart: '500M'
}]
};