When working on projects in recent times, you typically needed to invest a lot of initial effort to set up an automated build and release process by configuring the CI/CD pipelines. Things can become a bit complicated or consume more effort and time when the deployment target is Kubernetes. Azure DevOps Starter is here for the rescue. It enables you to build automated CI/CD pipelines for your application at the drop of a hat. This article presents a discussion on containerization, Kubernetes components, and how you can work with Azure DevOps Starter to deploy an ASP.NET Core app to Azure Kubernetes Service.

Take advantage of Azure DevOps Starter to deploy an ASP.NET 5 application to Azure Kubernetes Service.

Prerequisites

You should have Visual Studio 2019 or a later version installed on your system. If you don't already have a copy downloaded and installed on your computer, you can download a copy of Visual Studio from here: https://visualstudio.microsoft.com/downloads/.

You should have an Azure account. If you don't have one, you can create it here: https://portal.azure.com/. You should also have an Azure DevOps Account, which you can create here: https://azure.microsoft.com/en-in/services/devops/.

Container Orchestration

Containers can be created on-demand to make them highly scalable. This is fine for a limited number of containers, but the complexity grows when you have to manage hundreds or thousands of containers. Managing lots of container lifecycles becomes a nightmare. This is precisely where container orchestration comes to the rescue.

Container orchestration is a technology that helps automate the administration, deployment, scaling, and networking of containers. Container orchestration might help you deploy the same application in several environments without rebuilding or redesigning it. DevOps teams can benefit from managing the lifecycle of containers with orchestration by integrating it into the continuous integration and continuous delivery workflows.

Container orchestration assists in automating container deployment to available systems depending on the resource requirements of each container. Container orchestration tackles this problem by automating the availability, deployment, scalability, scheduling, load balancing, and networking of containers.

Why You Need Container Orchestration

Container orchestration is a technology used to manage the life cycle of containers and schedule their deployment. When a container is deployed into a cluster, the container orchestration tool determines the most suitable host for the container based on available resources (CPU, RAM, etc.). You can use container orchestration tools in any environment that supports container execution. In addition to scheduling a new container deployment to a cluster, a container management tool also determines the appropriate host. After that, the orchestration tool maintains the container's lifetime according to the requirements specified in the compose file.

Container orchestration is used for managing tasks such as:

  • Provisioning
  • Deployment
  • Configuration
  • Scheduling
  • Improved security
  • Portability
  • Resilience
  • Scaling your applications and infrastructure easily
  • Optimal resource allocation
  • Monitoring container health
  • Improved governance

Intro to Kubernetes

Containers are an ideal solution for packaging and deploying your applications. However, it would be helpful to consistently manage the containers that run your applications to ensure that they operate without interruption. For example, let's say that you need to ensure that another container has to start automatically if one container goes down. How do you address this? Here's where Kubernetes steps in for the rescue.

Kubernetes, also known as K8s, is an open-source, popular container management (orchestration) tool for automating application deployment, scaling, and management. The orchestration capabilities of Kubernetes enable the creation of application services that can span several containers, the scheduling of containers throughout a cluster, the scaling of those containers, and the management of the health of the containers over time.

Kubernetes provides interfaces and reusable platform primitives to build and manage your applications with extreme flexibility, power, and dependability. When you use a container orchestration technology such as Kubernetes to define an application's configuration, you'll be using either a YAML or a JSON file. The configuration file is used to let the configuration management tool know how to locate container images, configure a network, and store logs.

Here are some of the reasons why you should use Kubernetes:

  • Open-source: Kubernetes is a community-driven project regulated by the CNCF and is entirely free and open source.
  • Portability and flexibility: Kubernetes is compatible with almost any container, runtime, and practically any underlying infrastructure (public cloud, private cloud, or on-premises server), provided that the host operating system is Linux or Windows (2016 or newer).
  • Multi-cloud capability: Kubernetes can host workloads that run on a single cloud and run across several clouds.
  • Load balancing: Kubernetes is capable of performing load balancing and network traffic distribution to ensure that the deployment is reliable.
  • Vendor- and cloud-agnostic: Kubernetes is vendor and cloud neutral, running in Microsoft Azure, Amazon Web Services (AWS), Google Cloud Platform (GCP), or even on-premises.

A Deep Dive into the Kubernetes Architecture

The basic foundation of Kubernetes architecture revolves around four distinct concepts: nodes, pods, deployments, and services. A good understanding of the components of Kubernetes architecture will help you understand how Kubernetes works. Figure 1 illustrates the components of Kubernetes architecture.

Figure 1: The Components of Kubernetes Architecture
Figure 1: The Components of Kubernetes Architecture

Let's now understand each of these components and their purpose.

Cluster

A typical deployment of Kubernetes is called a cluster. At a minimum, a Kubernetes cluster comprises a control plane and a collection of worker computers called nodes. Each of these nodes is capable of running containerized applications.

A Kubernetes cluster includes at least one cluster master and several nodes. The master node in a Kubernetes cluster runs the Kubernetes control plane.

Pods

In Kubernetes, pods are the smallest deployable units and are composed of one or more containers that share resources such as memory, lifecycle, and storage. In other words, it's a collection of containers that are all managed on the same computer, virtual machine, or node. A container is a lightweight, portable, and executable image that contains the application and its dependencies.

Each node is responsible for running pods, each of which contains one or more containers.

Control Plane and its Components

The Kubernetes control plane serves as the primary entry point for administrators and users to manage the different nodes in the cluster. The control plane components include the kube scheduler, kube-api server, cloud-controller-manager, and kube-controller-manager.

Here are the purposes of each of these components of the Control Plane:

  • cloud-controller-manager: The cloud-controller-manager is responsible for connecting your clusters to the cloud provider's API and running controllers unique to the cloud provider you are using currently.
  • kube-controller-manager: This is a control plane component that keeps track of the state of a cluster and runs a collection of controllers.
  • kube scheduler: The scheduler runs whenever there's a need to schedule pods and considers the resource requirements of a pod that include CPU or memory. Then it assigns the pod to a compute node that is suitable for it.
  • etcd: This is a consistent, distributed, and a highly available key store to store configuration data and make it available to all nodes in the cluster.

Node and Its Components

A node can either be a physical or a virtual machine. It runs and manages pods and is of two types: Worker Nodes and Master Nodes. Although the former can run user-defined containers, the latter controls one or more worker nodes and manages a Kubernetes cluster.

The Kubernetes nodes contain the kubelet service, the container runtime engine or docker, and the Kubernetes proxy service.

  • kubelet: This service runs on each node in a cluster and manages only the containers that Kubernetes has created. It runs on each node in a cluster and is responsible for transmitting information to and from a control plane service. It also reports the health of the host it's on to the master.
  • Container runtime engine: A container runtime engine runs containers in an isolated operating environment. There are several container engines such as Docker, Azure Container Service, Google Container Engine, Amazon ECS, etc.
  • kube-proxy: This is a network proxy that runs on each node in a Kubernetes cluster and assists in making the services accessible to external hosts by allowing them to communicate with the cluster.

The sections that follow discuss how Azure DevOps Starter can be used to deploy an ASP.NET Core application to Azure Kubernetes Service.

Intro to Azure Kubernetes Service (AKS)

Azure Kubernetes Service (also known as AKS) is a managed container orchestration service built on top of the open-source Kubernetes framework. You can leverage AKS to manage your hosted Kubernetes environment and quickly deploy, scale, and manage containerized applications seamlessly. AKS streamlines Kubernetes deployment and operation by provisioning, updating, and scaling resources on demand. It eliminates the complexity and operational overhead associated with Kubernetes management while allowing you to run your apps on the cloud. You can leverage AKS to bring your development and operations teams together on a single platform to build and deploy quickly and efficiently.

Intro to DevOps Starter

Azure DevOps Starter automates the tasks needed to get a CI/CD pipeline up and running in the Azure environment. Azure DevOps Starter makes it easy and seamless to set up code repo, build, and deployment, and it now supports workflow development for GitHub actions.

Azure DevOps Starter can do the following for you:

  • Create Azure resources, such as Azure Kubernetes Service, automatically.
  • Create, as well as configure, a release pipeline in Azure DevOps.
  • Create an Azure Application Insights resource to monitor applications.
  • Leverage Azure Monitor to keep track of the performance of container workloads that are deployed and running on your AKS cluster.

Azure DevOps Starter provides support for these two CI/CD providers:

  • Azure DevOps
  • GitHub Actions

Azure DevOps Starter enables you to select your CI/CD provider, Azure Service, as the deployment target, plus the pricing tier, Azure DevOps or GitHub organization, app framework, app language, Azure subscription, etc. Once you've created your Azure DevOps Starter project, you can customize the GitHub workflow or the Azure DevOps pipeline.

Azure DevOps Starter and GitHub Integration

DevOps Starter integrates with GitHub's actions and automates the steps necessary to build up a continuous integration and continuous delivery (CI/CD) workflow in GitHub. It builds a new Git repository in an existing or new Azure DevOps organization. Next, it commits a sample application or the existing source code to the repository that has just been created. Most importantly, every new code commit triggers an automated build and release process. You can also customize the GitHub workflow as needed.

You'll take advantage of Azure DevOps Starter and GitHub integration in this article.

Azure DevOps Starter and Azure DevOps Integration

Azure DevOps Starter automates the process required in Azure pipelines for setting up a continuous integration/continuous delivery (also known as CI/CD) pipeline. CI triggers for the build are also set up by the automation so that every new code commit can result in the initiation of a new build. Automation allows for the creation of a CD trigger for the build, which is triggered with each new successful build. Azure DevOps Starter also makes a CD trigger and deploys the successful build to the Azure service you've selected. You can copy the build and release pipelines and reuse them in other projects, if desired.

Create a New Azure DevOps Starter Project

You can create your Azure DevOps Starter resource much the same way you create any other resource. To create a new DevOps Starter project in the Azure portal, follow these steps:

  1. Log in to your Azure account. Select + Create a Resource from the Home screen.
  2. In the Create a Resource screen, search for DevOps Starter and select it after it shows up
  3. Click Create.
  4. In the next screen, you can select the technology you'd like to use and additionally, you can select the CI/CD provider from two choices: Azure DevOps and GitHub. Ensure that the CI/CD provider selected here is GitHub.
  5. Select .NET and click on the Next: Framework > button to proceed.
  6. Select ASP.NET Core as the application framework.
  7. Select Kubernetes Service in the next screen.
  8. Click the Next: Create > button to proceed.
  9. Now, click Authorize to provide the necessary permission to access your GitHub account to create the workflow. Once you've authorized Azure to access your GitHub account, you're ready to deploy your ASP.NET Core app to Azure Kubernetes Service.

Configure Azure DevOps: Specify Azure Subscription

Now you need to specify the subscription details to proceed. You can use an existing subscription if it's available or create a new Azure DevOps organization.

Assuming that you already have a subscription, specify the repository and subscription details and click the Review + Create button, as shown in Figure 2.

Figure 2: Specify the subscription parameters.
Figure 2: Specify the subscription parameters.

A GitHub repository in the name aks-azuredevops-starter will be created containing a sample ASP.NET Core application, which will be deployed to AKS after a series of build and release steps.

Examine the AKS Cluster

DevOps Starter creates and configures an AKS Cluster automatically for you. You can explore this AKS cluster by following these steps:

  1. Switch to the DevOps Starter Dashboard.
  2. Select the AKS service from the right pane.

