Get started with Visual Studio Kubernetes Tools
The Visual Studio Kubernetes Tools help streamline the development of containerized applications targeting Kubernetes. Visual Studio can automatically create the configuration-as-code files needed to support Kubernetes deployment, such as Dockerfiles and Helm charts. You can debug your code in a live Azure Kubernetes Service (AKS) cluster using Azure Dev Spaces, or publish directly to an AKS cluster from inside Visual Studio.
This tutorial covers using Visual Studio to add Kubernetes support to an project and publish to AKS. If you are primarily interested in using Azure Dev Spaces to debug and test your project running in AKS, you can jump to the Azure Dev Spaces tutorial instead.
To leverage this new functionality, you'll need:
- Visual Studio 2019 with the ASP.NET and web development workload.
- Docker Desktop installed on your development workstation (that is, where you run Visual Studio), if you wish to build Docker images, debug Docker containers running locally, or publish to AKS. (Docker is not required for building and debugging Docker containers in AKS using Azure Dev Spaces.)
If you wish to publish to AKS from Visual Studio (not required for debugging in AKS using Azure Dev Spaces):
The AKS publishing tools, available as a separate download.
Helm CLI installed on your development workstation. For more information see Installing Helm.
Helm configured against your AKS cluster by using the
helm initcommand. For more information on how to do this, see How to configure Helm.
Create a new Kubernetes project
Once you have the appropriate tools installed, launch Visual Studio and create a new project. Under Cloud, choose the Container Application for Kubernetes project type. Select this project type and choose OK.
In the Visual Studio start window, search for Kubernetes, and choose the Container Application for Kubernetes.
Provide the project name.
You can then choose which type of ASP.NET Core web application to create. Choose Web Application. The usual Enable Docker Support option does not appear on this dialog. Docker support is enabled by default for a container application for Kubernetes.
Add Kubernetes support to an existing project
Alternatively, you can add Kubernetes support to an existing ASP.NET Core web application project. To do this, right-click on the project, and choose Add > Container Orchestrator Support.
In the dialog box, select Kubernetes/Helm and choose OK.
What Visual Studio creates for you
After creating a new Container Application for Kubernetes project or adding Kubernetes container orchestrator support to an existing project, you see some additional files in your project that facilitate deploying to Kubernetes.
The added files are:
a Dockerfile, which allows you to generate a Docker container image hosting this web application. As you'll see, the Visual Studio tooling leverages this Dockerfile when debugging and deploying to Kubernetes. If you prefer to work directly with the Docker image, you can right-click on the Dockerfile and choose Build Docker Image.
a Helm chart, and a charts folder. These yaml files make up the Helm chart for the application, which you can use to deploy it to Kubernetes. For more information on Helm, see https://www.helm.sh.
azds.yaml. This contains settings for Azure Dev Spaces, which provides a rapid, iterative debugging experience in Azure Kubernetes Service. For more information, see the Azure Dev Spaces documentation.
Publish to Azure Kubernetes Service (AKS)
With all these files in place, you can use the Visual Studio IDE to write and debug your application code, just as you always have. You can also use Azure Dev Spaces to quickly run and debug your code running live in an AKS cluster. For more information, please reference the Azure Dev Spaces tutorial
Once you have your code running the way you want, you can publish directly from Visual Studio to an AKS cluster.
To do this, you first need to double-check that you've installed everything as described in the Prerequisites section under the item for publishing to AKS, and run through all the command line steps given in the links. Then, set up a publish profile that publishes your container image to Azure Container Registry (ACR). Then AKS can pull your container image from ACR and deploy it into the cluster.
In Solution Explorer, right-click on your project and choose Publish.
In the Publish screen, choose Container Registry as the publish target, and follow the prompts to select your container registry. If you don't already have a container registry, choose Create New Azure Container Registry to create one from Visual Studio. For more information, see Publish your container to Azure Container Registry.
Back in Solution Explorer, right click on your solution and click Publish to Azure AKS.
Choose your subscription and your AKS cluster, along with the ACR publish profile that you just created. Then click OK.
This takes you to the Publish to Azure AKS screen.
Choose the Configure Helm link to update the command line used to install the Helm charts on the server.
Updating the command line is useful if there are custom command line arguments that you wish to specify, such as a different Kubernetes context or chart name.
When you are ready to deploy, click the Publish button to publish your application to AKS.
Congratulations! You can now use the full power of Visual Studio for all your Kubernetes app development.
Learn more about Kubernetes development on Azure by reading the AKS documentation.
Learn more about Azure Dev Spaces by reading the Azure Dev Spaces documentation
Send feedback about: