ACR部署Windows容器到AKS失败:容器与主机操作系统不匹配
Let's break down why you're hitting this error and walk through the fixes step by step:
Root Cause
Windows containers have a strict compatibility rule: the container's Windows kernel version must match the host node's kernel version (or belong to the same release channel). Looking at your node details:
akssample000000 Ready agent 2d2h v1.14.0 10.240.0.35
Windows Server Datacenter 10.0.17763.379 docker://18.9.2
Your Windows node runs Windows Server 2019 (LTSC 2019, build 17763.379). The microsoft/iis:latest image you used defaults to the newest Windows Server release (likely Windows Server 2022, build 20348+), which has a mismatched kernel version—this is exactly what's triggering the error.
Step-by-Step Solution
1. Use a Windows Server 2019-compatible IIS base image
Replace the generic microsoft/iis:latest in your Dockerfile with an image built specifically for Windows Server 2019 LTSC. Microsoft maintains official tagged images for this:
# IIS image optimized for Windows Server 2019 LTSC FROM mcr.microsoft.com/windows/servercore/iis:windowsservercore-ltsc2019 SHELL ["powershell"] RUN Install-WindowsFeature NET-Framework-45-ASPNET ; \ Install-WindowsFeature Web-Asp-Net45 # Fixed path mismatch: original COPY used "ewims" but website targeted "c:\sample" COPY . c:\sample RUN Remove-WebSite -Name 'Default Web Site' RUN New-Website -Name 'sample' -Port 80 \ -PhysicalPath 'c:\sample' -ApplicationPool '.NET v4.5' EXPOSE 80
Note: I corrected a path inconsistency in your original Dockerfile—you copied files to ewims but configured the website to use c:\sample, which would have caused another error even after fixing the OS mismatch.
2. Rebuild and push the updated image to ACR
# Build the new image with an updated version tag docker build -t samplecloud.azurecr.io/sample:v2 . # Authenticate to your Azure Container Registry az acr login --name samplecloud # Push the image to ACR docker push samplecloud.azurecr.io/sample:v2
3. Update your deployment YAML
Modify the image field in your Deployment spec to use the new v2 image:
containers: - name: samplecloudpoc-v1 image: samplecloud.azurecr.io/sample:v2 # Updated to the compatible image version ports: - containerPort: 80 # ... rest of your container configuration remains unchanged
4. Redeploy to AKS
kubectl apply -f your-deployment-file.yaml
Quick Validation Checks
- Your
nodeSelector: beta.kubernetes.io/os: windowsis correct for Kubernetes 1.14 (newer versions usekubernetes.io/os: windows, but this works for your cluster). - The Docker runtime version (18.9.2) on your Windows node is fully compatible with Windows Server 2019 containers, so no changes are needed there.
内容的提问来源于stack exchange,提问作者Hub

