Autoscaling
Automatically scale your containers based on CPU, memory, or scheduled triggers.
Autoscaling ensures your application has the right amount of resources at all times—scaling up during traffic spikes and down during quiet periods.
How Autoscaling Works
SailOps automatically adjusts the number of container replicas based on CPU usage, memory usage or a schedule.
Traffic ↑ → Metrics ↑ → Replicas ↑
Traffic ↓ → Metrics ↓ → Replicas ↓
Prerequisites
Autoscaling is not available for containers with a persistent volume attached. Volumes require the container to be limited to a single replica. To use autoscaling, remove the persistent volume first.
Enable Autoscaling
- Navigate to your container
- Click the Details tab
- Scroll to the Autoscaling section
- Toggle Enable Autoscaling
- Configure the settings
- Click Save
Configuration Options
Replica Limits
| Setting | Description | Recommendation |
|---|---|---|
| Min Replicas | Minimum running instances | At least 2 for HA |
| Max Replicas | Maximum instances to scale to | Based on budget |
Set min replicas to at least 2 in production for high availability. This ensures your app stays online if one replica fails.
Scaling Triggers
CPU-Based Scaling
Scale based on CPU usage relative to your container's allocated limit:
| Setting | Value | Behavior |
|---|---|---|
| Target CPU | 70% | Scale up when avg CPU exceeds 70% of the container's CPU limit |
| Scale Up Stabilization | 15s | Wait before adding replicas |
| Scale Down Stabilization | 300s | Wait before removing replicas |
Memory-Based Scaling
Scale based on memory usage relative to your container's allocated limit:
| Setting | Value | Behavior |
|---|---|---|
| Target Memory | 80% | Scale up when avg memory exceeds 80% of the container's memory limit |
CPU and memory thresholds are always measured as a percentage of your container's allocated limit (the resources you are paying for). This ensures the threshold behaves consistently regardless of internal Kubernetes request adjustments.
Schedule-Based Scaling
Scale based on time schedules for predictable traffic patterns:
How Schedule Scaling Works
Schedule scaling automatically adjusts replicas based on time, perfect for predictable traffic patterns:
-
During scheduled period (between Start Time and End Time on Active Days):
- Replicas scale to
Desired Replicasvalue
- Replicas scale to
-
Outside scheduled period:
- Replicas scale back down to
Min Replicas - If
Min Replicasis 0, the container stops completely (scale to zero)
- Replicas scale back down to
- Start Time: When your container scales UP to the desired number of replicas
- End Time: When your container scales DOWN to minimum replicas
Between Start and End times on active days, SailOps maintains the desired replica count. Outside this window, it uses the minimum replicas setting.
Configuration Options
| Setting | Description | Example |
|---|---|---|
| Active Days | Days when the schedule is active | Mon, Tue, Wed, Thu, Fri |
| Start Time | Time to scale up | 08:00 |
| End Time | Time to scale down | 20:00 |
| Desired Replicas | Target replicas during schedule | 3 |
| Timezone | Timezone for the schedule | Europe/Paris |
Scaling Behavior
Scale Up
When metrics exceed the target:
- Autoscaler detects increased load
- New replicas are scheduled
- Health checks verify readiness
- Traffic is routed to new replicas
Default behavior: Fast scale-up (within 15 seconds)
Scale Down
When metrics fall below the target:
- Autoscaler detects decreased load
- Stabilization period begins (5 minutes)
- Replicas are gradually terminated
- Traffic drains gracefully
Default behavior: Slow scale-down to prevent thrashing
Cooldown Periods
Prevent rapid scaling oscillation:
| Direction | Default | Description |
|---|---|---|
| Scale Up | 15 seconds | Minimum time between scale-ups |
| Scale Down | 5 minutes | Minimum time between scale-downs |
Example Configurations
Web Application
Typical configuration for a web server:
| Parameter | Value |
|---|---|
| Enabled | true |
| Min Replicas | 2 |
| Max Replicas | 10 |
Triggers: CPU at 70%, Memory at 80%
API Server
Higher availability for APIs:
| Parameter | Value |
|---|---|
| Enabled | true |
| Min Replicas | 3 |
| Max Replicas | 20 |
Triggers: CPU at 60%, Memory at 75%
Background Worker
Scale on CPU usage for background processing:
| Parameter | Value |
|---|---|
| Enabled | true |
| Min Replicas | 1 |
| Max Replicas | 10 |
Triggers: CPU at 80%
Monitoring Autoscaling
Current Status
View autoscaling status in your container details:
| Metric | Description |
|---|---|
| Current Replicas | Active instances now |
| Desired Replicas | Target based on metrics |
| Current CPU | Average CPU across replicas |
| Current Memory | Average memory usage |
Events
Autoscaling events appear in the Events tab:
ScaledUp: Replicas increasedScaledDown: Replicas decreasedFailedScale: Scaling failed
Metrics
Monitor scaling patterns:
- Go to Metrics tab
- View replica count over time
- Correlate with CPU/memory metrics
Best Practices
Right-Size Your Compute Class
Before relying on autoscaling, ensure your compute class is appropriate:
- Containers should run at 40-60% CPU normally
- If always at 100%, consider upgrading compute class
- Autoscaling handles spikes, not baseline capacity
Set Appropriate Targets
| Target | Too Low | Just Right | Too High |
|---|---|---|---|
| CPU | 40% | 60-70% | 90% |
| Memory | 50% | 70-80% | 95% |
- Too low: Wastes resources, frequent scaling
- Too high: Poor performance, slow response to spikes
Configure Health Checks
Ensure replicas are healthy before receiving traffic:
| Parameter | Value |
|---|---|
| Path | /health |
| Initial Delay | 10s |
| Period | 5s |
Graceful Shutdown
Handle termination signals:
process.on('SIGTERM', () => {
server.close(() => {
process.exit(0);
});
});
Test Your Scaling
Use load testing to verify:
- Scale-up happens at expected load
- Scale-down is gradual and stable
- No requests are dropped during scaling
Scale to Zero
Setting Min Replicas to 0 lets the container stop completely: no replica runs and no compute is billed. Scale to zero requires a Schedule trigger. A minimum of 0 is rejected when the only triggers are CPU or memory, because those are measured on running replicas and could never start the container again.
A container scaled to zero does not start when a request arrives. Requests sent while no replica is running fail until the next scheduled start time. Scale to zero suits workloads with predictable hours, such as stopping a staging environment at night, not services that must answer at any time.
Example: Scale to Zero Outside Business Hours
Save costs by running 0 replicas during nights and weekends:
Step 1: Configure Autoscaling Settings
| Parameter | Value | Description |
|---|---|---|
| Enable Autoscaling | ✓ | Turn on automatic scaling |
| Min Replicas | 0 | Allow scaling to zero |
| Max Replicas | 10 | Maximum during peaks |
Step 2: Add a Schedule Trigger
| Parameter | Value | Description |
|---|---|---|
| Active Days | Mon, Tue, Wed, Thu, Fri | Business days only |
| Start Time | 08:00 | Scale up at 8:00 AM |
| End Time | 20:00 | Scale down at 8:00 PM |
| Desired Replicas | 2 | Minimum during business hours |
| Timezone | Europe/Paris | Your local timezone |
Result:
- Mon-Fri 8:00-20:00: 2+ replicas running (can scale higher with CPU/Memory triggers)
- Mon-Fri 20:00-8:00: 0 replicas (container stopped, no compute charges)
- Weekends: 0 replicas (outside schedule)
This configuration can reduce costs by up to 70% for development or internal applications that are only used during business hours.
Example: Different Capacity for Peak Hours
You can add multiple Schedule triggers for different time periods:
Schedule 1 - Morning Peak:
- Active Days: Mon-Fri
- Start: 08:00, End: 10:00
- Desired Replicas: 5
Schedule 2 - Normal Hours:
- Active Days: Mon-Fri
- Start: 10:00, End: 18:00
- Desired Replicas: 3
Schedule 3 - Evening Peak:
- Active Days: Mon-Fri
- Start: 18:00, End: 20:00
- Desired Replicas: 4
With Min Replicas: 0, your container will:
- Run 5 replicas during morning rush
- Run 3 replicas during normal business hours
- Run 4 replicas during evening traffic
- Stop completely at night and weekends
Startup Time After Scale to Zero
When a schedule starts, the container goes from 0 replicas to the desired count. It cannot answer requests until startup completes:
| Factor | Typical Time |
|---|---|
| Small image (<100MB) | 5-15 seconds |
| Large image (>500MB) | 30-60 seconds |
| Fast app initialization | 5-10 seconds |
| Heavy initialization (databases, caches) | 30+ seconds |
Total startup time = Image pull + Container start + App initialization + Health check
Recommendations for scale-to-zero:
- Set the schedule start time a few minutes before the service is needed
- Optimize container image size (use multi-stage builds)
- Configure appropriate startup probes
- For services that must answer at any time, keep
Min Replicas: 1or more
Combining Schedule with CPU/Memory Scaling
You can use schedule scaling alongside CPU/Memory triggers. SailOps uses the maximum replica count from all active triggers.
Example Configuration:
- CPU trigger: target 70%
- Schedule trigger: Mon-Fri 9:00-18:00, Desired Replicas: 3
- Min Replicas: 1
Behavior:
| Time Period | Active Triggers | Result |
|---|---|---|
| Weekday business hours, low traffic | Schedule (3) + CPU (1) | 3 replicas (max) |
| Weekday business hours, high traffic | Schedule (3) + CPU (8) | 8 replicas (max) |
| Weekday night, low traffic | CPU only (1) | 1 replica |
| Weekend | CPU only | Based on CPU usage |
This is useful for:
- Ensuring minimum capacity during known busy periods
- Allowing additional scaling during unexpected traffic spikes
Troubleshooting
Scaling Not Working
- Verify autoscaling is enabled
- Check metrics are being collected
- Ensure min/max replicas are different
- Review Events for errors
Too Much Scaling
- Increase stabilization windows
- Raise target percentages
- Check for application memory leaks
Not Scaling Fast Enough
- Lower target percentages
- Reduce scale-up stabilization
- Pre-scale before expected traffic
Replicas Keep Crashing
- Check health check configuration
- Verify application handles concurrent requests
- Review logs for crashes
Cost Optimization
Autoscaling helps optimize costs:
| Strategy | Implementation |
|---|---|
| Scale to zero overnight | Use Schedule triggers with Min Replicas: 0 |
| Right-size base capacity | Analyze actual usage patterns |
| Set appropriate maximums | Prevent runaway costs |
| Peak hour optimization | Multiple Schedule triggers for different time periods |