@@ -242,9 +242,8 @@ _containers_ and _Hyper-V_ features.
242
242
$networkName = 'nat'
243
243
# Get-HnsNetwork is available once you have enabled the 'Hyper-V Host Compute Service' feature
244
244
# 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.
248
247
$natInfo = Get-HnsNetwork -ErrorAction Ignore | Where-Object { $_.Name -eq $networkName }
249
248
if ($null -eq $natInfo) {
250
249
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
254
253
255
254
$cniConfPath = "$env:ProgramFiles\containerd\cni\conf\0-containerd-nat.conf"
256
255
$cniBinDir = "$env:ProgramFiles\containerd\cni\bin"
257
- $cniVersion = "0.3.0"
256
+ $cniVersion = "1.0.0"
257
+ $cniPluginVersion = "0.3.1"
258
258
259
259
# get the CNI plugins (binaries)
260
260
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
263
263
264
264
$natConfig = @"
265
265
{
@@ -282,4 +282,29 @@ $natConfig = @"
282
282
}
283
283
"@
284
284
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
285
292
```
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