|
| 1 | +--- |
| 2 | +title: 'Autoscaling Configuration' |
| 3 | +sidebarTitle: 'Autoscaling' |
| 4 | +--- |
| 5 | + |
| 6 | +Configure horizontal pod autoscaling to automatically adjust the number of replicas based on resource utilization. |
| 7 | + |
| 8 | +## Field Reference |
| 9 | + |
| 10 | +| Field | Type | Description | |
| 11 | +|-------|------|-------------| |
| 12 | +| `enabled` | boolean | Enable autoscaling | |
| 13 | +| `minInstances` | integer | Minimum number of replicas | |
| 14 | +| `maxInstances` | integer | Maximum number of replicas | |
| 15 | +| `cpuThresholdPercent` | integer | CPU usage threshold (0-100) | |
| 16 | +| `memoryThresholdPercent` | integer | Memory usage threshold (0-100) | |
| 17 | + |
| 18 | +## Basic Configuration |
| 19 | + |
| 20 | +```yaml |
| 21 | +services: |
| 22 | + - name: api |
| 23 | + # ... |
| 24 | + autoscaling: |
| 25 | + enabled: true |
| 26 | + minInstances: 2 |
| 27 | + maxInstances: 10 |
| 28 | + cpuThresholdPercent: 80 |
| 29 | + memoryThresholdPercent: 80 |
| 30 | +``` |
| 31 | +
|
| 32 | +<Info> |
| 33 | +When autoscaling is enabled, the `instances` field is ignored. The autoscaler manages replica count automatically. |
| 34 | +</Info> |
| 35 | + |
| 36 | +<Tip> |
| 37 | +For high availability, set `minInstances` to at least 3. See [High Availability Applications](/configure/zero-downtime-deployments#high-availability-applications) for more details. |
| 38 | +</Tip> |
| 39 | + |
| 40 | +## How It Works |
| 41 | + |
| 42 | +When either CPU or memory usage exceeds your configured threshold, Porter automatically adds replicas. When usage drops, replicas are removed (down to your minimum). |
| 43 | + |
| 44 | +### Example: Autoscaling in Action |
| 45 | + |
| 46 | +Consider an API service with this configuration: |
| 47 | + |
| 48 | +```yaml |
| 49 | +autoscaling: |
| 50 | + enabled: true |
| 51 | + minInstances: 2 |
| 52 | + maxInstances: 10 |
| 53 | + cpuThresholdPercent: 60 |
| 54 | + memoryThresholdPercent: 80 |
| 55 | +``` |
| 56 | + |
| 57 | +Here's how the autoscaler responds to changing load: |
| 58 | + |
| 59 | +| Time | Avg CPU | Avg Memory | Replicas | What Happens | |
| 60 | +|------|---------|------------|----------|--------------| |
| 61 | +| t=0 | 30% | 40% | 2 | Baseline: both metrics below thresholds | |
| 62 | +| t=1 | 75% | 50% | 4 | CPU (75%) exceeds 60% threshold → scale up | |
| 63 | +| t=2 | 90% | 60% | 6 | CPU still high → continue scaling up | |
| 64 | +| t=3 | 55% | 85% | 8 | CPU stabilized, but memory (85%) exceeds 80% → scale up | |
| 65 | +| t=4 | 45% | 70% | 8 | Both metrics below thresholds → no change (cooldown period) | |
| 66 | +| t=5 | 40% | 50% | 5 | Sustained low usage → scale down | |
| 67 | +| t=6 | 35% | 45% | 2 | Continue scaling down to minimum | |
| 68 | + |
| 69 | +Key behaviors: |
| 70 | +- **Either metric triggers scaling**: If CPU *or* memory exceeds its threshold, replicas are added |
| 71 | +- **Both must be low to scale down**: Replicas are only removed when both CPU and memory are below their thresholds |
| 72 | +- **Respects bounds**: Replicas never drop below `minInstances` (2) or exceed `maxInstances` (10) |
| 73 | +- **Gradual changes**: The autoscaler adjusts incrementally, not all at once, to avoid oscillation |
| 74 | + |
| 75 | +## Custom Metrics Autoscaling (Prometheus) |
| 76 | + |
| 77 | +Scale based on application-specific metrics like queue length, request latency, or custom business metrics. |
| 78 | + |
| 79 | +| Field | Type | Description | |
| 80 | +|-------|------|-------------| |
| 81 | +| `customAutoscaling.prometheusMetricCustomAutoscaling.metricName` | string | Prometheus metric name | |
| 82 | +| `customAutoscaling.prometheusMetricCustomAutoscaling.threshold` | number | Threshold value to trigger scaling | |
| 83 | +| `customAutoscaling.prometheusMetricCustomAutoscaling.query` | string | Custom PromQL query (optional, defaults to metric name) | |
| 84 | + |
| 85 | +```yaml |
| 86 | +services: |
| 87 | + - name: api |
| 88 | + # ... |
| 89 | + autoscaling: |
| 90 | + enabled: true |
| 91 | + minInstances: 1 |
| 92 | + maxInstances: 10 |
| 93 | + customAutoscaling: |
| 94 | + prometheusMetricCustomAutoscaling: |
| 95 | + metricName: "http_requests_per_second" |
| 96 | + threshold: 100 |
| 97 | + query: "rate(http_requests_total[5m])" |
| 98 | +``` |
| 99 | + |
| 100 | +<Info> |
| 101 | +Custom metrics autoscaling requires Prometheus to be accessible in your cluster. See [Custom Metrics and Autoscaling](/observability/custom-metrics-and-autoscaling) for setup details. |
| 102 | +</Info> |
| 103 | + |
| 104 | +## Temporal Autoscaling |
| 105 | + |
| 106 | +Scale Temporal workflow workers based on task queue depth. Porter monitors your Temporal task queues and automatically adjusts worker count. |
| 107 | + |
| 108 | +<Info> |
| 109 | +Temporal autoscaling requires a Temporal integration to be configured. See [Temporal Autoscaling](/configure/temporal-autoscaling) for setup details. |
| 110 | +</Info> |
| 111 | + |
| 112 | +| Field | Type | Description | |
| 113 | +|-------|------|-------------| |
| 114 | +| `temporalAutoscaling.temporalIntegrationId` | string | UUID of the Temporal integration | |
| 115 | +| `temporalAutoscaling.taskQueue` | string | Name of the Temporal task queue to monitor | |
| 116 | +| `temporalAutoscaling.targetQueueSize` | integer | How many queued tasks each replica should handle (e.g., set to 10 with 100 tasks queued → 10 replicas) | |
| 117 | + |
| 118 | +```yaml |
| 119 | +services: |
| 120 | + - name: temporal-worker |
| 121 | + # ... |
| 122 | + autoscaling: |
| 123 | + enabled: true |
| 124 | + minInstances: 2 |
| 125 | + maxInstances: 50 |
| 126 | + temporalAutoscaling: |
| 127 | + temporalIntegrationId: "550e8400-e29b-41d4-a716-446655440000" |
| 128 | + taskQueue: "my-task-queue" |
| 129 | + targetQueueSize: 10 |
| 130 | +``` |
| 131 | + |
| 132 | +## Related Documentation |
| 133 | + |
| 134 | +- [Autoscaling Overview](/configure/autoscaling) - UI-based configuration and concepts |
| 135 | +- [Web Services](/deploy/configuration-as-code/services/web-service) - Web service configuration |
| 136 | +- [Worker Services](/deploy/configuration-as-code/services/worker-service) - Worker service configuration |
0 commit comments