TTL & Automatic Cleanup
Time-to-Live (TTL) ensures environments are automatically cleaned up after a specified duration, preventing resource waste and unexpected costs.
Overview
Every environment can have a TTL that specifies how long it should exist. When the TTL expires:
- Warning notifications are sent (24h, 1h, 10min before)
- A final checkpoint is created (if enabled)
- The environment is terminated
- All resources are released
TTL Configuration
Setting TTL at Creation
# Create with 8-hour TTL
teactl env create --blueprint workshop --name march-training --ttl 8h
# Create with 3-day TTL
teactl env create --blueprint demo --name client-demo --ttl 3d
# Create without TTL (runs indefinitely)
teactl env create --blueprint dev --name my-sandbox --no-ttl TTL in Blueprints
Define default TTL in your blueprint:
apiVersion: teabar.dev/v1
kind: Blueprint
metadata:
name: workshop-environment
spec:
ttl:
default: 8h # Default TTL for environments
max: 24h # Maximum allowed TTL
extendable: true # Allow users to extend TTL
max_extensions: 3 # Maximum number of extensions TTL Hierarchy
TTL values are resolved in this order (first non-null wins):
- Environment-specific - Set at creation or via extend
- Blueprint default - Defined in the blueprint
- Project default - Project-level setting
- Organization default - Organization-level setting
- System default - Platform default (usually 24h for SaaS)
# View effective TTL configuration
teactl env get march-training --show-ttl-source TTL Countdown Behavior
Running Environments
TTL counts down while the environment is in RUNNING state.
Sleeping Environments
By default, TTL pauses when an environment is sleeping:
# In blueprint or project config
ttl:
count_while_sleeping: false # Default: pause TTL during sleep To continue countdown during sleep:
ttl:
count_while_sleeping: true State Transitions
| State | TTL Behavior |
|---|---|
PROVISIONING | Not counting (environment not ready) |
RUNNING | Counting down |
SLEEPING | Paused (configurable) |
TERMINATING | Not applicable |
Extending TTL
Add Time
# Add 4 more hours
teactl env extend march-training --add 4h
# Add 1 day
teactl env extend march-training --add 1d Set Absolute Expiration
# Extend until specific time
teactl env extend march-training --until "2024-01-20 18:00"
# Extend until end of day
teactl env extend march-training --until "today 23:59" Remove TTL
# Remove TTL (environment runs indefinitely)
teactl env extend march-training --no-ttl Warning
Extension Limits
Blueprints can limit extensions:
ttl:
extendable: true
max_extensions: 3 # Max 3 extensions allowed
max_extension_time: 24h # Max time per extension
max_total: 7d # Maximum total lifetime Check remaining extensions:
teactl env get march-training
# Output includes:
# TTL: 2h remaining (extended 2/3 times) Expiration Warnings
Default Warning Schedule
| Time Before Expiry | Notification |
|---|---|
| 24 hours | Email + Slack (if configured) |
| 1 hour | Email + Slack + CLI notification |
| 10 minutes | All channels + terminal banner |
Configuring Warnings
# Project or organization config
notifications:
ttl_warnings:
- time: 24h
channels: [email]
- time: 1h
channels: [email, slack]
- time: 10m
channels: [email, slack, webhook] Viewing Expiring Environments
# List environments expiring soon
teactl env list --expiring
# List environments expiring within 2 hours
teactl env list --expiring --within 2h Sample output:
NAME STATUS TTL REMAINING EXPIRES AT
march-training Running 1h 30m 2024-01-15 16:30 UTC
demo-env Running 45m 2024-01-15 15:45 UTC
test-workshop Sleeping 4h 2024-01-15 19:00 UTC Grace Period
After TTL expires, there’s a grace period before deletion:
ttl:
grace_period: 30m # 30 minutes grace period During grace period:
- Environment is marked as
EXPIRED - Warning banner shown to all users
- Final checkpoint created
- Environment can still be extended
# Extend expired environment (during grace period)
teactl env extend march-training --add 2h Final Checkpoint
Before termination, Teabar can create a final checkpoint:
ttl:
final_checkpoint: true
checkpoint_retention: 30d # Keep final checkpoint for 30 days Access final checkpoints:
# List checkpoints including final ones
teactl checkpoint list --include-final
# Restore from final checkpoint
teactl env create --from-checkpoint march-training-final Cleanup Process
When TTL expires and grace period ends:
- Pre-termination hook runs (if configured)
- Final checkpoint created (if enabled)
- Environment terminated - all resources deleted
- Notification sent - confirmation of cleanup
- Billing stopped - no further charges
Pre-termination Hook
Run custom scripts before cleanup:
ttl:
pre_termination:
- name: Export data
command: /scripts/export-data.sh
timeout: 5m Cost Implications
TTL directly impacts costs:
# View cost projection based on TTL
teactl env get march-training --show-cost-projection
# Output:
# Current cost: $12.50
# TTL remaining: 4h
# Projected total: $18.50 Cost Optimization Tips
- Set appropriate TTLs - Don’t use longer than needed
- Use sleep mode - Pause TTL and reduce compute costs
- Extend incrementally - Add small amounts vs. removing TTL
- Review expiring envs - Clean up before they expire
CLI Reference
| Command | Description |
|---|---|
teactl env create --ttl <duration> | Create with TTL |
teactl env create --no-ttl | Create without TTL |
teactl env extend --add <duration> | Add time to TTL |
teactl env extend --until <datetime> | Set absolute expiration |
teactl env extend --no-ttl | Remove TTL |
teactl env list --expiring | List expiring environments |
teactl env get --show-ttl-source | Show TTL configuration source |