Draft is an open-source project that helps developers go from a noncontainerized application to running on Kubernetes with ease. As a developer with Draft, you don't have to go through an extensive ramp of containers, container registries, Kubernetes, and deployment methods to get your app running as a container on Azure Kubernetes Services.
Avatar
Latest posts by Steve Buchanan (see all)

Microsoft acquired container platform Deis from Engine Yard in 2017. You can read about that here. Deis is behind some of the most popular tools for building and managing applications on Kubernetes. Their projects include Helm, Brigade, and Containerd Wasm Shims. They also built Draft.

Draft streamlines the containerization of apps for Azure Kubernetes Service by detecting your application's language from the code, generating the needed Dockerfile, pushing it to a container registry as an image, generating the needed Kubernetes manifests or Helm charts for deployment, and then deploying the app to your Kubernetes cluster via a GitHub Actions workflow.

If you go with Helm or Kustomize, Draft generates what is needed to support these artifact types. If you chose Helm, Draft creates a charts folder in your app directory with the chart YAML files and a values.yaml file containing your app's specifics. If you choose Kustomize, Draft creates the overlays directory and a production directory inside with the necessary deployment and kustomization.yaml files. Draft simplifies creating the artifacts needed to run your app on Kubernetes so that you can stay more focused on building and maintaining the app itself.

Deis still exists but has been renamed to Deis Labs with a bolstered team of new colleagues and resources within the Cloud Native Compute Team of Microsoft. Deis Labs continues to work on open-source projects to this day. One of these projects is Draft.

Currently, there is the open-source version of Draft found here and the newer Draft 2, aka Draft for Azure Kubernetes Service (AKS) (preview), found here. The team at Microsoft decided to breathe new life into Draft, releasing an updated version and integrating the Draft experience into AKS. Draft 2 is wrapped up in the Azure CLI as an extension and works directly with the cloud now. One difference between the versions can be seen in the commands you run with Draft:

Draft commands start with:

draft 

whereas Draft for AKS commands start with this command:

az aks draft

Future versions of Draft will add it as a GUI-based extension in Visual Studio Code, and later bring Draft into the Azure portal.

In this blog post, I will walk you through containerizing a JavaScript-based app and running it on AKS using Draft for AKS. Note that the Azure Kubernetes Service (AKS) DevX Extension for Visual Studio Code (Preview) has been released. It is an early version that includes Draft, so it is still a work in progress. I will cover it in a future blog post. In this blog post, we will:

  • Create a Dockerfile
  • Create the Kubernetes manifest files for deployment and service
  • Connect our Azure to our GitHub repository
  • Create a GitHub Actions workflow
  • Run the GitHub Actions workflow to build our containerized app, push it to the Azure Container Registry, and deploy our app on Azure Kubernetes Service

Prerequisites

  • Azure subscription
  • Resource group to hold all components
  • Azure Container Registry
  • AKS cluster
  • Application code hosted in a GitHub repository
  • VS Code
  • Azure CLI installed and logged into a proper Azure subscription
  • GitHub CLI installed and logged into a GitHub.com account
  • aks-preview Azure CLI extension
  • Ability to run all code from the VS Code Bash terminal

I will cover one prerequisite here, as it is specific to the scenario in this article. You will need the aks-preview Azure CLI extension installed in your VS Code after you have the Azure CLI. To install the aks-preview Azure CLI extension, run the following from the Bash terminal in VS code:

# Install the aks-preview extension
az extension add --name aks-preview
# Update the extension to make sure you have the latest version installed
az extension update --name aks-preview

Now, let us dive into the steps to go from a noncontainerized app to an app running on AKS.

Create your Dockerfile

Run az aks draft to create the Dockerfile in your app folder. Draft will automatically detect the language of the app. As shown in the screenshot, it knew that my app was JavaScript-based.

Enter the port your app will use. Draft will then create a Dockerfile for the app.

Dockerfile creation port

Dockerfile creation port

NOTE: Test the Dockerfile locally to ensure it runs. If it does not run locally, it will error out during the GitHub Action workflow > Build and push to ACR.

To test locally, use Docker Desktop and run:

docker build -t NAMEOFYOURIMAGE .
docker run -d --name NAMEOFCONTAINER NAMEOFYOURIMAGE

Create Kubernetes deployment files

After Draft creates the Dockerfile, it will then prompt you to create a K8s deployment. Notice how you can navigate via arrows.

