Saturday 17 December 2022

Resolve "encountered an error during hcsshim::System::CreateProcess: failure in a Windows system call: The system cannot find the file specified. (0x2)"

 As discussed in the post "Run .NET Core 3.1 Application with Windows Server Core 2019 Docker Image" there could be situations you need to setup .NET Core 3.1 on Windows servercore docker image. However, you might have experienced below error running Windows container, when you setup tools such as .NET runtime by yourself using dockerfile. 


Let's see one such example case and how it can be fixed with .NET Core runtime 3.1 installed on Windows servercore docker image.

Sunday 4 December 2022

Run .NET Core 3.1 Application with Windows Server Core 2019 Docker Image

 You would love to run your .NET applications as Linux containers instead of using Windows containers.  However, there are situations that you have to run your .NET applications as Windows containers with servercore docker image due to your project having dependencies, such as a third party dll (could be even built by different department in your company) which demands your application to run on Windows servercore docker image. Worst case is sometimes your app is still on .NET 3.1 Core you do not have a servercore image for .NET Core 3.1. (For .NET 5,6,7,8 the Windows servercore images are available.. check here)  Therefore you need to setup .NET Core 3.1 runtime on the servercore docker image. Let's see how we can achive this requirement.

Friday 25 November 2022

Create Azure CNI based AKS Cluster with Application Gateway Ingress Controller (AGIC) Using Terraform

AKS clusters can be created with two networking types Kubenet (basic networking) and Azure CNI (advanced networking). If you are using Windows nodes as well in your AKS cluster you must use Azure CNI (Container Networking Interface).  Application gatway ingress controller is a great way to setup Ingress for AKS. Let's look at terraform code to deploy Azure CNI based AKS with AGIC.

Saturday 19 November 2022

Resolve "BadRequest message: error: code: InUseSubnetCannotBeDeleted" with Bicep IaC

 Bicep is really simple and easy to implement infrastructure as Code tool for Azure. However, there is a bit of an issue with subnet resource when we try to redeploy. Even without no changes Bicep is trying to delete and create subnet resources and cmplaining a subnet cannot be deleted, because the resources are using it. Let's try to understand the problem and a solution to fix the issue.

Friday 11 November 2022

Create Deployment Groups Dynamically in Azure DevOps Release Pipeline

 Deployment groups are used in Azure DevOps classic release pipelines to define groups of targets an application should be deployed. We may sometime need to create these deployment groups dyamically based on the stage we are running in release pipeline. Let's look at the sample PowerShell code to use for creating depployment group dynamically, using Azure DevOps REST API, and how to use it in a pipeline.

Saturday 5 November 2022

Azure Redis Connectivity Checker App

Here is a simple .NET application to test connectivity to Azure Redis Cache. The application code is available in GitHub chamindac/RedisConnectionChecker. Refer the video for more details.

Saturday 29 October 2022

Use Template Parameter to Create Array in Bash Task in Azure Pipelines

 Converting Azure pipeline parameter type of object, which contain an array of strings, to an array object in bash script task is not clearly documented. We can use the join expression for Azure pipeline tasks to achive this requirement. Let's look at how to do with an example.

Saturday 22 October 2022

Writing a json Easily and Elegently in in C# 11

 In the previous post "No More " Escaping Needed with C# 11" we have discussed, how the json can be writen in C# code, without having to escape each occurance of double quote, when we use the new C# 11 feature Raw String Literals. You might not want to hardcode the entire json in code, instead may want to use variables dynamically setting the json body content. Let's see how we can use String interpolation, in Raw String Leiterals to write json body elegently, and have variables dynamically set values in the josn.

Saturday 15 October 2022

No More " Escaping Needed with C# 11

Writing json body in C# code as a string variable value to pass on to a method or service, is something you may hate as you need to escape every " that you use in your json specification, even though you could use @ (verbatim string literals) to write multi-line strings.  With new Raw String Literals in c# 11, we can write " as content of the strings wihtout having to escape each instance. Let's explore bit about escaping double qutes with Raw String Literals.

Saturday 8 October 2022

Check The C# Language Version of a Project

 C# Language version used in your project is determined by the .NET Framework you are using. We can set specific language version for a project if required for exxampe if we need to use the preview features we can add in the <LangVersion>preview</LangVersion> .csproj file <PropertyGroup>. If the language version is not specifically set and if you want to check the language versio used by your project, the following explained step can be performed.

