Skip to main content

Python Quickstart

This guide will teach you how to setup up the Jetpack backend development platform for the very first time, and how to build and deploy your first backend to a Kubernetes cluster in a matter of minutes.

You don't even need an existing Kubernetes cluster to get started – we'll give you access to a free cluster to get you up and running!

Prerequisites

Docker is required to package your backend as a container before deploying to the cloud.

If you don't already have Docker installed as part of your development environment, follow one of the guides below before returning to this quickstart:

kubectl, while not required, is a useful tool for inspecting and managing your deployments in Kubernetes. We recommend following the installation directions for your platform:

Install the Jetpack CLI

The Jetpack Command Line Interface (CLI) is a command-line tool that helps you create, build and deploy new backends directly from your terminal. It’s simple to install and works for both macOS and Linux.

To install it, run the install script:

curl https://get.jetpack.io -fsSL | bash

Validate the installation by running the jetpack version command

jetpack version
danger

If you see a command not found error instead, double check that your PATH environment variable is set up correctly. The CLI is installed under /usr/local/bin by default and should be included in your PATH.

Login to Jetpack

Next, you'll sign-up for a new Jetpack Cloud account, which will grant you access to a free Kubernetes cluster and a container registry managed by us.

1. Run the following command to authenticate the CLI:

jetpack auth login

2. Create a new account by following the instructions in your browser, or if you already have an account, use your existing credentials to log in.

Your CLI is now linked to your account and it's ready to deploy new backends.

Clone Jetpack's quickstart project

Jetpack can deploy any containerized application to Kubernetes as an autoscaling, Kubernetes deployment. For this quickstart, we'll use a simple example FastAPI app from Jetpack's example repo.

git clone https://github.com/jetpack-io/jetpack-examples.git
cd jetpack-examples/01-py-fastapi-quickstart

Initialize your project

This launch a generator which will ask you a few questions to configure your project. For this quickstart, we'll choose the following options:

  • What is the name of this application? 01-py-fastapi-quickstart
  • Choose your project template Web Service (Since we're creating a web app with an API)
  • Would you like to use Jetpack's trial cluster, or your own Kubernetes cluster? jetpack-cloud (We'll use Jetpack's trial cluster)

Here's the output you'll see:

? What is the name of this application? test-app
? What type of application is this? Web Service
? Would you like to use Jetpack's trial cluster, or your own kubernetes cluster? jetpack-cloud

This will create a jetconifg.yaml in your project folder. This file has the basic configuration that Jetpack will use to deploy your project to Kubernetes.

configVersion: 0.1.2
projectId: #Unique ID goes here
name: py-fastapi-quickstart
cluster: jetpack-cloud
services:
test-app:
type: web
port: 8080

Deploy to Kubernetes

Step 1: Deploy the Test App with Jetpack Dev

We are now ready to deploy our example app! We'll deploy using jetpack dev , which will stream our service's logs to our terminal and let us quickly redeploy any changes that we make.

From within the quickstart-project folder, run:

jetpack dev

This will create and build a Docker container for your project, push it to the container registry, and deploy it to the Kubernetes cluster. Once it finishes deploying, the CLI will stream your logs and port-forward from your local machine to the running container, so that you can test it live in the cluster:

# [Done] App deployed
Attempting to port forward app...
The service will be accessible at http://localhost:8080
- this port forwards to port 8080 on the pod
Attempting to port forward runtime...
The service will be accessible at http://localhost:8090
- this port forwards to port 8080 on the pod
+ jetpack-runtime-7c46d5cd7b-d2ksj › jetpack-runtime
+ new-project-app-68b9f8cddf-xgpzg › app
new-project-app-68b9f8cddf-xgpzg app INFO: Started server process [1]
new-project-app-68b9f8cddf-xgpzg app INFO: Waiting for application startup.
new-project-app-68b9f8cddf-xgpzg app INFO: Application startup complete.
new-project-app-68b9f8cddf-xgpzg app INFO: Uvicorn running on http://0.0.0.0:8080 (Press CTRL+C to quit)

Step 2: Test your Service

When Jetpack finishes deploying, you can test the service at http://localhost:8080 using curl, httpie, or your browser:

curl localhost:8080

You should see the response:

<h1>Hello! Welcome to Jetpack</h1>

Cleanup

You now have a project up and running in a Kubernetes cluster – let's bring it down now that we are done so that it doesn't stay consuming resources in the background.

To bring the project down run the jetpack down command:

jetpack down

Next Steps

Now that you've created and deployed your first project to Jetpack, head over to our Guides section to learn more about the different types of backends you can build with our SDK: