Python (Polls) Example App
Estimated Time: 10 minutes
Although you normally need your own cluster to use Kelda, this guide uses a precreated Hosted Kelda cluster so that you can dive right in to the example app.
In this guide we will deploy the Polls Python application, observe Kelda syncing an update to our code, and take a look at the application's Kelda config files. If you're trying to use Kelda with a Python app, we recommend that you start with this doc.
Run the following command to download and install Kelda.
curl -fsSL 'https://kelda.io/install.sh' | sh
Download the Kelda examples repository
This repository contains the source code and Kelda config for Polls.
git clone https://github.com/kelda-inc/examples
Configure Kelda to work on the Polls project
The following command creates a file that's required for the
keldacommands to work.
Most users can just use the defaults by hitting [Enter] for each prompt.
In the root directory of the examples repository, run:
If the command succeeded, you should see something like:
Wrote config to /Users/kevin/.kelda.yaml
Kelda maintains a public cluster for demos. If you've already setup a Kelda cluster, just omit the
Developing with Kelda
Start development on the Polls service
Run the following command from the examples repo. It will boot the Polls service and its dependencies, start the code syncing, and start the tunnel to the app's frontend.
kelda dev ./django-polls/src
Wait for all of the services to become
Ready. The first boot may take several minutes while all the services boot.
View the Poll frontend
Open http://localhost:8000 in your browser, click the "Cats or dogs?" link, then cast your vote.
Modify the service code to show the poll results
django-polls/src/polls/templates/polls/index.htmlto delete the comment elements on lines 13 and 19. Save the changes. Kelda will sync the change into your development environment and and restart the Django server.
View the change in your browser
Reload http://localhost:8000. You will see the results of the poll now. Cast a few more votes to guarantee victory for your side.
Exit Kelda by entering
Ctrl + cinto the terminal window where the Kelda CLI is running.
Delete your development namespace
kelda deleteto delete your development namespace so that it stops consuming resources in the remote cluster.
Deep Dive into the Kelda Configuration
Let's take a closer look at this project's Kelda configuration files to better understand what Kelda is doing under the hood.
First, take a look at the workspace.yaml file. Every Kelda project requires this Workspace config file. It defines the services that will be deployed into Kubernetes.
The Polls app has three services:
setup-db. The Kubernetes YAML
for the services are stored in the same directory as the
||This service deploys a Python Docker container and runs the Django server on port 8000.|
||This service deploys and configures a Postgres database container. The Polls Django application stores the polls and votes in this database.|
||This service is a Kubernetes job (as opposed to the previous deployments) so it runs a single time then stops. It contains an init container, which in this case waits until Postgres is fully deployed, before initializing the database and importing data.|
In the Kelda CLI window you will see each of these services and their
Completed when the job finishes running,
Synced when the initial sync finishes, and
the database is ready to accept connections.
tunnels section of the
workspace.yaml file sets up the HTTP tunnel to the cluster.
It tunnels port 8000 on
localhost to port 8000 in the
This lets you easily and privately access the app on the cluster.
Please see our guide on writing the Workspace configuration for more information.
Another required Kelda file is kelda.yaml. This is the Sync configuration for the project. It starts the Django server, performs an initial sync based on the defined rules, then resyncs files as they are changed.
|1||version||The Kelda config format version.|
|2||name||The name of the service that Kelda is syncing to. It must match a service in the output of
|3||image||The Docker image used by the cluster,
|4||command||The commands that are run after each sync. For the Polls app, the command starts the Django server. The
|5||initCommand||The commands that are run after a sync on any rule with
|6-11||sync||The local and remote paths of files to sync.|
Please see our guide on writing the Sync configuration for more information.