Sunday 2 October 2022

Getting Started with GitHub Copilot with VS Code

GitHub Copilot is the AI pair programmer who will assit us in writing code efficiently, while we are working with VS Code, Visual Studio, JetBrains IDEs or Neovim. Let's explore how to get started with GitHub copilot with VS Code and C# using a console application.

Friday 30 September 2022

Replace String in Variable in Azure DevOps YAML Pipelines

In  Azure DevOps YAML pipelines there are several functions available for you to use. replace is such a useful function, which you can use to replace string segements within a string. Let's look at how we can use replace function to replace contents of a variable. 

Use case would be: For example you have a variable value for your customer api name as cutomer-api.  You may need to use it and generate customer_api value for another variable which you want to use in a namig of resouce, for consitency purpose with _ in naming instead of -.

Tuesday 27 September 2022

Setup jsonnet-bundler in WSL2

 We need jsonnet-bundler to package the jsonnet projects For example, to generate the required Prometheus rules and Grafana dashboards in kubernetes-mixin project used for Kubernetes monitoring,  requires jsonnet-bundler. Let's see how we can setup jsonnet-bundler in Windows Subsystem for Linux (WSL2) to use it as a package tool.

Friday 23 September 2022

Resolve "Unable to connect to the server: getting credentials: exec: executable kubelogin not found" in AKS

az aks get-credentials  is used to get the kubeconfig updated so that we can access AKS clusters from a terminal (You need to first use az login and az account set --subscription to connect to your Azure subscription). You may encounter Unable to connect to the server: getting credentials: exec: executable kubelogin not found issue after geting credentials and when trying to execute kubectl commands such as kubectl get namespace. Let's see what we need to do to get the issue resolved.

Friday 16 September 2022

View More lines in VS Code Integrated Terminal

VS Code might be your favourite development tool to develop in any language in any platform. It has integrated terminals, for PowerShell, comand prompt, Git Bash, WSL  Azure Cloud shell etc. You may find missing teminal logs specially when you run commands producing larger logs for review such as terraform plan or bicep with --what-if. By default integrated terminal in VS Code only displays last 1000 lines. Let's look at how we can increase the number of log lines in the VS code integrated terminal.

Saturday 3 September 2022

Manually Push .NET App Docker Image to Azure Container Registry

 You might want to do quick test deploying your containers to AKS or Azure App Services, while development is ongoing. I fyou do not have a pipelines setup yet you may need to manually push your docker  images to Azure Contianer Registry (ACR). Let's have a look at the steps need to push a local image built to ACR using docker commands.

Wednesday 31 August 2022

Show Terraform Plan in Azure Pipeline Summary

You can view the terraform plan details in the Azure pipeline terraform task logs when you are executing terraform plan in Azure pipelines. However, I would be great to view  the plan in the pipeline summary. The great extension here allows us to have the terraform plan details in the pipeline summary and let's look at the steps required.

Friday 26 August 2022

Resolve 404 for manifest.webmanifest in Azure App Service

 If you are deploying PWA apps with Node JS/Angular to Azure App Services on Windows, you might encounter "The resource you are looking for has been removed, had its name changed, or is temporarily unavailable." with a 404 for manifest.webmanifest, wven though they are correctly deployed to your Azure App Service. Let's see how we can resolve this issue in Azure App Services.

Saturday 20 August 2022

Create Service Connection in Azure DevOps for Azure Container Registry - Using a Service Principal

Adding Azure Container Registry (ACR) service connection to Azure DevOps  is really simple as described in "Create Service Connection in Azure DevOps for Azure Container Registry", when you have the same account you are using for Azure DevOps, is associated with your Azure Subscription. However, this may not be the case always and you may want to push docker images to ACR in an Azure Subscription which is not related to your Azure DevOps organization, such as your customer's production Azure subscription. We have discussed one option with basic authentication in the post "Create Service Connection in Azure DevOps for Azure Container Registry - Using Basic Authentication". Let’s see how to create a service connection for ACR in such situation to utilize it in a deployment pipeline using a Service Principal in this post.

Tuesday 16 August 2022

Create Service Connection in Azure DevOps for Azure Container Registry - Using Basic Authentication

