Home Explore Blog CI



kubernetes

2nd chunk of `content/en/blog/_posts/2017-05-00-Draft-Kubernetes-Container-Development.md`
5d4cc69b5c1903d8b51e7b81979799b60edde9c7e4dcab430000000100000ab5
$ cd examples/python
  ```


**Draft Create**  

We need some "scaffolding" to deploy our app into a [Kubernetes](https://kubernetes.io/) cluster. Draft can create a [Helm](https://github.com/kubernetes/helm) chart, a Dockerfile and a draft.toml with draft create:  


 ```
$ draft create

--\> Python app detected

--\> Ready to sail

$ ls

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](https://hub.docker.com/_/python/), 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
  ```



**Draft Up**



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 registry
- draftd 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:  
     1. Get the application URL by running these commands:  
     NOTE: It may take a few minutes for the LoadBalancer IP to be available.  
           You can watch the status of by running 'kubectl get svc -w tufted-lamb-tufted-lamb'  
  export SERVICE\_IP=$(kubectl get svc --namespace default tufted-lamb-tufted-lamb -o jsonpath='{.status.loadBalancer.ingress[0].ip}')  

Title: Using Draft: Creating and Deploying a Python Application
Summary
This section walks through creating and deploying a sample Python application using Draft. The `draft create` command generates the necessary Dockerfile, Helm chart, and `draft.toml` file for deployment. The `draft.toml` file contains basic configuration, including the application name, namespace, and watch settings. Subsequently, the `draft up` command builds a Docker image, pushes it to a registry, and deploys the application to a Kubernetes cluster using Helm. With the 'watch' option enabled, Draft monitors for local file changes, automatically rebuilding and redeploying the application.