title | services | ms.date | ms.topic | description | keywords | manager |
---|---|---|---|---|---|---|
Develop an application on Kubernetes |
azure-dev-spaces |
02/20/2020 |
quickstart |
This quickstart shows you how to use Azure Dev Spaces and the command line to develop an application on Azure Kubernetes Service |
Docker, Kubernetes, Azure, AKS, Azure Kubernetes Service, containers, Helm, service mesh, service mesh routing, kubectl, k8s |
gwallace |
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.
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 --generate-ssh-keys
Use the 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.
Note
The use-dev-spaces
command will also install the Azure Dev Spaces CLI if its not already installed. You cannot install the Azure Dev Spaces CLI in the Azure Cloud Shell.
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.
[1] 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.
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
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 --enable-ingress
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.
Tip
The prep
command attempts to generate a Dockerfile and Helm chart for your project. Azure Dev Spaces uses these files to build and run your code, but you can modify these files if you want to change how the project is built and ran.
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/
.
Note
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 azds up
.
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:
-
If
azds up
is still running, press Ctrl+c. -
Update line 13 in
server.js
to:res.send('Hello from webfrontend in Azure');
-
Save your changes.
-
Rerun the
azds up
command:$ 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
azds up
command.
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.
[!div class="nextstepaction"] Team development in Azure Dev Spaces