Skip to content
Permalink
Browse files

deploy

  • Loading branch information...
mbcrump committed Oct 6, 2019
1 parent 12776be commit 95dda1d006bff34af459fcd2928a555781e2a901
BIN +0 Bytes (100%) .DS_Store
Binary file not shown.
@@ -32,7 +32,7 @@ module.exports = {
{
title: 'Recently Added',
collapsable: false,
children: ['/blog/tip227','/blog/tip226','/blog/tip225','/blog/tip224','/blog/tip223','/blog/tip222','/blog/tip221','/blog/tip220','/blog/tip219','/blog/tip218','/blog/tip217','/blog/tip216','/blog/tip215','/blog/tip214','/blog/tip213','/blog/tip212','/blog/tip211','/blog/tip210']
children: ['/blog/tip228','/blog/tip227','/blog/tip226','/blog/tip225','/blog/tip224','/blog/tip223','/blog/tip222','/blog/tip221','/blog/tip220','/blog/tip219','/blog/tip218','/blog/tip217','/blog/tip216','/blog/tip215','/blog/tip214','/blog/tip213','/blog/tip212','/blog/tip211','/blog/tip210']
},
{
title: 'App Service',
@@ -128,6 +128,11 @@ module.exports = {
collapsable: true,
children: ['/blog/tip180', '/blog/tip181']
},
{
title: 'Kubernetes',
collapsable: true,
children: ['/blog/tip228']
},
{
title: 'Logic Apps',
collapsable: true,
BIN +0 Bytes (100%) .vuepress/public/.DS_Store
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -0,0 +1,150 @@
---
type: post
title: "Tip 228 - Part 1 - Get started with .NET Core on Kubernetes with Azure Dev Spaces"
excerpt: "Learn how to get started with .NET Core on Kubernetes with Azure Dev Spaces"
tags: [azure, .netcore, kubernetes, azuredevspaces]
share: true
date: 2019-10-06 02:00:00
---

::: tip

:fire: Checkout our new Azure Developer page at [azure.com/developer](https://azure.com/developer?WT.mc_id=azure-azuredevtips-micrum).

:bulb: Learn more : [Azure Dev Spaces](https://docs.microsoft.com/azure/dev-spaces/about?WT.mc_id=docs-azuredevtips-micrum).

:::

#### Using Azure Dev Spaces to develop for Azure Kubernetes Service
This is part 1 of a 3-part series about [Azure Dev Spaces](https://docs.microsoft.com/azure/dev-spaces/about?WT.mc_id=docs-azuredevtips-micrum):

* (This post) Azure Tips and Tricks 228 - Part 1 Get started with .NET Core on Kubernetes with Azure Dev Spaces
* (Upcoming) Azure Tips and Tricks xxx - Part 2 Develop multi-service applications on Kubernetes with Azure Dev Spaces
* (Upcoming) Azure Tips and Tricks xxx - Part 3 Use Azure Dev Spaces to collaborate with a team on Kubernetes

Developing container-based solutions used to be challenging. You needed to create and run the complete solution locally, with all the containers that run all the services you need. This takes a lot of compute resources and makes it difficult to easily update components and debug them.

[Azure Dev Spaces](https://docs.microsoft.com/azure/dev-spaces/about?WT.mc_id=docs-azuredevtips-micrum) makes developing container-based solutions for [Kubernetes](https://azure.microsoft.com/services/kubernetes-service/?WT.mc_id=azure-azuredevtips-micrum) a lot easier. It provides a way to run your solution in the cloud and update it easily and quickly to create a great developer experience.

In this article, we'll take a look at how you can use Azure Dev Spaces to create and run an ASP.NET Core application.

#### Prerequisites
If you want to follow along, you'll need the following:
* An Azure subscription (If you don't have an Azure subscription, create a [free account](https://azure.microsoft.com/free/?WT.mc_id=azure-azuredevtips-micrum) before you begin)
* The latest version of the [Azure CLI](https://docs.microsoft.com/cli/azure/install-azure-cli?view=azure-cli-latest&WT.mc_id=docs-azuredevtips-micrum) on your local machine
* The [.NET Core SDK](https://dotnet.microsoft.com/download?WT.mc_id=microsoft-azuredevtips-micrum)
* The latest version of [Visual Studio Code](https://code.visualstudio.com/)

We are going to use the Azure CLI to perform most of our actions. You can also do all of this through the Azure portal.
Open a command prompt with the Azure CLI Tools installed and log into your Azure account to get started:

#### Create a Kubernetes cluster enabled for Azure Dev Spaces
Let's create a Kubernetes cluster in Azure and enable Azure Dev Spaces in it.

Open a command prompt and log into your Azure account to get started:
```
az login
```

If you have multiple Azure subscriptions, you can select one by first finding the ID of the subscription that you want with this command:
```
az account list
```
And if the subscription which has the **isDefault:true** is not the one you want to use, set the subscription using this command:
```
az account set --subscription <subscription ID>
```

Now that we are logged in, we'll create a new resource group that will contain the Kubernetes cluster.
In the **\<region\>** placeholder, fill in a [region that supports Azure Dev Spaces](https://docs.microsoft.com/azure/dev-spaces/about#supported-regions-and-configurations?WT.mc_id=docs-azuredevtips-micrum), like **westeurope**.
```
az group create --name TipsAndTricksAKS --location <region>
```

Next, create the Kubernetes cluster in Azure by running this command:
```
az aks create -g TipsAndTricksAKS -n MyAKS --location <region> --disable-rbac --generate-ssh-keys
```

And finally, enable the Kubernetes cluster for Azure Dev Spaces with this command:
```
az aks use-dev-spaces -g TipsAndTricksAKS -n MyAKS
```
This will also prompt you to install the Azure Dev Spaces CLI on your local machine, like in the image below:

<img :src="$withBase('/files/29azuredevspacescli.png')">

(Install the Azure Dev Spaces CLI)



#### Run and debug an application on Kubernetes using Azure Dev Spaces
Now that we have a Kubernetes cluster with Azure Dev Spaces, we can deploy and run an application in it.

To make it easy on ourselves, we will use an already existing application:
1. Go to the [Azure Dev Spaces sample application](https://github.com/Azure/dev-spaces) and **clone or download** it to your local machine
2. On your local machine, navigate to the **samples/dotnetcore/getting-started/webfrontend** directory
3. Open the **webfrontend** folder with **VS Code**. This will open a standard ASP.NET Core web application
4. In VS Code, open the **terminal** by clicking on the **View > Terminal** menu-item
5. In the terminal, make sure that the prompt is in the **webfrontend directory**. If it isn't, navigate to the webfrontend directory by typing
```
cd [location of the code on your computer]samples/dotnetcore/getting-started/webfrontend
```
6. Now run the following command to prepare the application to run in a container on Kubernetes:
```
azds prep --public
```
This adds a **Docker file** to the application, that enables it to run in a container. And a **[Helm chart](https://docs.helm.sh/)** that it can use to run in Kubernetes. And also an **azds.yaml** file, which configures the application to work with Azure Dev Spaces:

<img :src="$withBase('/files/29azdsprep.png')">

(Docker, Kubernetes and Azure Dev Spaces files in the project)

**Run and update the application**

Now for some container magic! Let's run the application and see how it works with Azure Dev Spaces.
1. In VS Code, in the **terminal**, make sure that you are still in the **webfrontend** directory
2. Run the following command to run the code:
```
azds up
```
The first time that you run this command, it will take several minutes, as it is creating and uploading a container to Azure.
3. When the application is running, you will see the URL to the application in the output of the **terminal**, like in the image below:

<img :src="$withBase('/files/29runningtheapp.png')">

(Running the app produces output in the VS Code terminal)

Notice that there are **two URLs** to the application. One that runs in Azure and one on **localhost**. Azure Dev Spaces routes the application to localhost with the Kubernetes port-forward functionality (so it is still running in Azure), so that you can interact with the application from your local machine. The terminal also shows the logs of any interaction with the application. When you use the application, you'll see the requests to the app show up
4. Use one of the **application URLs** to open the application in a browser
5. Now go to VS Code and **change some HTML** in one of the views of the application. When you save the changes, Azure Dev Spaces instantly sends the changes to Kubernetes and the application is updated. This work really fast and facilitates a **very fast developer experience**. This work so fast, because ASP.NET Core doesn't require a compilation for changed files. However, if you change some code, like code in a controller of the application, it is still fast. When you change code, you do need to run the **azds up** command again to recompile the application

<img :src="$withBase('/files/29appinbrowser.png')">

(The application in a browser, also reachable from localhost)

**Debug the application**
Using Azure Dev Spaces, we can also debug the application easily. To do that, the code in VS Code needs to communicate with the Azure Dev Space.
1. In VS Code, go to **View > Command Palette** and type **Azure Dev Spaces: Prepare configuration files for Azure Dev Spaces**. This adds debug configuration for Azure Dev Spaces to the project
2. Click on the **Debug icon** on the left sidebar of VS Code
3. Select **.NET Core Launch (AZDS)**, like in the image below:

<img :src="$withBase('/files/29debuggingaks.png')">

(The debug configuration in VS Code)

4. Hit **F5** to start debugging
5. You can now put breakpoints in your code and diagnose the application

The beauty of working with Azure Dev Spaces is that you can quickly make changes and continue working.
1. Make a change to code in the **HomeController.cs** file
2. Now restart the debugging process by clicking the **Restart button** in the **Debug actions pane**

<img :src="$withBase('/files/29debuggingaks2.png')">

(Restart debugging)

The change will be uploaded and you can continue to debug with the new code. This is very fast, because Azure Dev Spaces only incrementally recompiles code within the existing container to provide a faster edit/debug loop.

#### Conclusion
Running containers offers a lot of freedom but can also slow down your develop-deploy-debug cycle as you need to compile containers and deploy and run them everytime you change your code. [Azure Dev Spaces](https://docs.microsoft.com/azure/dev-spaces/about?WT.mc_id=docs-azuredevtips-micrum) helps with that. It works with [Kubernetes](https://azure.microsoft.com/services/kubernetes-service?WT.mc_id=azure-azuredevtips-micrum) to provide a fast and seamless developer experience. When you use Azure Dev Spaces, your container-based solution runs in the cloud, but you can easily develop your code locally and run and debug it, without running a local Docker engine. Go and check it out!

0 comments on commit 95dda1d

Please sign in to comment.
You can’t perform that action at this time.