Quickstart: Develop an application on Kubernetes using Azure Dev Spaces
In this guide, you will learn how to:
- Set up Azure Dev Spaces with a managed Kubernetes cluster in Azure.
- Develop and run code in containers using the command line.
- An Azure subscription. If you don't have an Azure subscription, you can create a free account.
- Azure CLI installed.
Create an Azure Kubernetes Service cluster
You need to create an AKS cluster in a supported region. The below commands create a resource group called MyResourceGroup and an AKS cluster called MyAKS.
az group create --name MyResourceGroup --location eastus az aks create -g MyResourceGroup -n MyAKS --location eastus --disable-rbac --generate-ssh-keys
Enable Azure Dev Spaces on your AKS cluster
use-dev-spaces command to enable Dev Spaces on your AKS cluster and follow the prompts. The below command enables Dev Spaces on the MyAKS cluster in the MyResourceGroup group and creates a default dev space.
$ az aks use-dev-spaces -g MyResourceGroup -n MyAKS 'An Azure Dev Spaces Controller' will be created that targets resource 'MyAKS' in resource group 'MyResourceGroup'. Continue? (y/N): y Creating and selecting Azure Dev Spaces Controller 'MyAKS' in resource group 'MyResourceGroup' that targets resource 'MyAKS' in resource group 'MyResourceGroup'...2m 24s Select a dev space or Kubernetes namespace to use as a dev space.  default Type a number or a new name: 1 Kubernetes namespace 'default' will be configured as a dev space. This will enable Azure Dev Spaces instrumentation for new workloads in the namespace. Continue? (Y/n): Y Configuring and selecting dev space 'default'...3s Managed Kubernetes cluster 'MyAKS' in resource group 'MyResourceGroup' is ready for development in dev space 'default'. Type `azds prep` to prepare a source directory for use with Azure Dev Spaces and `azds up` to run.
Get sample application code
In this article, you use the Azure Dev Spaces sample application to demonstrate using Azure Dev Spaces.
Clone the application from GitHub and navigate into the dev-spaces/samples/nodejs/getting-started/webfrontend directory:
git clone https://github.com/Azure/dev-spaces cd dev-spaces/samples/nodejs/getting-started/webfrontend
Prepare the application
In order to run your application on Azure Dev Spaces, you need a Dockerfile and Helm chart. For some languages, such as Java, .NET core, and Node.js, the Azure Dev Spaces client tooling can generate all the assets you need. For many other languages, such as Go, PHP, and Python, the client tooling can generate the Helm chart as long as you can provide a valid Dockerfile.
Generate the Docker and Helm chart assets for running the application in Kubernetes using the
azds prep command:
azds prep --public
You must run the
prep command from the dev-spaces/samples/nodejs/getting-started/webfrontend directory to correctly generate the Docker and Helm chart assets.
Build and run code in Kubernetes
Build and run your code in AKS using the
azds up command:
$ azds up Using dev space 'default' with target 'MyAKS' Synchronizing files...2s Installing Helm chart...2s Waiting for container image build...2m 25s Building container image... Step 1/8 : FROM node Step 2/8 : ENV PORT 80 Step 3/8 : EXPOSE 80 Step 4/8 : WORKDIR /app Step 5/8 : COPY package.json . Step 6/8 : RUN npm install Step 7/8 : COPY . . Step 8/8 : CMD ["npm", "start"] Built container image in 6m 17s Waiting for container...13s Service 'webfrontend' port 'http' is available at http://webfrontend.1234567890abcdef1234.eus.azds.io/ Service 'webfrontend' port 80 (http) is available at http://localhost:54256 ...
You can see the service running by opening the public URL, which is displayed in the output from the
azds up command. In this example, the public URL is http://webfrontend.1234567890abcdef1234.eus.azds.io/.
When you navigate to your service while running
azds up, the HTTP request traces are also displayed in the output of the
azds up command. These traces can help you troubleshoot and debug your service. You can disable these traces using
--disable-http-traces when running
If you stop the
azds up command using Ctrl+c, the service will continue to run in AKS, and the public URL will remain available.
To deploy an updated version of your service, you can update any file in your project and rerun the
azds up command. For example:
azds upis still running, press Ctrl+c.
Update line 13 in
res.send('Hello from webfrontend in Azure');
Save your changes.
$ azds up Using dev space 'default' with target 'MyAKS' Synchronizing files...1s Installing Helm chart...3s Waiting for container image build... ...
Navigate to your running service and observe your changes.
Press Ctrl+c to stop the
Clean up your Azure resources
az group delete --name MyResourceGroup --yes --no-wait
Learn how Azure Dev Spaces helps you develop more complex applications across multiple containers, and how you can simplify collaborative development by working with different versions or branches of your code in different spaces.