This document shows how to deploy a "Hello World" app with Draft. If you havent done so already, be sure you have Draft installed according to the Installation Guide.
There are multiple example applications included within the examples directory. For this walkthrough, we'll be using the python example application which uses Flask to provide a very simple Hello World webserver.
$ cd examples/python
We need some "scaffolding" to deploy our app into a Kubernetes cluster. Draft can create a Helm chart, a Dockerfile
and a draft.toml
with draft create
:
$ draft create
--> Draft detected the primary language as Python with 85.990338% certainty.
--> Ready to sail
$ ls -a
.draftignore Dockerfile app.py chart/ draft.toml requirements.txt
The chart/
and Dockerfile
assets created by Draft default to a basic Python
configuration. This Dockerfile
harnesses the python:onbuild
image, which will install the dependencies in requirements.txt
and copy the current directory
into /usr/src/app
. And to align with the service values in chart/values.yaml
, this Dockerfile
exposes port 80 from the container.
The draft.toml
file contains basic configuration about the application like the name, which
namespace it will be deployed to, and whether to deploy the app automatically when local files
change.
$ cat draft.toml
[environments]
[environments.development]
name = "tufted-lamb"
namespace = "default"
watch = true
watch_delay = 2
See the Draft User Guide for more information and available configuration on the
draft.toml
.
A .draftignore
file is created as well for elements we want to exclude tracking on draft up
when watching for changes. The syntax is identical to
helm ignore feature.
Note that for technical reasons, the .git/
directory is unconditionally ignored for now.
Now we're ready to deploy app.py
to a Kubernetes cluster.
Draft handles these tasks with one draft up
command:
- reads configuration from
draft.toml
- compresses the
chart/
directory and the application directory as two separate tarballs - uploads the tarballs to
draftd
, the server-side component draftd
then builds the docker image and pushes the image to a registrydraftd
instructs helm to install the Helm chart, referencing the Docker registry image just built
With the watch
option set to true
, we can let this run in the background while we make changes
later on...
$ draft up
--> Building Dockerfile
Step 1 : FROM python:onbuild
onbuild: Pulling from library/python
...
Successfully built 38f35b50162c
--> Pushing docker.io/microsoft/tufted-lamb:5a3c633ae76c9bdb81b55f5d4a783398bf00658e
The push refers to a repository [docker.io/microsoft/tufted-lamb]
...
5a3c633ae76c9bdb81b55f5d4a783398bf00658e: digest: sha256:9d9e9fdb8ee3139dd77a110fa2d2b87573c3ff5ec9c045db6009009d1c9ebf5b size: 16384
--> Deploying to Kubernetes
Release "tufted-lamb" does not exist. Installing it now.
--> Status: DEPLOYED
--> Notes:
http://tufted-lamb.example.com to access your application
Watching local files for changes...
Using the handy output that follows successful deployment, we can now contact our app.
$ curl http://tufted-lamb.example.com
Hello Draft!
When we curl
our app, we see our app in action! A beautiful "Hello Draft!" greets us. If not, make sure you've followed the Ingress Guide.
Now, let's change the output in app.py
to output "Hello Kubernetes!" instead:
$ cat <<EOF > app.py
from flask import Flask
app = Flask(__name__)
@app.route("/")
def hello():
return "Hello Kubernetes!\n"
if __name__ == "__main__":
app.run(host='0.0.0.0', port=8080)
EOF
Now if we watch the terminal that we initially called draft up
with, Draft will notice that there
were changes made locally and call draft up
again. Draft then determines that the Helm release
already exists and will perform a helm upgrade
rather than attempting another helm install
:
--> Building Dockerfile
Step 1 : FROM python:onbuild
...
Successfully built 9c90b0445146
--> Pushing docker.io/microsoft/tufted-lamb:f031eb675112e2c942369a10815850a0b8bf190e
The push refers to a repository [docker.io/microsoft/tufted-lamb]
...
--> Deploying to Kubernetes
--> Status: DEPLOYED
--> Notes:
http://tufted-lamb.example.com to access your application
Now when we run curl http://tufted-lamb.example.com
, we can see our app has been updated and deployed to Kubernetes automatically!