Draft

Installation

Draft requires the following:

  • Cloud-provided Kubernetes cluster (Azure Container Services used here, see Introduction)
  • Helm installed on Kubernetes cluster (see Helm)
  • Docker registry
  • Ingress controller

Sadly, there is no Windows version yet. There is a Linux and macOS version. For Linux, see https://azuredraft.blob.core.windows.net/draft/draft-canary-linux-amd64.tar.gz.

You can download the tool in the Windows 10 Linux shell and unpack it:

wget https://azuredraft.blob.core.windows.net/draft/draft-canary-linux-amd64.tar.gz
tar -zxvf draft-canary-linux-amd64.tar.gz

The above unpacks draft to a Linux-amd64 folder. Move the draft executable to a folder in the PATH like /usr/local/bin.

Naturally, also install kubectl in the Linux shell and point it to your Kubernetes cluster (you can copy the .ssh and .kube folders). Also install Helm in the Linux shell.

Now we are ready to install the server-side of Draft:

draft init --set registry.url=docker.io,registry.org=orgname,registry.authtoken=auth_token,
    basedomain=baeke.info

I created a * A record for baeke.info that points to the Ingress Controller.

To build the auth token for Docker Hub or Quay:

echo '{"username":"jdoe","password":"secret","email":"[email protected]"}' | base64 --wrap=0

Using Draft

Let's use Draft with the Golang example from GitHub. Get glide.yaml and main.go from that location and put in in some folder on your localmachine.

main.go contains the following code:

package main

import (
    "fmt"
    "net/http"
)

func handler(w http.ResponseWriter, r *http.Request) {
    fmt.Fprintf(w, "Hello World, I'm Golang!")
}

func main() {
    http.HandleFunc("/", handler)
    http.ListenAndServe(":8080", nil)
}

Pretty clear that this listens for an incoming HTTP request on port 8080 and gives back a simple response. the glide.yaml file is for Glide, a vendor package manager for Go. Note that in this sample, that file is empty but required.

The idea is to let Draft create a Helm chart and a Docker file. Run the following command from the folder that contains main.go:

draft create

The response will be:

--> Go app detected
--> Ready to sail

Inside the folder, you will get:

  • Dockerfile: creates a simple container image from golang:onbuild and exposes 8080
  • draft.toml: basic configuration about the application like name, namespace etc...
  • chart folder: contains a Helm chart for this application

Now we can deploy the app to our Kubernetes cluster with:

draft up

All sorts of stuff will happen now:

  • Read config from .toml file
  • chart directory and application directory compressed and sent to draftd, the sever-side component of draft
  • Docker image gets build (by draftd, not on your local machine)
  • Docker image is pushed to the configured registry (public repo)
  • draftd instructs Helm to install the chart; it references to pushed image

At the end, you will see something like:

The cool thing is you can now just surf to the URL, thanks to the Ingress Controller and the stuff Draft does in the background. Result from curl:

curl http://enervated-sloth.baeke.info
Hello World, I'm Golang!

If you change your application, the change is detected and the process starts again. I changed the HTTP response and in a few seconds, you can curl again to see the change:

curl http://enervated-sloth.baeke.info
Hello World, I'm Golang! Draft is cool!

results matching ""

    No results matching ""