In the Kubernetes service Dashboard that's shown next, you can monitor container health, search logs, etc.

Examine the CI/CD Process

Azure DevOps configures the CI/CD pipeline automatically for you. You can explore the pipeline and even customize it, if needed. Click on the Go to resource button. You'll observe that Azure Kubernetes Service is being created.

Once the Azure Kubernetes Service instance has been created successfully, you will be presented with the screen shown in Figure 3.

Figure 3: An Azure Kubernetes Service instance has been successfully created.
Figure 3: An Azure Kubernetes Service instance has been successfully created.

You can select Azure DevOps as your CI/CD provider, as discussed earlier in this article. If you've chosen Azure DevOps as your CI/CD provider, Figure 4 shows what it will look like when the build and release pipelines have executed successfully:

Figure 4: The CI/CD pipeline as viewed in Azure DevOps
Figure 4: The CI/CD pipeline as viewed in Azure DevOps

Examine the CI Pipeline

To explore the CI pipeline once the build process is complete, follow these steps:

  1. Switch to the DevOps Starter Dashboard.
  2. If you've used Azure DevOps as your CI/CD provider, click on the Build hyperlink, as shown in Figure 4.
  3. A new browser tab will open and display the build pipeline.
  4. You can make changes to your build pipeline now.
  5. Once you're done with the changes, select Save.

If you've used GitHub as the CI/CD provider, click on the “Build and push image to container” job in the DevOps Starter dashboard. You can now see the sequence of the events that has been executed in the build process.

Examine the CD Pipeline

To explore the CD release pipeline after the release process is complete, follow these steps:

  1. Switch to the DevOps Starter Dashboard.
  2. If you've used Azure DevOps as your CI/CD provider, click on aks-azure-devops-starter-azure � CD, as shown in Figure 4.
  3. A new browser tab will open and display the release pipeline.
  4. You can make changes to your release pipeline now.
  5. Once you're done with the changes, select Save.

If you've used GitHub as the CI/CD provider, click on the “Deploy application to AKS” job in the DevOps Starter dashboard. You can now see the sequence of the events that have been executed in the release process.

Trigger the Build and Release Pipelines Automatically

In this section, I'll examine how you can update the source code of the Web application and commit the code changes to the GitHub repository so that the pipelines get triggered automatically.

  1. Clone the repository in your computer inside a folder of your choice.
  2. Once the source code has been downloaded, open the solution file in Visual Studio 2019.
  3. Open the Index.cshtml file and change the title of the page as shown here:
@{
    ViewData["Title"] = "Welcome to Azure DevOps Starter";
}
  1. Build and commit the changes to the GitHub repository that your application is connected to.

The moment you commit the changes, the build pipeline is triggered, as shown in Figure 5.

Figure 5: Build and deploy to AKS.
Figure 5: Build and deploy to AKS.

Once the build process has completed its execution, the release pipeline starts execution and deploys the application to Azure Kubernetes Service.

Once these pipelines have completed their execution, Figure 6 is what you'll see in the Actions tab of your project in GitHub.

Figure 6: The build and release pipelines have been executed successfully.
Figure 6: The build and release pipelines have been executed successfully.

Once both the build and release pipelines have completed their execution, the Azure DevOps Starter page will look like Figure 7. Note the details of the last commit you made.

Figure 7: Changes in the Index.cshtml file have been pushed to the repository.
Figure 7: Changes in the Index.cshtml file have been pushed to the repository.

Summary

I started this journey with an introduction of containerization and a discussion on Kubernetes and its architectural components. Then I examined Azure DevOps Starter, its features and how it can be used to deploy an ASP.NET Core application to AKS.

You might want to modify the build and release pipelines to suit your project's requirements or the needs of your team. You might also want to use the CI/CD pattern as a template for other pipelines. If you'd like to know more about AKS and its capabilities, here's a great read: https://docs.microsoft.com/en-us/azure/aks/.