title
stringlengths
3
46
content
stringlengths
0
1.6k
22:49
Immediately after the installation, you must run SQL Server Management Console (just write this name in the Windows search box) to enable TCP/IP-based connections. In order to configure SQL Server properly, follow all the steps below.
22:50
22:51
22:52
Once in the SQL Server Management Console, expand the SQL Server Network Configuration node.
22:53
Select Protocols for <your instance name>.
22:54
On the right detail pane, you should see all the available communication protocols.
22:55
Right-click on TCP/IP and select Enable.
22:56
Now, TCP/IP is enabled but on a dynamic port. In order to impose a fixed port, right-click on the same TCP/IP node and select Properties.
22:57
22:58
22:59
Figure 22.2: Forcing a static IP address
22:60
22:61
Select the IP Addresses tab.
22:62
You should see several IP addresses. These are all IP addresses that are associated with your computer, and each of them executes the next step.
22:63
Remove the 0 that is in TCP Dynamic Port and keep this field empty, and then write 1433 in the TCP Port field.
22:64
Once finished, click on the OK button.
22:65
Now, you need to restart the SQL Server service. Select SQL Server Services in the left pane.
22:66
Finally, in the right detail pane, right-click on SQL Server <your instance name> and select Restart.
22:67
Once installed, the SQL Server only has Windows authentication enabled. In order to use the instance on a non-Windows network, you must enable username-based authentication and define at least one administrative user. This is a necessary step because Windows authentication will not work on Docker networks and Kubernetes.
22:68
You can do this in SQL Server Management Studio. Once SQL Server Management Studio opens, it prompts you for an instance to connect with and for authentication information. The instance name of the database you just installed should be something like <computer name>SQLEXPRESS; select it and also select Windows Authentication, as shown below:
22:69
22:70
22:71
Figure 22.3: Connecting with SQL Server Management Studio
22:72
Once connected with the database, you can enable username-based authentication as follows:
22:73
22:74
Right-click on your server icon in Object Explorer and choose Properties.
22:75
In the window that opens, select Security in the left pane.
22:76
Select SQL Server and Windows Authentication mode, as shown in the screenshot below:
22:77
22:78
22:79
Figure 22.4: Enabling SQL Server authentication
22:80
In order to make your changes effective, you must restart SQL Server. You can do it by right-clicking on your server icon in Object Explorer and by selecting Restart.
22:81
Now, you need to define at least one user by following the steps below:
22:82
22:83
Expand the Security folder under your server icon in Object Explorer.
22:84
Right-click on the Logins folder and select New Login.
22:85
In the window that opens, insert a username.
22:86
Select SQL Server authentication, insert a password, and confirm it by retyping the same password in the Confirm password field, as shown in the screenshot below:
22:87
22:88
22:89
Figure 22.5: Defining user name and password
22:90
22:91
Finally, right-click on Server Roles and enable the sysadmin role to give all rights to the new user.
22:92
22:93
And there you have it! Now, your SQL Server instance can be used by both Docker and Minikube.
22:94
The next subsection explains how to configure Visual Studio for debugging applications running on Minikube or any other Kubernetes cluster.
22:95
Enabling Kubernetes application debugging with Bridge to Kubernetes
22:96
Since microservices running on Kubernetes have no fixed IP address and ports attached to them, only virtual addresses that are solved at runtime by Kubernetes, we can’t attach the Visual Studio debugger directly to any running microservice. That’s why we need software like Bridge to Kubernetes, which interacts with the Kubernetes API to enable debugging.
22:97
Bridge to Kubernetes is a Visual Studio extension that’s easy to install, but it requires Kubectl to be installed on your development machine, which presents a challenge, as there is no direct Windows installer for Kubectl. In this subsection, we’ll guide you through the process of installing both Bridge to Kubernetes and Kubectl, overcoming the lack of a direct Windows installer for the latter.
22:98
Bridge to Kubernetes enables Kubernetes application debugging by interacting with the Kubernetes API via Kubectl. However, it is not a debugger driver or a debugger extension. It does a completely different job; it asks you to select a service running in a Kubernetes cluster and reroute all communication with this service to a locally running Visual Studio POD replica instead of the actual cluster POD.
22:99
22:100
Figure 22.6: How Bridge to Kubernetes works
22:101
Therefore, the developer debugs a local copy of the POD code but in exactly the same dynamic Kubernetes environment as the original POD. This way, you have all the facilities offered by a usual local debugging session, but while you are debugging it, your code interacts with the actual Kubernetes cluster you need to fix.
22:102
Bridge to Kubernetes doesn’t work just with Minikube; it works with any Kubernetes cluster. Thus, you can use it for debugging the whole application on your development machine, and also for debugging the staging application or the production application.
22:103
Since you debug just the local code and not the deployed code, you are not forced to compile an application in debug mode in order to debug it. You can deploy the application with all compilation optimizations you want without caring about possible debugging needs; it is enough to have local copies of the PODs you would like to debug compiled in debug mode.
22:104
You will learn how to use Bridge to Kubernetes in practice in the Remote debugging of a Kubernetes application section. The remainder of this section will explain all the steps needed to install Bridge to Kubernetes on a development machine.
22:105
First of all, you need to install Kubectl. The simplest way to do it is by using the Chocolatey package manager.
22:106
22:107
Chocolatey is a package manager like NuGet. Similarly, it consists of a public repository containing all packages and a client you must install on your machine, in order to interact with the public repository.
22:108
22:109
If you don’t have Chocolatey already installed, you can install it from a PowerShell prompt, as follows:
22:110
22:111
Search PowerShell in the Windows search box.
22:112
Right-click on the PowerShell link and select to execute it as an administrator.
22:113
Finally, execute the PowerShell command suggested on the official Chocolatey page: https://chocolatey.org/install#individual.
22:114
22:115
The PowerShell command to execute is repeated below for your convenience:
22:116
Set-ExecutionPolicy Bypass -Scope Process -Force; [System.Net.ServicePointManager]::SecurityProtocol = [System.Net.ServicePointManager]::SecurityProtocol -bor 3072; iex ((New-Object System.Net.WebClient).DownloadString('https://community.chocolatey.org/install.ps1'))
22:117
22:118
Once installation is complete, run choco -? to verify that the installation was successful and that the Chocolatey user interface works properly.
22:119
With Chocolatey installed, installing Kubectl is super easy; just open a Windows Command Prompt as an administrator and type this:
22:120
choco install kubernetes-cli
22:121
22:122
You can check whether everything works properly by typing kubectl version –client.
22:123
Kubectl should be configured to access a specific cluster, but when you start Minikube with minikube start, Minikube automatically configures it to access the local Minikube cluster, so you don’t need to worry about Kubectl configuration.
22:124
Now, you are ready to install Bridge to Kubernetes, as follows:
22:125
22:126
Open Visual Studio and select Extensions -> Manage Extensions.
22:127
Search Bridge to Kubernetes.
22:128
Select it and install it.
22:129
22:130
And there you have it! Now, your development machine is ready for .NET Kubernetes development. The next section details the development process and explains how to modify an existing project to run with both the local Docker installation and any Kubernetes cluster.
22:131
Organizing the development process
22:132
Since Visual Studio and other IDEs offer good support for Docker and a good integration with Docker Desktop, the best option for most of the development time is working with just Dockerized images without running them inside of Minicube.
22:133
In fact, as we will see shortly, once we have added Docker support to our projects, it is enough to click the Run Visual Studio button to start all our Dockerized microservices and to enable them to communicate through a Docker network. Conversely, running our application in Minikube requires several manual steps, and it takes some time to load the Docker images on Minikube and to create all the necessary Kubernetes objects.
22:134
Doing this in Visual Studio is super easy. It is enough to add Docker support for all microservice projects in your solution and to select the option of launching several projects simultaneously when the solution is run. Then, Visual Studio will automatically perform all the necessary tasks when your solution is run, namely:
22:135
22:136
Compile and link all code.
22:137
Build all microservice Docker images.
22:138
Insert the Docker images into the Docker Desktop local repository.
22:139
Launch all Docker images simultaneously.
22:140
Attach the debugger to all launched Docker images.
22:141
22:142
You just need to take care of microservice communication by defining a virtual network with Docker Desktop.
22:143
We will explain all the details of the development process with a simple example in the next subsection.
22:144
gRPC worker microservices revisited
22:145
In the code associated with Chapter 14, Implementing Microservices with .NET, and described in Chapter 21, Case study, there is a solution called GrpcMicroService. The solution is composed of two microservices. The first microservice simulates purchases by generating random data, while the second one uses this data to compute statistics that it stores in a database. The whole code is available in the ch15->GrpcMicroService folder of the GitHub repository associated with the book.
22:146
Let’s make a copy of the whole GrpcMicroService folder and call it GrpcMicroServiceDocker.
22:147
The steps below describe all the modifications that need to be made to Docker to enable all microservices.
22:148
Adding Docker support to GrpcMicroServiceDocker