Siemens-Healthineers / K2s

Kubernetes distribution for Windows & Linux workloads
https://siemens-healthineers.github.io/K2s/
MIT License
40 stars 4 forks source link

Failed to deploy a pod to windows #738

Closed yanrunming closed 1 month ago

yanrunming commented 1 month ago

According to the official building guide (https://siemens-healthineers.github.io/K2s/latest/user-guide/building-container-image/#building-a-windows-container-image), I built a container image and failed to deploy it to the win10 node.

My steps:

  1. Create a simple console project (dotnet framework 4.7.2) for testing
        static void Main(string[] args)
        {
            Console.WriteLine("test1");
            Console.ReadKey();
        }
  2. Add the docker file Screenshot 2024-09-12 155716
    
    # tag 6, Use the Microsoft Windows Server Core image with .NET Framework 4.7.2
    FROM mcr.microsoft.com/dotnet/framework/runtime:4.7.2-windowsservercore-ltsc2019
    # tag 5
    # FROM mcr.microsoft.com/windows/servercore:ltsc2019
    # tag 4
    # FROM mcr.microsoft.com/windows/nanoserver:ltsc2019

Set up environment variables

ENV DOTNET_RUNNING_IN_CONTAINER=true

Set the working directory

WORKDIR /app

Copy the application files to the container

COPY bin/Debug/ .

Specify the command to run your application

CMD ["ConsoleApp1.exe"]

3. Build the container image
```cmd
c:\k2s\k2s image build --input-folder Z:\test\docker\ConsoleApp1\ConsoleApp1 --windows --image-name local/consoleapp1 --image-tag 6 -o

Screenshot 2024-09-12 160056

  1. Apply the pod
    apiVersion: apps/v1
    kind: Deployment
    metadata:
    name: consoleapp1
    spec:
    replicas: 1
    selector:
    matchLabels:
      app: consoleapp1
    template:
    metadata:
      labels:
        app: consoleapp1
    spec:
      nodeSelector:
        kubernetes.io/os: windows
      tolerations:
        - key: "OS"
          operator: "Equal"
          value: "Windows"
          effect: "NoSchedule"
      containers:
      - name: consoleapp1
        image: docker.io/local/consoleapp1:6
  2. But the pods failed to run Screenshot 2024-09-12 160524 My environments Screenshot 2024-09-12 160819

Thanks!

krotz-dieter commented 1 month ago

This issue is known, the official image mcr.microsoft.com/dotnet/framework/runtime:4.7.2-windowsservercore-ltsc2019 is not released for newer Windows 10 OS versions. You can try syngopredevelopmentimages.azurecr.io/dotnetframework:base, which is older but should also work .NET Framework processes. Better is to create windows container which uses the nano server image as base, it's only around 100MB: https://hub.docker.com/r/microsoft/windows-nanoserver

Example for that in K2s: https://github.com/Siemens-Healthineers/K2s/blob/main/k2s/test/e2e/addons/storage/smb/diskwriter/Dockerfile or https://github.com/Siemens-Healthineers/K2s/tree/main/k2s/test/e2e/addons/generic/build_image/weather-win

If it's OK for you, I would close this issue.

yanrunming commented 1 month ago

I tested the base and still got some error.

FROM mcr.microsoft.com/windows/nanoserver:20H2
COPY bin/Debug/ .
CMD ["ConsoleApp1.exe"]

Screenshot 2024-09-14 165538

krotz-dieter commented 1 month ago

For dotnetframework you need a dotnetframework base image like we have syngopredevelopmentimages.azurecr.io/dotnetframework:base. I can give you the token to access it. Or you check these examples: https://github.com/microsoft/dotnet-framework-docker/blob/main/samples/README.md

Better you do it on Windows 11 with mcr.microsoft.com/dotnet/framework/runtime:4.8.1, on Windows 10 you need to use our base image because MS stopped to provide support after 20H2.

Else please checkout the samples from K2s with golang: https://github.com/Siemens-Healthineers/K2s/blob/main/k2s/test/e2e/addons/storage/smb/diskwriter/Dockerfile or https://github.com/Siemens-Healthineers/K2s/tree/main/k2s/test/e2e/addons/generic/build_image/weather-win

Also in containers never use debug executables always release images because of dependencies !

yanrunming commented 1 month ago

Hi dieter, you are so kind. Thanks for your reminder. I didn't expect that It was a compatibility issue. Due to my host is win10 22h2(build no 19045), I should choose the 20H2 (19042) base image. And the nanoserver doesn't support the old net framework. So servercore:20H2 does work.

FROM mcr.microsoft.com/windows/servercore:20H2
WORKDIR /app
COPY ndp48.exe .
RUN ndp48.exe /q /norestart /log C:/dotnet48_install.log
COPY bin/Release/ .
CMD ["ConsoleApp2.exe"]