title | titleSuffix | author | services | ms.service | ms.component | ms.author | ms.date | ms.topic | description | keywords | manager |
---|---|---|---|---|---|---|---|---|---|---|---|
Create a Kubernetes dev space in the cloud | Microsoft Docs |
Azure Dev Spaces |
ghogen |
azure-dev-spaces |
azure-dev-spaces |
azds-kubernetes |
ghogen |
07/09/2018 |
quickstart |
Rapid Kubernetes development with containers and microservices on Azure |
Docker, Kubernetes, Azure, AKS, Azure Kubernetes Service, containers |
douge |
In this guide, you will learn how to:
- Set up Azure Dev Spaces with a managed Kubernetes cluster in Azure.
- Iteratively develop code in containers using Visual Studio.
- Debug code running in your cluster.
Note
If you get stuck at any time, see the Troubleshooting section, or post a comment on this page. You can also try the more detailed tutorial.
-
A Kubernetes cluster running Kubernetes 1.9.6 or later, in the EastUS, CentralUS, WestUS2, WestEurope, CanadaCentral, or CanadaEast region, with Http Application Routing enabled.
-
Visual Studio 2017 with the Web Development workload installed. If you don't have it installed, download it here.
Install Visual Studio Tools for Kubernetes.
Next, you'll create and configure a project for Azure Dev Spaces.
From within Visual Studio 2017, create a new project. Currently, the project must be an ASP.NET Core Web Application. Name the project webfrontend.
Select the Web Application (Model-View-Controller) template and be sure you're targeting .NET Core and ASP.NET Core 2.0.
With the project you just created, select Azure Dev Spaces from the launch settings dropdown, as shown below.
In the dialog that is displayed next, make sure you are signed in with the appropriate account, and then select an existing cluster.
Leave the Space dropdown set to default
for now. Check the Publicly Accessible checkbox so the web app will be accessible via a public endpoint.
Click OK to select or create the cluster.
If you choose a cluster that hasn't been configured to work with Azure Dev Spaces, you'll see a message asking if you want to configure it.
Choose OK.
While you wait for the dev space to be created, look at the files that have been added to your project when you chose to use Azure Dev Spaces.
- A folder named
charts
has been added and within this folder a Helm chart for your application has been scaffolded. These files are used to deploy your application into the dev space. Dockerfile
has information needed to package your application in the standard Docker format.azds.yaml
contains development-time configuration that is needed by the dev space.
Once the dev space is successfully created, you can debug the application. Set a breakpoint in the code, for example on line 20 in the file HomeController.cs
where the Message
variable is set. Click F5 to start debugging.
Visual Studio will communicate with the dev space to build and deploy the application and then open a browser with the web app running. It might seem like the container is running locally, but actually it's running in the dev space in Azure. The reason for the localhost address is because Azure Dev Spaces creates a temporary SSH tunnel to the container running in AKS.
Click on the About link at the top of the page to trigger the breakpoint. You have full access to debug information just like you would if the code was executing locally, such as the call stack, local variables, exception information, and so on.
Azure Dev Spaces isn't just about getting code running in Kubernetes - it's about enabling you to quickly and iteratively see your code changes take effect in a Kubernetes environment in the cloud.
- Locate the file
./Views/Home/Index.cshtml
and make an edit to the HTML. For example, change line 70 that reads<h2>Application uses</h2>
to something like:<h2>Hello k8s in Azure!</h2>
- Save the file.
- Go to your browser and refresh the page. You should see the web page display the updated HTML.
What happened? Edits to content files, like HTML and CSS, don't require recompilation in a .NET Core web app, so an active F5 session automatically syncs any modified content files into the running container in AKS, so you can see your content edits right away.
Updating code files requires a little more work, because a .NET Core app needs to rebuild and produce updated application binaries.
- Stop the debugger in Visual Studio.
- Open the code file named
Controllers/HomeController.cs
, and edit the message that the About page will display:ViewData["Message"] = "Your application description page.";
- Save the file.
- Press F5 to start debugging again.
Instead of rebuilding and redeploying a new container image each time code edits are made, which will often take considerable time, Azure Dev Spaces will incrementally recompile code within the existing container to provide a faster edit/debug loop.
Refresh the web app in the browser, and go to the About page. You should see your custom message appear in the UI.
[!div class="nextstepaction"] Working with multiple containers and team development