This document shows how to deploy a "Hello World" app with Draft. If you haven't 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/example-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 97.267760% 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 = "example-python"
namespace = "default"
wait = false
watch = false
watch_delay = 2
See DEP 6 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's .helmignore file.
Now we're ready to deploy this app 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
builds the docker image and pushes the image to a registrydraftd
instructs helm to install the chart, referencing the image just built
$ draft up
Draft Up Started: 'example-python'
example-python: Building Docker Image: SUCCESS ⚓ (73.0991s)
example-python: Pushing Docker Image: SUCCESS ⚓ (69.1425s)
example-python: Releasing Application: SUCCESS ⚓ (0.6875s)
example-python: Build ID: 01BSY5R8J45QHG9D3B17PAXMGN
Now that the application has been deployed, we can connect to our app.
$ draft connect
Connecting to your app...SUCCESS...Connect to your app on localhost:55139
Starting log streaming...
172.17.0.1 - - [13/Sep/2017 19:10:09] "GET / HTTP/1.1" 200 -
Note that it may take some time for the app to deploy, so if you see a message like "Error: could not find a ready pod", just wait a little longer for the image to be deployed.
draft connect
works by creating a local environment for you to test your app. It proxies a connection from the pod running in minikube to a localhost url that you can use to see your application working. It will also print out logs from your application.
In another terminal window, we can connect to our app using the address displayed from draft connect
's output.
$ curl localhost:55139
Hello, World!
Once you're done playing with this app, cancel out of the draft connect
session using CTRL+C.
Now, let's change the output in app.py
to output "Hello, Draft!" instead:
$ cat <<EOF > app.py
from flask import Flask
app = Flask(__name__)
@app.route("/")
def hello():
return "Hello, Draft!\n"
if __name__ == "__main__":
app.run(host='0.0.0.0', port=8080)
EOF
When we call draft up
again, Draft determines that the Helm release already exists and will perform a helm upgrade
rather than attempting another helm install
:
$ draft up
Draft Up Started: 'example-python'
example-python: Building Docker Image: SUCCESS ⚓ (13.0127s)
example-python: Pushing Docker Image: SUCCESS ⚓ (16.0272s)
example-python: Releasing Application: SUCCESS ⚓ (0.5533s)
example-python: Build ID: 01BSYA4MW4BDNAPG6VVFWEPTH8
We should notice a significant faster build time here. This is because Docker is caching unchanged layers and only compiling layers that need to be re-built in the background.
Now when we run draft connect
and open the local URL using curl
or our browser, we can see our app has been updated!
$ curl localhost:55196
Hello, Draft!