Getting Started
In this guide, we’ll deploy a FastAPI service for solving the Iris classification problem. Iris flower has 3 species: Iris setosa, Iris versicolor, and Iris virginica. The problem involves predicting the species of an iris flower based on its sepal length, sepal width, petal length, and petal width.
The model has 4 inputs: sepal length, sepal width, petal length, and petal width and ouputs the confidence scores for each species in the following format:
We’ve already created a FastAPI service for the Iris classification problem, and you can find the code in our GitHub Repository.
Please visit the repository to familiarize yourself with the code you’ll be deploying. The project files are organized as follows:
Getting Started With Deployment
To deploy a service, you’ll need a workspace. If you don’t have one, you can create it using this guide: Creating a Workspace or seek assistance from your cluster administrator in case you don’t have permission to create a workspace.
In TrueFoundry, you can either deploy code from your Github repository or from your local machine in case the code is not pushed to a Github repository.
In the above walkthrough, we did the following steps:
- Select a workspace to deploy the service. This basically decides which cluster and environment the service will be deployed to.
- Select the Service option since this is a FastAPI service and exposed a REST API.
- We chose the Github option since the code is already pushed to a Github repository.
The key fields that we need to fill up in the deployment form are:
Repo Url
: This is the URL of the Github repository that contains the code for the service. For this example, the repo url is https://github.com/truefoundry/getting-started-examplesPath to build context
: This is the path to the directory in the Github repository that contains the code for the service. For this example, the path to the build context is./deploy-model-with-fastapi/
Command
: This is the command to run the service. For this example, the command isuvicorn app:app --host 0.0.0.0 --port 8000
Port
: This is the port on which the service will be exposed. Since we have mentioned port 8000 in the command above, so we need to specify the port here as 8000.
On filling up the form, we can press the Submit button to deploy the service.
In the above walkthrough, we did the following steps:
- Select a workspace to deploy the service. This basically decides which cluster and environment the service will be deployed to.
- Select the Service option since this is a FastAPI service and exposed a REST API.
- We chose the Github option since the code is already pushed to a Github repository.
The key fields that we need to fill up in the deployment form are:
Repo Url
: This is the URL of the Github repository that contains the code for the service. For this example, the repo url is https://github.com/truefoundry/getting-started-examplesPath to build context
: This is the path to the directory in the Github repository that contains the code for the service. For this example, the path to the build context is./deploy-model-with-fastapi/
Command
: This is the command to run the service. For this example, the command isuvicorn app:app --host 0.0.0.0 --port 8000
Port
: This is the port on which the service will be exposed. Since we have mentioned port 8000 in the command above, so we need to specify the port here as 8000.
On filling up the form, we can press the Submit button to deploy the service.
Clone the github repository and navigate to the deploy-model-with-fastapi
directory.
To deploy from your local machine, you can follow the steps on the UI to get the deployment script.
Once you reach the last step, you will be able to download a deploy.py script that contains the configuration for the deployment.
The deploy.py should be placed in the root of your project.
The deploy.py has a field called project_root_path
in the build_source section.
The project_root_path is considered relative to where the command python deploy.py
is executed from.
The build_context_path is relative to the project_root_path.
All the code in the build_context_path
will be packaged into a docker image and deployed.
It’s usually recommended to use ”./” as the project_root_path, put the deploy.py
in that path and execute the command python deploy.py
from the project_root_path directory.
The directory structure will then appear as follows:
To deploy, execute the command:
After running the command mentioned above, wait for the deployment process to complete. Monitor the status until it shows DEPLOY_SUCCESS:
, indicating a successful deployment.
Once deployed, you’ll receive a dashboard access link in the output, typically mentioned as You can find the application on the dashboard:
. Click this link to access the deployment dashboard.
View your deployed service
Congratulations! You’ve successfully deployed your FastAPI service.
Once you click Submit
, your deployment will be successful in a few seconds, and your service will be displayed as active (green), indicating that it’s up and running.
You can view all the information about your service following the steps below:
To make a request to the Service, you can copy the endpoint URL as shown on the UI or from what you provided in the Ports section. The endpoint will be an internal cluster URL or an external URL based on whether you chose Expose in the Ports configuration. You can read about it more in the Ports section. You can call the service using curl or Postman or using the Python code as shown below: