Can I migrate my console apps (which locally run like Windows services) in Kubernetes?

11/16/2021

I developed a .NET Framework console application, built around the concept of "Windows services". In the Main() method, I have something like:

internal static class Program {
   private static void Main(string[] args) {
      if (Environment.UserInteractive) {
         var myService = new MyService();
         myService.Test(args);
      } else {
         ServiceBase.Run(new ServiceBase[] { new MyService() });
      }
   } 
}

MyService is a class that derives from the .NET System.ServiceProcess.ServiceBase class, and MyService overrides its OnStart() method, OnStop() method, and so on. I'd like to run these console applications inside Kubernetes. The problem I face is that the execution immedately ends since the applications are not "installed" as true Window services in the cluster. I've read about worker services in .NET, but I'd like to know if it's possible to maintain the old code.

-- Pine Code
azure-aks
kubernetes
windows-services
worker-service

0 Answers