How app deployment works
Deployment is the recommended way to deploy apps to production. It creates versioned, immutable app deployments.
Overview
When you deploy an app, the following happens:
- Code bundling: Your app code is bundled and prepared
- Image building: Container images are built (if needed)
- Deployment: The app is deployed to your Flyte cluster
- Activation: The app is automatically activated and ready to use
Using the Python SDK
Deploy an app:
app_env = flyte.app.AppEnvironment(
name="my-prod-app",
# ...
)
if __name__ == "__main__":
flyte.init_from_config()
deployments = flyte.deploy(app_env)
# Access deployed apps from deployments
for deployment in deployments:
for deployed_env in deployment.envs.values():
print(f"Deployed: {deployed_env.env.name}")
print(f"URL: {deployed_env.deployed_app.url}")
flyte.deploy() returns a list of Deployment objects. Each Deployment contains a dictionary of DeployedEnvironment objects (one for each environment deployed, including environment dependencies). For apps, the DeployedEnvironment is a DeployedAppEnvironment which has a deployed_app property of type App.
Deployment plan
Flyte automatically creates a deployment plan that includes:
- The app you’re deploying
- All app environment dependencies (via
depends_on)
The app and the environments it reaches through depends_on go into a single plan, and the environments in a plan deploy concurrently. For example, if frontend depends on backend, flyte.deploy(frontend) deploys both and returns a list with one Deployment, whose envs contains both frontend and backend.
Overriding app configuration at deployment time
If you need to override the app configuration at deployment time, you can use the clone_with method to create a new
app environment with the desired overrides.
app_env = flyte.app.AppEnvironment(name="my-app", ...)
if __name__ == "__main__":
flyte.init_from_config()
deployments = flyte.deploy(
app_env.clone_with(app_env.name, resources=flyte.Resources(cpu="2", memory="2Gi"))
)
for deployment in deployments:
for deployed_env in deployment.envs.values():
print(f"Deployed: {deployed_env.env.name}")
print(f"URL: {deployed_env.deployed_app.url}")
Activation/deactivation
Deploying an app activates it. To deactivate a deployed app, or activate it again, use deactivate() and activate() on the App:
if __name__ == "__main__":
flyte.init_from_config()
deployments = flyte.deploy(app_env)
app = App.get(name=app_env.name)
# deactivate the app
app.deactivate()
# activate the app
app.activate()
See Activating and deactivating apps for more details.
Using the CLI
Deploy from the command line:
flyte deploy path/to/app.py appWhere app is the variable name of the AppEnvironment object.
You can also specify the following options. They go before the file path:
flyte deploy \
--version v1.0.0 \
--project my-project \
--domain production \
--dry-run \
path/to/app.py appExample: Full deployment configuration
if __name__ == "__main__":
flyte.init_from_config()
deployments = flyte.deploy(
app_env,
dryrun=False,
version="v1.0.0",
interactive_mode=False,
copy_style="loaded_modules",
)
# Access deployed apps from deployments
for deployment in deployments:
for deployed_env in deployment.envs.values():
app = deployed_env.deployed_app
print(f"Deployed: {deployed_env.env.name}")
print(f"URL: {app.url}")
# Activate the app
app.activate()
print(f"Activated: {app.name}")
Best practices
- Use for production: Deploy is designed for production use.
- Version everything: Always specify versions for reproducibility.
- Test first: Test with serve before deploying to production.
- Manage dependencies: Use
depends_onto manage app dependencies. - Activation strategy: Have a strategy for activating/deactivating apps.
- Use dry-run: Test deployments with
dryrun=Truefirst (--dry-runon the CLI). - Separate environments: Use different projects/domains for different environments.
- Parameter management: Consider using environment-specific parameter values.
Deployment status and return value
flyte.deploy() returns a list of Deployment objects. Each Deployment contains a dictionary of DeployedEnvironment objects:
deployments = flyte.deploy(app_env)
for deployment in deployments:
for deployed_env in deployment.envs.values():
if hasattr(deployed_env, 'deployed_app'):
# Access deployed environment
env = deployed_env.env
app = deployed_env.deployed_app
# Access deployment info
print(f"Name: {env.name}")
print(f"URL: {app.url}")
print(f"Status: {app.deployment_status}")
For apps, each DeployedAppEnvironment includes:
env: TheAppEnvironmentthat was deployeddeployed_app: TheAppobject with properties likeurl,endpoint,name, anddeployment_status
Troubleshooting
Deployment fails:
- Check that all dependencies are available
- Verify image builds succeed
- Review deployment logs
App not accessible:
- Ensure the app is activated
- Check cluster connectivity
- Verify app configuration
Version conflicts:
- Use unique versions for each deployment
- Check existing app versions
- Clean up old versions if needed