# Deploy FastAPI

> Deploy a FastAPI app on Ownkube in minutes. Push your repo and Ownkube builds and ships it, with a live URL and automatic TLS. Managed Postgres and env vars included.

Deploy a [FastAPI](https://fastapi.tiangolo.com/) app on Ownkube in minutes. Push your repo and Ownkube builds it and ships it, and you get a live URL with automatic TLS. Managed Postgres, logs, metrics, and one-click rollbacks come built in. No cloud account to start.

## What you'll need

- A [FastAPI](https://fastapi.tiangolo.com/) app in a GitHub or GitLab repository
- About five minutes

No card required to sign in and look around. Deploying needs a plan: **Personal** is \$5 / month on a prepaid wallet. See [Pricing](/docs/configuration/pricing).

## Deploy it

1. **Connect your repo**

   Sign in at [app.ownkube.io/login](https://app.ownkube.io/login), open [**Settings**](https://app.ownkube.io/dashboard/settings), and connect the GitHub App (or GitLab) so Ownkube can reach your repository. Already have a prebuilt image in a registry? Point Ownkube at it instead. See [Registries](/docs/features/registries).

2. **Create a Web deployment**

   From your [dashboard](https://app.ownkube.io/dashboard), choose **Create deployment**, pick **Web**, and select your FastAPI repo. Ownkube builds it and pushes the image to a registry it manages for you.

3. **Set the port**

   FastAPI apps commonly serve on port **8000** when run with Uvicorn (`uvicorn app.main:app --host 0.0.0.0 --port 8000`, adjusting `app.main:app` to match your module path). Set that as the port so traffic routes to your app. You can change it later in Settings. Bind Uvicorn to `--host 0.0.0.0`, not the default `127.0.0.1`, or the deployment's health checks can't reach your app. For more throughput, run Gunicorn with Uvicorn workers instead of Uvicorn alone.

4. **Add environment variables**

   Add any `KEY=value` pairs your app reads, such as API credentials or a database URL override, and mark secrets with the **Secret** toggle. See [Environment variables](/docs/guides/environment-variables).

5. **Deploy**

   Click **Create deployment**. The deployment page streams the build, then startup and health checks. When the status goes **healthy**, open the generated hostname on the Overview tab. Your FastAPI app is live, with TLS included.

## Database migrations

If you use Alembic or another migration tool, run it before your app serves traffic rather than on startup. Ownkube's [Jobs](/docs/features/jobs) resource runs a container to completion, which makes it the right place for a migration step ahead of a deploy.

## Notes for FastAPI

### Port 8000

FastAPI apps commonly serve on port 8000 via Uvicorn. Set that as the port so Ownkube routes traffic to your app.

### Bind to 0.0.0.0

Uvicorn needs `--host 0.0.0.0`, not the default `127.0.0.1`, or the deployment's health checks can't reach your app.

### Async workers

FastAPI is async by default. If your endpoints do blocking I/O, run more worker processes rather than relying on a single event loop.

### Bring your own Dockerfile

Want full control of the build? Add a `Dockerfile` to your repo and Ownkube uses it, reading the port from its `EXPOSE` line.

## Add a database

Need Postgres? Add a **Database** in one click and Ownkube injects the connection string as `DATABASE_URL` (plus `PGHOST`, `PGUSER`, and friends) into your app. See [Databases](/docs/features/databases).

## Scale and observe

Once you're running, turn on [autoscaling](/docs/features/autoscaling) on CPU and memory, watch [logs and metrics](/docs/features/monitoring) on every deployment, and roll back a bad deploy in one click.

- [Databases](/docs/features/databases)
- [Scheduled jobs](/docs/features/jobs)

---

**Don't see a feature you need?** Email [support@ownkube.io](mailto:support@ownkube.io?subject=Feature%20request). Ownkube is shaped by the teams using it and we ship what our users ask for.