Adding Azure Container Registry (ACR) service connection to Azure DevOps  is really simple as described in "Create Service Connection in Azure DevOps for Azure Container Registry", when you have the same account you are using for Azure DevOps, is associated with your Azure Subscription. However, this may not be the case always and you may want to push docker images to ACR in an Azure Subscription which is not related to your Azure DevOps organization, such as your customer's production Azure subscription. Let’s see how to create a service connection for ACR in such situation to utilize it in a deployment pipeline using basic authentication.

Saturday 13 August 2022

Create Service Connection in Azure DevOps for Azure Container Registry

 To push docker contianer images from Azure Pipelines to Azure Container Registry (ACR) you need to establish a connection between the Azure DevOps Team Project and the Azure Continer Registry in the Azure Subscription. General service principal based Azure Resource Manager Service Connection cannot be used to push docker images to Azure Contianer Registry. We need to instead create a service connection of type docker registry in Azure DevOps. Let's look at few simple steps to get such service connction created.

It is simple to setup this service connection if your Azure subscription and the Azure DevOps belong to the same account as described in this post. If you have your Azure subscription account as a different account form your Azure DevOps account refer one of below options to create the service connectiont to ACR. 

Saturday 6 August 2022

Kubernetes Pod Logs - View Latest Logs Faster

 We have discussed about enabling detailed request, resposnse logs in ASP.NET Core APIs in the post "Log All Requests in ASP.NET Core API". In a contianerinzed API running in a Kubernetes cluster, say AKS, you would be interested in reading these logs to debug some error or for quick monitoring on the requests made. Implementing a proper monitoring solution using ELK for Kubernetes is more useful, however, doing a quick look at logs of contianers/pods will help as well at times. When you run  kubectl logs podname-xxxxxxxxxx-xxxxxx -n k8snamesapce you will get the entire log of a particular pod. But depending on pod age it may be a long log and you might only be interested in couple of minutes or last hour details to have a quick look. Let's see how we can limit and read pod logs for a time frame or number of log lines.

Saturday 30 July 2022

Log All Requests in ASP.NET Core API

Logging all incoming requests and the respose returned data in an API are useful way to diagnose any issues and monitor requests to an API. You can easily enable request logging in AP.NET Core 6 APIs, by setting the log level in app settings. Enabling such request reponse data logging will be useful in containerized APIs deployed to Kubernetes or even for APIs deployed to AzureApp Services  to diagnose and monitoring purposes. Let's look at how to enable request logging.

Saturday 23 July 2022

Path Based Routing to AKS Ingress with Application Gateway Ingress Controller

 We have discussed getting Application Gateway Ingress Controller (AGIC) deployed using AGIC addon method in the post "Enable Application Gateway Ingress Controller (AGIC) for AKS - SImplest Way with a New App Gatway in Same vNet of AKS Cluster". We have tried a sample app deployment and added a routing ingress rule, to route to root, and reach the sample application toverify the working state of the AGIC in AKS cluster. However, generally in the APIs we deploy to AKS cluster, would require path based routing to reach, diffrent APIs. Let's discuss how to create ingress path based routing to AKS deployed APIs using AGIC.

Saturday 16 July 2022

Enable Application Gateway Ingress Controller (AGIC) for AKS - SImplest Way with a New App Gatway in Same vNet of AKS Cluster

 With AKS you can use Nginx ingress controller as can be done with any Kubernetes cluster. However, you might want to have more integratied experience with Azure cloud services, so that other Azure serivces can easily access your applications in your AKS. Application Gateway Ingress Controller (AGIC) is a great way to implement secure ingress for AKS. Essntially, AGIC is a pod deployed in AKS, which will monitor AKS ingress resources and apply App Gatway configurations based on AKS ingress. Let's see how to enable AKS ingress using Application Gateway Ingress Controller, by creating a new App Gatway in the same virtual network of the AKS cluster.

Saturday 9 July 2022

Listing and Switching Kubernetes Config Contexts

You may be having to work with multiple Kubernetes clusters while development or administering. Once you add credentials to kubeconfig you can work with a single cluster at a time, sing kubectl commands. In this post let's see how we can list and switch between different Kubernetes clsuters added to kubeconfig.

Saturday 2 July 2022

Enable Swagger UI with an .NET 6 API having Custom Routing

 In .NET APIs using swagger for API documentation is really useful to perform API testing and to describe API. We may need to set custom API routing, specially when w deploy the APIs as contianers to Kubernetes, to enable path based routing using ingress such as Nginx. Let's look at steps of setting up custom routing and getting swagger to work with custom routing using a .NET 6 API.

