Fading Coder

One Final Commit for the Last Sprint

Home > Tech > Content

Simplifying Source to Container Deployment for DevOps with Draft on Kubernetes

Tech 2

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:

  1. Jenkins X
  2. Spinnaker
  3. Argo
  4. 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 the draftd server component to your Kubernetes cluster. draftd handles 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:

  1. Install and initialize Helm (v2.4.x, do not forget to run helm init after installation)
  2. Register an account with a container registry (e.g. Docker Hub or Quay.io)
  3. 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!

Related Articles

Understanding Strong and Weak References in Java

Strong References Strong reference are the most prevalent type of object referencing in Java. When an object has a strong reference pointing to it, the garbage collector will not reclaim its memory. F...

Comprehensive Guide to SSTI Explained with Payload Bypass Techniques

Introduction Server-Side Template Injection (SSTI) is a vulnerability in web applications where user input is improper handled within the template engine and executed on the server. This exploit can r...

Implement Image Upload Functionality for Django Integrated TinyMCE Editor

Django’s Admin panel is highly user-friendly, and pairing it with TinyMCE, an effective rich text editor, simplifies content management significantly. Combining the two is particular useful for bloggi...

Leave a Comment

Anonymous

◎Feel free to join the discussion and share your thoughts.