Skip to main content

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​

Persistent Volumes

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​

  1. Navigate to your container
  2. Click the Details tab
  3. Scroll to the Autoscaling section
  4. Toggle Enable Autoscaling
  5. Configure the settings
  6. Click Save

Configuration Options​

Replica Limits​

SettingDescriptionRecommendation
Min ReplicasMinimum running instancesAt least 2 for HA
Max ReplicasMaximum instances to scale toBased on budget
Minimum Replicas

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:

SettingValueBehavior
Target CPU70%Scale up when avg CPU exceeds 70% of the container's CPU limit
Scale Up Stabilization15sWait before adding replicas
Scale Down Stabilization300sWait before removing replicas

Memory-Based Scaling​

Scale based on memory usage relative to your container's allocated limit:

SettingValueBehavior
Target Memory80%Scale up when avg memory exceeds 80% of the container's memory limit
Thresholds are based on limits

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:

  1. During scheduled period (between Start Time and End Time on Active Days):

    • Replicas scale to Desired Replicas value
  2. Outside scheduled period:

    • Replicas scale back down to Min Replicas
    • If Min Replicas is 0, the container stops completely (scale to zero)
Understanding Start and End Times
  • 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​
SettingDescriptionExample
Active DaysDays when the schedule is activeMon, Tue, Wed, Thu, Fri
Start TimeTime to scale up08:00
End TimeTime to scale down20:00
Desired ReplicasTarget replicas during schedule3
TimezoneTimezone for the scheduleEurope/Paris

Scaling Behavior​

Scale Up​

When metrics exceed the target:

  1. Autoscaler detects increased load
  2. New replicas are scheduled
  3. Health checks verify readiness
  4. Traffic is routed to new replicas

Default behavior: Fast scale-up (within 15 seconds)

Scale Down​

When metrics fall below the target:

  1. Autoscaler detects decreased load
  2. Stabilization period begins (5 minutes)
  3. Replicas are gradually terminated
  4. Traffic drains gracefully

Default behavior: Slow scale-down to prevent thrashing

Cooldown Periods​

Prevent rapid scaling oscillation:

DirectionDefaultDescription
Scale Up15 secondsMinimum time between scale-ups
Scale Down5 minutesMinimum time between scale-downs

Example Configurations​

Web Application​

Typical configuration for a web server:

ParameterValue
Enabledtrue
Min Replicas2
Max Replicas10

Triggers: CPU at 70%, Memory at 80%

API Server​

Higher availability for APIs:

ParameterValue
Enabledtrue
Min Replicas3
Max Replicas20

Triggers: CPU at 60%, Memory at 75%

Background Worker​

Scale on CPU usage for background processing:

ParameterValue
Enabledtrue
Min Replicas1
Max Replicas10

Triggers: CPU at 80%

Monitoring Autoscaling​

Current Status​

View autoscaling status in your container details:

MetricDescription
Current ReplicasActive instances now
Desired ReplicasTarget based on metrics
Current CPUAverage CPU across replicas
Current MemoryAverage memory usage

Events​

Autoscaling events appear in the Events tab:

  • ScaledUp: Replicas increased
  • ScaledDown: Replicas decreased
  • FailedScale: Scaling failed

Metrics​

Monitor scaling patterns:

  1. Go to Metrics tab
  2. View replica count over time
  3. Correlate with CPU/memory metrics

Best Practices​

Right-Size Your Compute Class​

Before relying on autoscaling, ensure your compute class is appropriate:

  1. Containers should run at 40-60% CPU normally
  2. If always at 100%, consider upgrading compute class
  3. Autoscaling handles spikes, not baseline capacity

Set Appropriate Targets​

TargetToo LowJust RightToo High
CPU40%60-70%90%
Memory50%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:

ParameterValue
Path/health
Initial Delay10s
Period5s

Graceful Shutdown​

Handle termination signals:

process.on('SIGTERM', () => {
server.close(() => {
process.exit(0);
});
});

Test Your Scaling​

Use load testing to verify:

  1. Scale-up happens at expected load
  2. Scale-down is gradual and stable
  3. 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.

No wake-up on incoming requests

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

ParameterValueDescription
Enable Autoscaling✓Turn on automatic scaling
Min Replicas0Allow scaling to zero
Max Replicas10Maximum during peaks

Step 2: Add a Schedule Trigger

ParameterValueDescription
Active DaysMon, Tue, Wed, Thu, FriBusiness days only
Start Time08:00Scale up at 8:00 AM
End Time20:00Scale down at 8:00 PM
Desired Replicas2Minimum during business hours
TimezoneEurope/ParisYour 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)
Cost Savings

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:

FactorTypical Time
Small image (<100MB)5-15 seconds
Large image (>500MB)30-60 seconds
Fast app initialization5-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: 1 or 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 PeriodActive TriggersResult
Weekday business hours, low trafficSchedule (3) + CPU (1)3 replicas (max)
Weekday business hours, high trafficSchedule (3) + CPU (8)8 replicas (max)
Weekday night, low trafficCPU only (1)1 replica
WeekendCPU onlyBased 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:

StrategyImplementation
Scale to zero overnightUse Schedule triggers with Min Replicas: 0
Right-size base capacityAnalyze actual usage patterns
Set appropriate maximumsPrevent runaway costs
Peak hour optimizationMultiple Schedule triggers for different time periods