Tuesday, January 25, 2022

PowerShell to list all the IIS Web Applications using IISAdministration

When it comes to automating Internet Information Services (IIS) Web server there are multiple choices. One with Appcmd command and the other with PowerShell. In PowerShell itself, there are different modules to manage. The WebAdministration is the legacy and IISAdministration is modern. More on that was written in a previous post about "Change recycle settings of IIS AppPools using PowerShell & appcmd.exe"

Let us get into the business of this post

Problem

There is an existing system that uses the on-premises model for hosting web applications. Windows Server 2019 + IIS is the hosting model. As the first step to the cloud, these servers were lifted and shifted to the Azure. Now to reduce the cost and time to market of course to improve the developer agility the IaaS model needs to be upgraded to containers. AKS is the preferred choice as it is in Azure. As part of the analysis and capacity planning the # of containers needs to be evaluated from the existing IIS-based deployment model.  ie count the web applications in IIS.

So this post is about listing all the web applications inside IIS web server that are spread across different IIS websites.

Solution

Since the last post about IIS automation was using WebAdministration, I thought of going with IISAdministration this time as it's the latest to replace the former.

Hope the code is self-explanatory. If the above embedding is not working please check the GitHub file.

Enjoy scripting...

Tuesday, January 18, 2022

Debugging why the deletion of PVC in Kubernetes is running indefinitely

This is related to troubleshooting Kubernetes deployment and requires good working knowledge about Kubernetes.

Issue

It all started with the issue of HELM chart deployment failing that are triggered from DevOps pipelines. The pipelines were using --atomic flag to make sure the failed deployments are getting rolled back. 

The deployments were working till last Friday and no changes to the HELM charts after that date.

Troubleshooting

The observable missing that we found when running kubectl get all is as follows.

0/3 nodes are available: 3 persistentvolumeclaim "my-azurefile-pvc" is being deleted.           Normal   NotTriggerScaleUp  2m42s (x91 over 17m)  cluster-autoscaler  pod didn't trigger scale-up: 1 persistentvolumeclaim "my-azurefile-pvc" is being deleted

This shows there is a PersistentVolumeClaim hanging around that needs to be deleted. Here is the PVC
The container is not starting due to PVC is not ready and its waiting.

The PVC was in the terminating state. Since it's in the terminating state but not terminating, the next step is to delete the my-azure-pvc and redeploy the HELM chart. When we tried to delete it using the below command, the command was not getting completed.

kubectl delete pvc/my-azurefile-pvc -n <namespace> --force

Warning: Immediate deletion does not wait for confirmation that the running resource has been terminated. The resource may continue to run on the cluster indefinitely.persistentvolumeclaim "my-azurefile-pvc" force deleted

Googling that revealed a possibility that it may have finalizers. We checked it and saw there is a finalizer.


Now we have to remove the finalizer by using the below command. The first command tried with namespace then it showed a wired error message as follows.

kubectl patch pvc my-azurefile-pvc -p '{"metadata":{"finalizers":null}}' -n <namespace>


Error from server (BadRequest): invalid character 'm' looking for beginning of object key string

There was no explanation I got from the internet where is this invalid 'm' character. 

Then we tried without namespace. Then it says the PVC resource is not available in default or I don't have the permission. Really I don't have permission in the default namespace instead I have permission to the namespace allocated to the application's dev instance. The behavior is wired as it's not able to find the resource in the right namespace.

kubectl patch pvc my-azurefile-pvc -p '{"metadata":{"finalizers":null}}'

Then get into research mode again. Then found that if there are any other containers in the cluster using the same PVC, the PVC resource cannot be deleted. We checked all the containers and could see there is another container from different HELM deployment is using it.

kubectl describe pod/<pod id> -n <namespace>

Uninstalled the deployment that created the above pod and the issue was solved.

Root cause

Not sure what caused the PVC to be not deleted in the first place. Maybe someone played in the cluster other than updating HELM charts from the DevOps pipeline.


Tuesday, January 11, 2022

Review of 2021 & plans for 2022 as a software engineer

The usual procedure continues. Reviewing last year and planning next year.

Below are the goals from 2021 as published last year with status.

2021 - What was planned

Goals

  • Continue
    • Focus on containers and K8s hands-on.
    • Pass the AZ-303 certification
    • Linux - Become an intermediate level knowledge
    • Continue to learn more and more enterprise practices. Including infrastructure concerns to understand how to run production systems than just building those
    • Continue making 1 blog post per week.
    • At least 25% or more posts to be videos
    • 100 subscribers in my coding channel Joymon v/s Code.
    • Monthly 1-2 hours to personal projects
  • New
    • Learn Python language. The goal is to reach an intermediate level
    • Build experience in Unified .Net platform.
  • Experiments
    • The big thing would be an attempt to present a topic in a public event conducted by user groups.
    • At least 10% posts to external sites such as CodeProject, DZone CSharpCorner, etc.
    • Set up a blockchain and write one smart contract
    • Write my own GitHub action.

Additional achievements

  • Architected microservice-based applications that are getting deployed to Azure Kubernetes Service.
  • Migrated my personal website https://joymononline.in/ to JAMstack architecture based on  Hugo from AngularJS.

What I was not going to do

  • Blockchain coding - expertise.
  • WebAssembly - Maybe watching some videos. Not in deep.
  • Go & Scala - Same as web assembly.
  • Data science algorithms

2022 - What is ahead

Goals

  • Continue
    • Linux - Install personal laptop to Linux and build expertise
    • Python - Continue learning to become intermediate level.
    • Pass AZ-304 exam. Continue learning Azure computing.
    • Continue making 1 blog post per week.
    • At least 25% or more posts to be videos
    • Achieve 250 subscribers in my coding YouTube channel Joymon v/s Code.
    • Monthly 1-2 hours to personal projects
  • New
    • WebAssembly - Try out apps
    • Blazor - Learn basics
    • Set up Ethereum blockchain and write one smart contract
  • Experiments
    • The big thing would be an attempt to present a topic in a public event conducted by user groups.
    • At least 10% posts to external sites such as CodeProject, DZone CSharpCorner, etc.
    • Write my own GitHub action.
    • Write a test Telegram/Discord bot
    • Write a test Flutter app

What I am not going to do

  • Blockchain coding - expertise.
  • Go & Scala - Maybe watching some videos. Not in deep.
  • Data science algorithms.

Tuesday, January 4, 2022

Using ILogger in minimal .Net ASP.Net Core API Application

.Net 6.0 introduced the minimal API model for WebAPIs. That is highly reducing the amount of boilerplate code to be used to run WebAPIs. All actions can be included in a single file. This post is not to explain the wow factor of the Minimal API model but to give some tips to use ILogger in minimal APIs.

Using ILogger outside of action method

This is about using the ILogger in the Program.cs