Sleep Mode & Scheduling

Sleep mode suspends environments to reduce costs while preserving state. Combined with scheduling, you can automatically start and stop environments based on usage patterns.

Overview

When an environment sleeps:

  • Compute stops - No CPU/memory charges
  • State preserved - Data and configuration retained
  • Quick resume - Faster than creating from scratch
  • TTL pauses - Time-to-live doesn’t count down (configurable)

Sleep Strategies

Teabar supports multiple sleep strategies based on your environment’s needs:

Scale to Zero

Scales Kubernetes workloads to zero replicas:

teactl env stop march-training --strategy scale-to-zero
  • Resume time: ~30 seconds
  • Cost savings: ~90% (storage still billed)
  • Best for: Kubernetes-based environments

VM Stop

Stops virtual machines but keeps storage:

teactl env stop march-training --strategy vm-stop
  • Resume time: ~2 minutes
  • Cost savings: ~80% (storage still billed)
  • Best for: VM-based environments

Full Hibernation

Creates snapshot, deletes all resources:

teactl env stop march-training --strategy hibernate
  • Resume time: ~5-10 minutes
  • Cost savings: ~95% (minimal snapshot storage)
  • Best for: Long-term suspension, maximum savings

Strategy Comparison

StrategyResume TimeCost SavingsData SafetyBest For
Scale to Zero~30s~90%HighK8s environments
VM Stop~2m~80%HighVM environments
Hibernate~5-10m~95%Very HighLong-term storage

Manual Sleep/Wake

Stop an Environment

# Default strategy (based on environment type)
teactl env stop march-training

# Specific strategy
teactl env stop march-training --strategy hibernate

# Stop multiple environments
teactl env stop march-training demo-env --all-matching "workshop-*"

Wake an Environment

# Start a sleeping environment
teactl env start march-training

# Start and wait until ready
teactl env start march-training --wait

# Start with timeout
teactl env start march-training --wait --timeout 10m

Check Sleep Status

teactl env get march-training

# Output:
# Name: march-training
# Status: SLEEPING
# Sleep Strategy: scale-to-zero
# Sleeping Since: 2024-01-15 18:00 UTC
# Estimated Wake Time: ~30 seconds

Scheduled Sleep/Wake

Configure Schedule

Set automatic start/stop times:

# Sleep at 6 PM, wake at 8 AM (weekdays)
teactl env schedule march-training 
  --sleep "18:00" 
  --wake "08:00" 
  --timezone "America/New_York" 
  --weekdays-only

Schedule Options

teactl env schedule <name> [flags]
FlagDescription
--sleep <time>Time to sleep (HH:MM or cron)
--wake <time>Time to wake (HH:MM or cron)
--timezone <tz>Timezone for schedule
--weekdays-onlyOnly run on weekdays
--days <list>Specific days (mon,tue,wed…)
--clearRemove schedule

Schedule Examples

# Run during business hours only
teactl env schedule dev-env 
  --wake "09:00" 
  --sleep "18:00" 
  --timezone "Europe/Berlin" 
  --weekdays-only

View Schedule

teactl env get march-training --show-schedule

# Output:
# Schedule:
#   Wake: 08:00 (America/New_York)
#   Sleep: 18:00 (America/New_York)
#   Days: Mon-Fri
#   Next Wake: 2024-01-16 08:00 EST
#   Next Sleep: 2024-01-15 18:00 EST

Clear Schedule

teactl env schedule march-training --clear

Idle-Based Sleep

Automatically sleep environments after inactivity:

Configure Idle Sleep

# In blueprint or project config
sleep:
  idle:
    enabled: true
    timeout: 2h              # Sleep after 2 hours of inactivity
    activity_types:          # What counts as activity
      - api_call
      - terminal_session
      - port_access

Override Idle Settings

# Disable idle sleep for specific environment
teactl env update march-training --no-idle-sleep

# Set custom idle timeout
teactl env update march-training --idle-timeout 4h

Activity Detection

Teabar considers these as activity (preventing idle sleep):

Activity TypeDescription
api_callKubernetes API requests
terminal_sessionActive web terminal
port_accessTraffic to exposed ports
ssh_sessionActive SSH connections

Blueprint Configuration

Default Sleep Settings

apiVersion: teabar.dev/v1
kind: Blueprint
metadata:
  name: workshop-environment
spec:
  sleep:
    # Default strategy for this blueprint
    default_strategy: scale-to-zero
    
    # Allow user to override strategy
    strategy_override: true
    
    # Idle detection
    idle:
      enabled: true
      timeout: 1h
    
    # Default schedule
    schedule:
      enabled: true
      sleep: "18:00"
      wake: "08:00"
      timezone: "UTC"
      weekdays_only: true

Per-Resource Sleep Behavior

resources:
  - name: database
    type: helm
    spec:
      chart: postgresql
    sleep:
      strategy: vm-stop    # Databases need clean shutdown
      pre_sleep:
        - command: pg_ctl stop -m fast
      
  - name: cache
    type: kubernetes
    spec:
      # ...
    sleep:
      strategy: scale-to-zero  # Cache can scale quickly
      warmup:
        enabled: true
        command: /scripts/warm-cache.sh

Cost Impact

Calculate Savings

# View cost comparison
teactl env cost march-training --compare-sleep

# Output:
# Current Status: Running
# 
# Cost Comparison (per week):
#   Always Running:     $84.00
#   Business Hours:     $35.00 (58% savings)
#   With Idle Sleep:    $28.00 (67% savings)
#   
# Recommended: Enable business hours schedule

Sleep Statistics

teactl env stats march-training --sleep

# Output:
# Sleep Statistics (last 30 days):
#   Total Runtime: 120 hours
#   Total Sleep: 600 hours
#   Sleep Ratio: 83%
#   Cost Saved: $450

TTL Interaction

By default, TTL pauses during sleep:

ttl:
  count_while_sleeping: false  # Default

To continue TTL countdown during sleep:

ttl:
  count_while_sleeping: true

Best Practices

  1. Match strategy to workload - Use scale-to-zero for stateless, hibernate for long-term
  2. Set schedules for predictable usage - Training environments, demo environments
  3. Enable idle sleep - Catch forgotten environments
  4. Consider wake time - Schedule wake before users need access
  5. Test wake process - Ensure environment recovers correctly

Troubleshooting

Environment Won’t Sleep

# Check for blocking conditions
teactl env get march-training --sleep-blockers

# Common blockers:
# - Active terminal sessions
# - Running jobs/pipelines
# - Pending checkpoints

Slow Wake Time

# Check wake progress
teactl env get march-training --wake-progress

# Optimize by:
# - Using scale-to-zero instead of hibernate
# - Pre-warming caches
# - Reducing resource requests

See Also

ende