From d3d0b1f1307275650ea2355e5016cf4f10cb33fd Mon Sep 17 00:00:00 2001 From: Anthony Nandaa Date: Thu, 30 Jan 2025 08:42:07 +0300 Subject: [PATCH] fix: docs: windows: enhance the CNI setup instructions The previous instructions had a slight mistake where the CNI version was similar to the CNI plugin Version. At that time, that was true, we had 0.3.0. However, the latest plugin version is 0.3.1 and supports upto CNI v 1.0.0. Fix the installation scripts to have `$cniVersion` and `$cniPluginVersion` as separate variables. Also add script to set up HNS Network on WS2019 when it is not already available by default, like in the rest of the SKUs WS2022+, after enabling Hyper-V. Signed-off-by: Anthony Nandaa --- docs/windows.md | 37 +++++++++++++++++++++++++++++++------ 1 file changed, 31 insertions(+), 6 deletions(-) diff --git a/docs/windows.md b/docs/windows.md index dc367641a..737e8f927 100644 --- a/docs/windows.md +++ b/docs/windows.md @@ -242,9 +242,8 @@ _containers_ and _Hyper-V_ features. $networkName = 'nat' # Get-HnsNetwork is available once you have enabled the 'Hyper-V Host Compute Service' feature # which must have been done at the Quick setup above -# Enable-WindowsOptionalFeature -Online -FeatureName containers -All -# Enable-WindowsOptionalFeature -Online -FeatureName Microsoft-Hyper-V-All -All -# the default one named `nat` should be available +# Enable-WindowsOptionalFeature -Online -FeatureName Microsoft-Hyper-V, Containers -All +# the default one named `nat` should be available, except for WS2019, see notes below. $natInfo = Get-HnsNetwork -ErrorAction Ignore | Where-Object { $_.Name -eq $networkName } if ($null -eq $natInfo) { throw "NAT network not found, check if you enabled containers, Hyper-V features and restarted the machine" @@ -254,12 +253,13 @@ $subnet = $natInfo.Subnets[0].AddressPrefix $cniConfPath = "$env:ProgramFiles\containerd\cni\conf\0-containerd-nat.conf" $cniBinDir = "$env:ProgramFiles\containerd\cni\bin" -$cniVersion = "0.3.0" +$cniVersion = "1.0.0" +$cniPluginVersion = "0.3.1" # get the CNI plugins (binaries) mkdir $cniBinDir -Force -curl.exe -LO https://github.com/microsoft/windows-container-networking/releases/download/v$cniVersion/windows-container-networking-cni-amd64-v$cniVersion.zip -tar xvf windows-container-networking-cni-amd64-v$cniVersion.zip -C $cniBinDir +curl.exe -LO https://github.com/microsoft/windows-container-networking/releases/download/v$cniPluginVersion/windows-container-networking-cni-amd64-v$cniPluginVersion.zip +tar xvf windows-container-networking-cni-amd64-v$cniPluginVersion.zip -C $cniBinDir $natConfig = @" { @@ -282,4 +282,29 @@ $natConfig = @" } "@ Set-Content -Path $cniConfPath -Value $natConfig +# take a look +cat $cniConfPath + +# quick test with nanoserver:ltsc20YY (YMMV) +$YY = 22 +ctr i pull mcr.microsoft.com/windows/nanoserver:ltsc20$YY +ctr run --rm --cni mcr.microsoft.com/windows/nanoserver:ltsc20$YY cni-test cmd /C curl -I example.com ``` + +> [!NOTE] +> **Notes for WS2019:** +> For cases where there is no default NAT network, like in WS2019 or even when you delete one +> and you would like to recreate. You can set this up with the following: + +```powershell +# Assumption: you have enabled Hyper-V and Containers features and restarted +# Enable-WindowsOptionalFeature -Online -FeatureName Microsoft-Hyper-V, Containers -All + +# get the HNS module that has the New-HnsNetwork function. +curl.exe -LO https://raw.githubusercontent.com/microsoft/SDN/master/Kubernetes/windows/hns.psm1 +Import-Module -Force ./hns.psm1 + +$adapter = Get-NetAdapter | where { $_.InterfaceDescription -eq 'Microsoft Hyper-V Network Adapter' } + +New-HnsNetwork -Type NAT -Name nat -AdapterName $adapter.Name +``` \ No newline at end of file