Activating and deactivating apps
Apps deployed with flyte.deploy() and apps served with flyte.serve() are activated automatically. Use deactivate() and activate() to turn a deployed app off and on.
Activation
Activate an app
When you get an app by name, you get the current app instance:
Check activation status
Check if an app is active:
app = App.get(name="my-app")
print(f"Active: {app.is_active()}")
print(f"Revision: {app.revision}")
Deactivation
Deactivate an app when you no longer need it:
app = App.get(name="my-app")
app.deactivate()
print(f"Deactivated app: {app.name}")
Lifecycle management
Typical deployment workflow
# 1. Deploy new version
deployments = flyte.deploy(
app_env,
version="v2.0.0",
)
# 2. Get the deployed app
new_app = App.get(name="my-app")
# Test endpoints, etc.
# 3. Activate the new version
new_app.activate()
print(f"Deployed and activated version {new_app.revision}")
Blue-green deployment
For zero-downtime deployments:
# Deploy new version without deactivating old
new_deployments = flyte.deploy(
app_env,
version="v2.0.0",
)
new_app = App.get(name="my-app")
# Test new version
# ... testing ...
# Switch traffic to new version
new_app.activate()
print(f"Activated revision {new_app.revision}")
Using CLI
Activate
flyte update app --activate my-appDeactivate
flyte update app --deactivate my-appCheck status
flyte get app my-appUse --project and --domain to target a specific project-domain pair.
For all available options, see the CLI reference.
Best practices
- Test before deploying: Test with serve or a dry run before deploying
- Version management: Keep track of which version is active
- Blue-green deployments: Use blue-green for zero-downtime
- Monitor: Monitor apps after activation
- Cleanup: Deactivate and remove old versions periodically
Automatic activation with serve
Apps served with flyte.serve() are automatically activated:
# Automatically activated
app = flyte.serve(app_env)
print(f"Active: {app.is_active()}") # True
This is convenient for development. For production, use flyte.deploy(), which also activates the app, and use deactivate() and activate() to control it afterwards.
Example: Complete deployment and activation
app_env = flyte.app.AppEnvironment(
name="my-prod-app",
# ... configuration ...
)
if __name__ == "__main__":
flyte.init_from_config()
# Deploy
deployments = flyte.deploy(
app_env,
version="v1.0.0",
project="my-project",
domain="production",
)
# Get the deployed app
app = App.get(name="my-prod-app")
# Activate
app.activate()
print(f"Deployed and activated: {app.name}")
print(f"Revision: {app.revision}")
print(f"URL: {app.url}")
print(f"Active: {app.is_active()}")
Troubleshooting
App not accessible after activation:
- Verify activation succeeded
- Check app logs for startup errors
- Verify cluster connectivity
- Check that the app is listening on the correct port
Activation fails:
- Check that the app was deployed successfully
- Verify app configuration is correct
- Check cluster resources
- Review deployment logs
Cannot deactivate:
- Ensure you have proper permissions
- Check if there are dependencies preventing deactivation
- Verify the app name and version