Simplifying Source to Container Deployment for DevOps with Draft on Kubernetes
Source to Deployment Workflows
Common open source tools that streamline end-to-end container build and deployment workflows include:
- Draft: A Helm-based tool to simplify container development and deployment
- Skaffold: Similar to Draft but does not include native Helm support
- Metaparticle: A collection of standard libraries for building cloud-native applications, available at https://metaparticle.io
CI/CD Tools
Popular CI/CD platforms for Kubernetes-native DevOps workflows:
- Jenkins X
- Spinnaker
- Argo
- Flux (GitOps-based)
Auxiliary Tools
- Kompose: Converts existing Docker Compose configurations to Kubernetes manifests
Draft Overview
Draft is an open source container application development tool originally built by Microsoft's Deis team (hosted at https://github.com/azure/draft). It cuts down complexity for developers building containerized applications for Kubernetes.
Core functionality of Draft is centered around three key commands:
draft init: Configures container registry credentials and deploys thedraftdserver component to your Kubernetes cluster.draftdhandles image building, registry pushes, and application deployments.draft create: Automatically detects your application's programming language via built-in packs, then generates a matching Dockerfile and Kubernetes Helm chart for your project.draft up: Builds the container image from your Dockerfile, uses Helm to deploy the application to any Kubernetes cluster (local or remote). It also runs a local client that watches for code changes and automatically triggers updates to the running deployment.
Installing Draft
Draft requires a runing Kubernetes cluster before installation. Complete these prerequisites first:
- Install and initialize Helm (v2.4.x, do not forget to run
helm initafter installation) - Register an account with a container registry (e.g. Docker Hub or Quay.io)
- Deploy an Ingress Controller and configure a wildcard DNS A record for
*.<your-base-domain>pointing to the Ingress Controller's external IP
quickest way to deploy an NGINX Ingress Controller via Helm is:
# Deploy NGINX Ingress Controller to the cluster
helm install stable/nginx-ingress --namespace=kube-system --name=nginxingress
# Wait for the controller to become ready and fetch its external IP
kubectl --namespace kube-system get services -w nginxingress-nginx-ingress-controller
Once your cluster and Helm are configured, download the Draft binary and initialize your local configuration:
# Replace the values below with your own registry credentials
encoded_creds=$(echo '{"username":"your-username","password":"your-password","email":"your-email@example.com"}' | base64 -w 0)
# Update the registry URL, organization and base domain to match your setup
draft init --set registry.url=docker.io,registry.org=your-username,registry.authtoken=${encoded_creds},basedomain=your-base-domain.com
Getting Started with Draft
Draft's source repository includes working examples for many common programming languages. Below we walk through building and deploying a simple Python web application with Draft.
Clone the Example Project
git clone https://github.com/Azure/draft.git
cd draft/examples/python
ls
# Output: app.py requirements.txt
cat requirements.txt
# Output: flask
cat app.py
from flask import Flask
app = Flask(__name__)
@app.route('/')
def hello_world():
return "Hello, World!\n"
if __name__ == '__main__':
app.run(host='0.0.0.0', port=8080)
Generate Project Configuration with draft create
Run draft create to auto-generate all required configuration files for your project:
draft create
# Output:
# --> Python app detected
# --> Ready to sail
ls
# Output: Dockerfile app.py chart/ draft.toml requirements.txt
cat Dockerfile
FROM python:onbuild
EXPOSE 8080
ENTRYPOINT ["python"]
CMD ["app.py"]
cat draft.toml
[environments]
[environments.development]
name = "python-demo"
namespace = "default"
watch = true
watch_delay = 2
Build and Deploy with draft up
Trigger the full build, push, and deploy workflow with a single command:
draft up
# Output:
# --> Building Dockerfile
# Step 1 : FROM python:onbuild
# onbuild: Pulling from library/python
# ...
# Successfully built <image-id>
# --> Pushing docker.io/your-username/python-demo:<unique-hash>
# ...
# --> Deploying to Kubernetes
# Release "python-demo" does not exist. Installing it now.
# --> Status: DEPLOYED
# --> Notes:
# http://python-demo.your-base-domain.com to access your application
# Watching local files for changes...
Access You're Deployed Application
Open a new terminal window and test your application via the automatically generated subdomain:
curl python-demo.your-base-domain.com
# Output: Hello, World!