Saturday 25 June 2022

Deploying Nginx Ingress to AKS Using a Makefile in a Custom Namespace

 Nginx is a popular ingress controller used in Kubernetes. We can use the yaml file here to deploy Nginx ingress controller to Azure Kubernetes Services. By default the namespace ingress-nginx will be used to deploy the Nginx controller. Let's see the usage of a Makefile to deploy Nginx ingress controller to AKS in a custom namespace utilizing the yaml file here.

Saturday 18 June 2022

Set Environment Variable for .NET Core Running in WSL2 Ubuntu 20.04 Distro

Testing .NET Core applications with environment varaibles as dependency, on Linux using WSL2 and Ubuntu distro, requires you to set environemnt varaibles in WSL2 distro. For settiing up environement variable in your WSL2 distro you can use the ~/.profile file.

Friday 10 June 2022

Get WSL 2 Distro /etc/hosts File Updated via Windows hosts file

 The hosts file in /etc/hosts is allowing the WSL distros to map IP addresses to domain names before going to domain name servers, similar to the Windows hosts file available in C:\Windows\System32\drivers\etc\hosts. You can maintain WSL host file sperately from your Windows host file or let your WSL host file to be generated automatically (the default behavoir) by using contents in your Windows hosts file. 

Saturday 4 June 2022

Resolve " Got permission denied while trying to connect to the Docker daemon socket at unix:///var/run/docker.sock: Get "http://%2Fvar%2Frun%2Fdocker.sock/v1.24/containers/json": dial unix /var/run/docker.sock: connect: permission denied"

While setting up docker on Ubuntu 20.04 you might run into below issue permission denied error is shown while trying to execute any docker command.

Got permission denied while trying to connect to the Docker daemon socket at unix:///var/run/docker.sock: Get "http://%2Fvar%2Frun%2Fdocker.sock/v1.24/containers/json": dial unix /var/run/docker.sock: connect: permission denied

Tuesday 31 May 2022

Create K3D Cluster with Local Docker Registry

 K3D is the lightweight wrapper allowing us to run K3S Ranchers minimal Kubernetes deployment easily in local environments. Developers can quickly create a cluster, test the apps in containers with Kubernetes locally. Advantage is it is really really simple and faster to get a Kubernetes cluster created, and deleted using K3D, giving the opportunity to the developers to play around with Kubernetes as much as they want, without a worry. This is a great way to develop with Kubernetes as if you are using a central development Kubernetes cluster, such as Azure AKS, it takes time for you to get the cluster up and running if you made a mess with it while development. Instead K3D let's you have your own development Kubernetes cluster running locally in your machine, which you can destroy and create faster when ever you want or need.

Sunday 15 May 2022

Resolve C# Connection Issue "StackExchange.Redis.RedisConnectionException: No connection is active/available to service this operation: It was not possible to connect to the redis server(s). There was an authentication failure; check that passwords (or client certificates) are configured correctly." to Azure Redis cache Connection via Private Endpoint

 Using Azure Redis cache with C# throws an error message such as below while accessing the Redis cache via a private endpoint.

StackExchange.Redis.RedisConnectionException: 
No connection is active/available to service this operation: 
GET Zdddddddddddddddddddddddddd; It was not possible to connect to the redis server(s). 
There was an authentication failure; check that passwords (or client certificates) are 
configured correctly. ConnectTimeout, mc: 1/1/0, mgr: 10 of 10 available,
 clientName: DESKTOP-XXXXX, IOCP: (Busy=1,Free=999,Min=16,Max=1000), WORKER: 
(Busy=3,Free=32764,Min=16,Max=32767), v: 2.2.88.56325
 ---> StackExchange.Redis.RedisConnectionException: It was not possible to connect to the 
redis server(s). There was an authentication failure; check that passwords 
(or client certificates) are configured correctly. ConnectTimeout
   --- End of inner exception stack trace ---

Saturday 1 January 2022

Executing Azure CLI Commands with GitHub Actions

 Azure CLI is very powerful in deploying or managing Azure resources programmatically. Generally Azure CLI is used in cloud shell or in PowerShell scripts to deploy and manage resources in Azure. We can use Azure CLI commands in PowerShell script tasks with GitHub Actions to automate resource deployments to Azure. Let's explore the steps required.

Popular Posts