title
stringlengths
3
46
content
stringlengths
0
1.6k
21:2130
Now, click the Pipelines menu item to create a DevOps pipeline to build and test your project. In the window that appears, click the button to create a new pipeline:
21:2131
21:2132
21:2133
Figure 21.34: Pipeline page
21:2134
21:2135
You will be prompted to select where your repository is located:
21:2136
21:2137
21:2138
Figure 21.35: Repository selection
21:2139
21:2140
Select Azure Repos Git and then your repository. Then, you will be prompted about the nature of the project:
21:2141
21:2142
21:2143
Figure 21.36: Pipeline configuration
21:2144
21:2145
Select ASP.NET Core. A pipeline for building and testing your project will be automatically created for you. Save it by committing the newly created .yaml file to your repository:
21:2146
21:2147
21:2148
Figure 21.37: Pipeline properties
21:2149
21:2150
The pipeline can be run by selecting the Queue button, but since the standard pipeline scaffolded by DevOps has a trigger on the master branch of the repository, it is automatically launched each time changes to this branch are committed and each time the pipeline is modified. The pipeline can be modified by clicking the Edit button:
21:2151
21:2152
21:2153
Figure 21.38: Pipeline code
21:2154
21:2155
Once in edit mode, all pipeline steps can be edited by clicking the Settings link that appears above each of them. New pipeline steps can be added as follows:
21:2156
Write - task: where the new step must be added and then accept one of the suggestions that appear while you are typing the task name.
21:2157
Once you have written a valid task name, a Settings link appears above the new step. Click it.
21:2158
Insert the desired task parameters in the window that appears and then save.
21:2159
21:2160
21:2161
To have our test working, we need to specify the criteria to locate all assemblies that contain tests. In our case, since we have to execute just the tests contained in PackagesManagementTest.dll and not the ones contained in PackagesManagementFTest.dll, we must specify the exact .ddl name.
21:2162
Click the Settings link of the VSTest@2 test task and replace the content that is automatically suggested for the Test files field with the following:
21:2163
**PackagesManagementTest.dll
21:2164
!***TestAdapter.dll
21:2165
!**obj**
21:2166
21:2167
21:2168
21:2169
Then, click Add to modify the actual pipeline content. As soon as you confirm your changes in the Save and run dialog, the pipeline is launched and, if there are no errors, test results are computed. The results of tests launched during a specific build can be analyzed by selecting the specific build in the pipeline Runs tab and by clicking the Tests tab on the page that appears. In our case, we should see something like the following screenshot:
21:2170
21:2171
21:2172
Figure 21.39: Test results
21:2173
Summing up, we created a new Azure DevOps repository, published the solution to the new repository, and then created a build pipeline that executes our tests after each build. The build pipeline is executed as soon as we save it and will be executed each time someone commits to the master branch.
21:2174
Summary
21:2175
The main purpose of this chapter was to deliver pieces of implementations that can be useful to begin the challenge of delivering a software solution for an enterprise. Although we have not shown the complete implemention of the WWTravelClub application, we are confident that the microservices and code provided here can help you in your professional projects; this is in line with what we understand to be the main purpose of a software architect―to help the team in developing software that meets the users’ needs exactly as required.
21:2176
Leave a review!
21:2177
Enjoyed this book? Help readers like you by leaving an Amazon review. Scan the QR code below for a 20% discount code.
21:2178
21:2179
*Limited Offer
21:2180
21:2181
22:1
Case Study Extension: Developing .NET Microservices for Kubernetes
22:2
In this chapter, we bridge the insights from Chapter 21, Case Study, where we explored the practical implementation of .NET microservices, with the foundational knowledge of Kubernetes presented in Chapter 20, Kubernetes. Our focus here is on preparing .NET code for seamless integration with Kubernetes, encompassing the complete development cycle—from coding to debugging, and even troubleshooting post-deployment challenges.
22:3
We will guide you through the process of setting up a development workstation optimized for Kubernetes, learn the intricacies of packaging code with Docker, and understand how to organize your codebase for flawless execution across varied environments, such as Docker Desktop, local minikube installations, and production or staging Kubernetes clusters.
22:4
Also, this chapter delves into the nuances of remote debugging, providing you with the necessary skills to efficiently troubleshoot and debug your application. Here, you will learn how to prepare each developer workstation, how to package the code with Docker, and how to organize the code so that it can immediately run both on the developer Docker Desktop, on the developer’s local Minikube installation, and on the production/staging Kubernetes clusters, without modifications.
22:5
By the end of the chapter, you will have mastered remote debugging techniques for applications in production or staging environments, enabling swift issue resolution and system reliability.
22:6
More specifically, you will learn about the following topics:
22:7
22:8
The tools needed for .NET Kubernetes development
22:9
Organizing the development process
22:10
Running your application in Minikube
22:11
Remote debugging of a Kubernetes application
22:12
22:13
All concepts will be explained with the help of a previous example taken from Chapter 21, Case Study, which we will adapt for Kubernetes execution.
22:14
You’ll adapt the GrpcMicroService microservice from Chapter 21, Case Study, seeing firsthand how a real-world application transitions to Kubernetes.
22:15
To fully leverage this chapter, fortify your understanding of Docker and Kubernetes as laid out in Chapter 11, Applying a Microservice Architecture to Your Enterprise Application, and Chapter 20, Kubernetes, which form the foundation for the advanced practices discussed herein.
22:16
Technical requirements
22:17
This chapter requires Visual Studio 2022 free Community Edition or better, with all the database tools installed.
22:18
You will also need these:
22:19
22:20
WSL (Windows Subsystem for Linux) and Docker Desktop for Windows. Detailed instructions on how to install both of them are given in the Technical requirements section of Chapter 11, Applying a Microservice Architecture to Your Enterprise Application.
22:21
A Minikube installation that specifies Docker as a virtualization tool. Minikube installation is described in the Using Minikube section of Chapter 20, Kubernetes.
22:22
A SQL Server database that allows TCP/IP connections. You can’t use SQL Server Express LocalDB, which comes with Visual Studio installation, since it doesn’t allow TCP/IP connections. So you need either a full SQL Express installation or an Azure SQL Server database. More details on how to fulfill this requirement will be given in the Tools needed for .NET Kubernetes development section of this chapter.
22:23
22:24
All the code of this chapter can be found in the GitHub repository associated with this book: https://github.com/PacktPublishing/Software-Architecture-with-C-Sharp-12-and-.NET-8-4E.
22:25
The Tools needed for .NET Kubernetes development
22:26
Each single microservice can be unit-tested and debugged independently from the remainder of its application, with the technique you learned Chapter 9, Testing Your Enterprise Application. You don’t need to package it inside a Docker image to do this.
22:27
However, debugging and performing integration tests on the whole application or parts of it requires that all involved microservices interact and are packaged as in the final application.
22:28
You can use a staging environment to beta-test your application. Prior to staging deployment, ensure your application’s stability in the development environment to prevent time-consuming troubleshooting, because the staging environment doesn’t have all the facilities that are available in a development environment. Otherwise, troubleshooting all frequent bugs and crashes discovered in the staging environment might imply an unacceptable time cost.
22:29
Therefore, it is preferable to reach good application stability before deploying the application in a staging environment. Moreover, for easier and more efficient debug-fix cycles, it is desirable that all microservices run on each single developer machine. That’s why each developer workstation must be equipped with both Docker and Minikube.
22:30
Furthermore, the developer machine must be able to simulate all communications between microservices and between services and other storage media, like databases.
22:31
It is likely that, Minikube can run and simulate all communications that occur in an actual Kubernetes cluster, including when it runs on a single development machine.
22:32
We can also let all involved Docker images communicate among them before loading them on Minikube because Docker Desktop allows the creation of virtual networks that are accessible by the local Docker images.
22:33
Finally, both Docker and Minikube virtual networks automatically include the development machine that hosts them, so we can place storage services like disk volumes and databases on the development machine itself.
22:34
22:35
Figure 22.1: Minikube and Docker network structure
22:36
However, the sophisticated virtual network facilities of both Docker and Kubernetes are not enough to ensure an efficient development and debugging environment, and further tools are needed.
22:37
Below are all the issues we need to fix to configure an efficacious development-debugging environment and how to solve them:
22:38
22:39
As a default, Visual Studio installs SQL Server Express LocalDB instead of SQL Server Express, and SQL Server Express LocalDB is not able to communicate via actual or virtual networks. Therefore, we need either an SQL Server Express installation or an external database.
22:40
Since Kubernetes nodes have just virtual addresses that are handled by the Kubernetes engine itself, a Visual Studio debugger can be attached to a running microservice just through the REST API of the Kubernetes engine. At the time of writing, the best tool available for Visual Studio is Bridge to Kubernetes, which, in turn, uses kubectl to interact with the API of any Kubernetes cluster, Minikube included. Unluckily, we can’t use the Kubectl installation that runs on the virtual machine that hosts Minikube as we did in Chapter 20, Kubernetes, but we need an installation that runs directly in the development machine.
22:41
22:42
We describe how to install and configure all tools mentioned in the above points in two dedicated subsections.
22:43
Installing and configuring SQL Server Express
22:44
If you have access to an SQL Server instance running in your development machine, you can use that one. Otherwise, you can choose between creating an SQL Server database in Azure following the instructions contained in Chapter 12, Choosing Your Data Storage in the Cloud, or installing a local instance of SQL Server Express:
22:45
22:46
Begin by downloading the SQL Server installer from https://www.microsoft.com/en-US/download/details.aspx?id=104781.
22:47
You can freely choose between SQL Server Express and SQL Server Express Advanced, but please select a complete installation that includes both SQL Server Management Studio and the SQL Server Management console.
22:48
Select to install SQL Server as the default instance on your machine (the default in the installation procedure).