Kubernetes deployment type

Kubernetes deployment type

After you choose manifests, it will prompt you for the exposed port.

Kubernetes manifest creation port

Kubernetes manifest creation port

It will then prompt you for the name of the app.

Kubernetes manifest creation app name

Kubernetes manifest creation app name

It then creates a K8s manifest file.

Kubernetes manifest creation finish

Kubernetes manifest creation finish

NOTE: The name of the app should be lowercase. If not, it will fail during K8s deployment later.

If you run ls on the directory or navigate to it, you can see the Dockerfile and a folder with the manifest files for K8s deployment and service.

Display of Dockerfile and Kubernetes Manifests folder in the app directory

Display of Dockerfile and Kubernetes Manifests folder in the app directory

Kubernetes manifests in the app directory

Kubernetes manifests in the app directory

Connect Azure to the GitHub repository

Ensure you have the GitHub CLI installed. Instructions can be found here.

Run the following command to ensure you are logged into your GitHub.com account from VS Code:

gh auth login
Process for logging into GitHub.com using the GitHub CLI

Process for logging into GitHub.com using the GitHub CLI

Note: Create your resource group before this. Ensure that this is the same resource group that contains your AKS cluster and ACR.

Next, run this command:

az aks draft setup-gh
OIDC Azure GitHub connection setup prompts

OIDC Azure GitHub connection setup prompts

NOTE: Do not include https://github.com/ after Enter github organization and repo (organization/repoName). Enter it in this format instead: Buchatech/ContainerizedTodoApp.

OIDC setup status

OIDC setup status

After a couple of minutes, it will complete.

OIDC setup success

OIDC setup success

You should see the new app registration in your Azure subscription under Azure Active Directory > App registrations.

Display of new app registration in Azure Portal.jpg

Display of new app registration in Azure Portal.jpg

In the app registration, you should see the following credentials indicating that OIDC has been set up to connect to your GitHub repo.

Displaying Federal Credentials

Displaying Federal Credentials

In your GitHub repo, you should see the following secrets created under Actions:

New Actions secrets in GitHub

New Actions secrets in GitHub

Create the GitHub Action workflow

Note that you should have an Azure Container Registry and an AKS cluster created before continuing.

In your VS code bash terminal, run az aks draft generate-workflow

Generate workflow setup prompts

Generate workflow setup prompts

The YAML file is generated for the GitHub Actions workflow in your app folder.

Display of new GitHub Actions workflow YAML file

Display of new GitHub Actions workflow YAML file

Commit all the files to your repository, and the GitHub Actions workflow will start. The GitHub Actions workflow will build, push your container to ACR, and deploy the app to the AKS cluster.

Display of all files committed to the GitHub repo

Display of all files committed to the GitHub repo

In GitHub, click Actions to see your workflow starting to run, as shown in the following screenshot.

GitHub Actions workflow queued status

GitHub Actions workflow queued status

If you click the workflow run, you can see a summary of the workflow jobs, as shown in the following screenshots:

GitHub Actions workflow jobs status

GitHub Actions workflow jobs status

The GitHub Actions workflow should complete quickly.

GitHub Actions workflow completed status

GitHub Actions workflow completed status

After the workflow completes, you can go into AKS on the Azure Portal and see the secret that the workflow created in your AKS cluster, as shown in the following screenshot:

New secret in AKS.png

New secret in AKS

In AKS, click Workloads to see that the containerized app deployment is up and running on AKS.

App workload in AKS

App workload in AKS

You can see the load balancer for the app and its external IP by clicking Services and ingresses in AKS. The load balancer and external IP will be shown on the Services tab, as shown in the following screenshot:

New LoadBalancer service in AKS

New LoadBalancer service in AKS

You can click the external IP to access the app in the browser, as shown in the following screenshot:

Subscribe to 4sysops newsletter!

Example of a containerized JavaScript app in the browser

Example of a containerized JavaScript app in the browser

Thanks for reading this blog post. The next step is to go try out Draft for AKS on your own.

avatar
0 Comments

Leave a reply

Please enclose code in pre tags: <pre></pre>

Your email address will not be published. Required fields are marked *

*

© 4sysops 2006 - 2023

CONTACT US

Please ask IT administration questions in the forums. Any other messages are welcome.

Sending

Log in with your credentials

or    

Forgot your details?

Create Account