Skip to content

Commit d3d0b1f

Browse files
committed
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 <[email protected]>
1 parent 449856f commit d3d0b1f

File tree

1 file changed

+31
-6
lines changed

1 file changed

+31
-6
lines changed

docs/windows.md

Lines changed: 31 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -242,9 +242,8 @@ _containers_ and _Hyper-V_ features.
242242
$networkName = 'nat'
243243
# Get-HnsNetwork is available once you have enabled the 'Hyper-V Host Compute Service' feature
244244
# which must have been done at the Quick setup above
245-
# Enable-WindowsOptionalFeature -Online -FeatureName containers -All
246-
# Enable-WindowsOptionalFeature -Online -FeatureName Microsoft-Hyper-V-All -All
247-
# the default one named `nat` should be available
245+
# Enable-WindowsOptionalFeature -Online -FeatureName Microsoft-Hyper-V, Containers -All
246+
# the default one named `nat` should be available, except for WS2019, see notes below.
248247
$natInfo = Get-HnsNetwork -ErrorAction Ignore | Where-Object { $_.Name -eq $networkName }
249248
if ($null -eq $natInfo) {
250249
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
254253

255254
$cniConfPath = "$env:ProgramFiles\containerd\cni\conf\0-containerd-nat.conf"
256255
$cniBinDir = "$env:ProgramFiles\containerd\cni\bin"
257-
$cniVersion = "0.3.0"
256+
$cniVersion = "1.0.0"
257+
$cniPluginVersion = "0.3.1"
258258

259259
# get the CNI plugins (binaries)
260260
mkdir $cniBinDir -Force
261-
curl.exe -LO https://github.com/microsoft/windows-container-networking/releases/download/v$cniVersion/windows-container-networking-cni-amd64-v$cniVersion.zip
262-
tar xvf windows-container-networking-cni-amd64-v$cniVersion.zip -C $cniBinDir
261+
curl.exe -LO https://github.com/microsoft/windows-container-networking/releases/download/v$cniPluginVersion/windows-container-networking-cni-amd64-v$cniPluginVersion.zip
262+
tar xvf windows-container-networking-cni-amd64-v$cniPluginVersion.zip -C $cniBinDir
263263

264264
$natConfig = @"
265265
{
@@ -282,4 +282,29 @@ $natConfig = @"
282282
}
283283
"@
284284
Set-Content -Path $cniConfPath -Value $natConfig
285+
# take a look
286+
cat $cniConfPath
287+
288+
# quick test with nanoserver:ltsc20YY (YMMV)
289+
$YY = 22
290+
ctr i pull mcr.microsoft.com/windows/nanoserver:ltsc20$YY
291+
ctr run --rm --cni mcr.microsoft.com/windows/nanoserver:ltsc20$YY cni-test cmd /C curl -I example.com
285292
```
293+
294+
> [!NOTE]
295+
> **Notes for WS2019:**
296+
> For cases where there is no default NAT network, like in WS2019 or even when you delete one
297+
> and you would like to recreate. You can set this up with the following:
298+
299+
```powershell
300+
# Assumption: you have enabled Hyper-V and Containers features and restarted
301+
# Enable-WindowsOptionalFeature -Online -FeatureName Microsoft-Hyper-V, Containers -All
302+
303+
# get the HNS module that has the New-HnsNetwork function.
304+
curl.exe -LO https://raw.githubusercontent.com/microsoft/SDN/master/Kubernetes/windows/hns.psm1
305+
Import-Module -Force ./hns.psm1
306+
307+
$adapter = Get-NetAdapter | where { $_.InterfaceDescription -eq 'Microsoft Hyper-V Network Adapter' }
308+
309+
New-HnsNetwork -Type NAT -Name nat -AdapterName $adapter.Name
310+
```

0 commit comments

Comments
 (0)