Skip to content

Commit f1efbcc

Browse files
authored
Remove nat network (#42)
* Antrea retries if kube proxy not online yet * remove that containerd nat CNI * fix containerd
1 parent bb11056 commit f1efbcc

File tree

7 files changed

+145
-16
lines changed

7 files changed

+145
-16
lines changed

Vagrantfile

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,14 +49,16 @@ Vagrant.configure(2) do |config|
4949
winw1.vm.network :private_network, ip:"10.20.30.11"
5050
winw1.vm.synced_folder ".", "/vagrant", disabled:true
5151
winw1.vm.synced_folder "./sync/shared", "C:/sync/shared"
52-
winw1.vm.synced_folder "./sync/windows/bin/", "C:/sync/windows/bin"
52+
winw1.vm.synced_folder "./sync/windows/", "C:/sync/windows/"
53+
winw1.vm.synced_folder "./forked", "C:/forked/"
54+
5355
winw1.vm.provider :virtualbox do |vb|
5456
vb.memory = windows_ram
5557
vb.cpus = windows_cpus
5658
vb.gui = false
5759
end
5860

59-
winw1.vm.provision "shell", path: "sync/windows/hyperv.ps1", privileged: true #, run: "never"
61+
winw1.vm.provision "shell", path: "sync/windows/hyperv.ps1", privileged: true
6062
winw1.vm.provision :reload
6163
winw1.vm.provision "shell", path: "sync/windows/containerd1.ps1", privileged: true #, run: "never"
6264
winw1.vm.provision :reload

forked/1-antrea.ps1

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -131,9 +131,6 @@ Get-Service *kube*
131131
Get-Service *antrea*
132132
Get-Service *ovs*
133133

134-
##################################################
135-
# Try starting antrea. Restart it, just in case #
136-
##################################################
137134
$antrea = Get-Service -Name "antrea-agent"
138135
$antrea_starts = 0
139136
while ($antrea.Status -ne 'Running')

forked/Install-Containerd.ps1

Lines changed: 136 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,136 @@
1+
<#
2+
.SYNOPSIS
3+
Installs ContainerD on a Windows machines in preperation for joining the node to a Kubernetes cluster.
4+
5+
.DESCRIPTION
6+
This script
7+
- Verifies that Windows Features requried for running contianers are enabled (and enables then if they are not)
8+
- Downloads ContainerD binaries from from at the version specified.
9+
- Downloads Windows SND CNI plugins.
10+
- Sets up a basic nat networking config for ContainerD to use until another CNI is configured
11+
- Registers ContainerD as a windows service.
12+
13+
.PARAMETER ContainerDVersion
14+
ContainerD version to download and use.
15+
16+
.PARAMETER netAdapterName
17+
Name of network adapter to use when configuring basic nat network.
18+
19+
.EXAMPLE
20+
PS> .\Install-Conatinerd.ps1
21+
22+
#>
23+
24+
Param(
25+
[parameter(HelpMessage = "ContainerD version to use")]
26+
[string] $ContainerDVersion = "1.4.1",
27+
[parameter(HelpMessage = "Name of network adapter to use when configuring basic nat network")]
28+
[string] $netAdapterName = "Ethernet"
29+
)
30+
31+
$ErrorActionPreference = 'Stop'
32+
33+
function DownloadFile($destination, $source) {
34+
Write-Host("Downloading $source to $destination")
35+
curl.exe --silent --fail -Lo $destination $source
36+
37+
if (!$?) {
38+
Write-Error "Download $source failed"
39+
exit 1
40+
}
41+
}
42+
43+
<#
44+
.DESCRIPTION
45+
Computes a subnet for a gateway from the IPv4 IPAddress and PrefixLength properties
46+
for a given network adapter. This value is used for IPAM in a nat CNI config required for
47+
containerd.
48+
49+
.NOTES
50+
This logic is adapted from
51+
https://github.com/containerd/containerd/blob/4a6b47d470d9f2dfc3d49f2819b968861dfa123e/script/setup/install-cni-windows
52+
53+
.EXAMPLE
54+
PS> CalculateSubNet -gateway 172.16.5.8 -prefixLength 24
55+
172.16.5.0/8
56+
#>
57+
function CalculateSubNet {
58+
param (
59+
[string]$gateway,
60+
[int]$prefixLength
61+
)
62+
$len = $prefixLength
63+
$parts = $gateway.Split('.')
64+
$result = @()
65+
for ($i = 0; $i -le 3; $i++) {
66+
if ($len -ge 8) {
67+
$mask = 255
68+
69+
}
70+
elseif ($len -gt 0) {
71+
$mask = ((256 - 2 * (8 - $len)))
72+
}
73+
else {
74+
$mask = 0
75+
}
76+
$len -= 8
77+
$result += ([int]$parts[$i] -band $mask)
78+
}
79+
80+
$subnetIp = [string]::Join('.', $result)
81+
$cidr = 32 - $prefixLength
82+
return "${subnetIp}/$cidr"
83+
}
84+
85+
$requiredWindowsFeatures = @(
86+
"Containers",
87+
"Hyper-V",
88+
"Hyper-V-PowerShell")
89+
90+
function ValidateWindowsFeatures {
91+
$allFeaturesInstalled = $true
92+
foreach ($feature in $requiredWindowsFeatures) {
93+
$f = Get-WindowsFeature -Name $feature
94+
if (-not $f.Installed) {
95+
Write-Warning "Windows feature: '$feature' is not installed."
96+
$allFeaturesInstalled = $false
97+
}
98+
}
99+
return $allFeaturesInstalled
100+
}
101+
102+
if (-not (ValidateWindowsFeatures)) {
103+
Write-Output "Installing required windows features..."
104+
105+
foreach ($feature in $requiredWindowsFeatures) {
106+
Install-WindowsFeature -Name $feature
107+
}
108+
109+
Write-Output "Please reboot and re-run this script."
110+
exit 0
111+
}
112+
113+
Write-Output "Getting ContainerD binaries"
114+
$global:ConainterDPath = "$env:ProgramFiles\containerd"
115+
mkdir -Force $global:ConainterDPath | Out-Null
116+
DownloadFile "$global:ConainterDPath\containerd.tar.gz" https://github.com/containerd/containerd/releases/download/v${ContainerDVersion}/containerd-${ContainerDVersion}-windows-amd64.tar.gz
117+
tar.exe -xvf "$global:ConainterDPath\containerd.tar.gz" --strip=1 -C $global:ConainterDPath
118+
$env:Path += ";$global:ConainterDPath"
119+
[Environment]::SetEnvironmentVariable("Path", $env:Path, [System.EnvironmentVariableTarget]::Machine)
120+
containerd.exe config default | Out-File "$global:ConainterDPath\config.toml" -Encoding ascii
121+
#config file fixups
122+
$config = Get-Content "$global:ConainterDPath\config.toml"
123+
$config = $config -replace "bin_dir = (.)*$", "bin_dir = `"c:/opt/cni/bin`""
124+
$config = $config -replace "conf_dir = (.)*$", "conf_dir = `"c:/etc/cni/net.d`""
125+
$config | Set-Content "$global:ConainterDPath\config.toml" -Force
126+
127+
mkdir -Force c:\opt\cni\bin | Out-Null
128+
mkdir -Force c:\etc\cni\net.d | Out-Null
129+
130+
Write-Output "Registering ContainerD as a service"
131+
containerd.exe --register-service
132+
133+
Write-Output "Starting ContainerD service"
134+
Start-Service containerd
135+
136+
Write-Output "Done - please remember to add '--cri-socket `"npipe:////./pipe/containerd-containerd`"' to your kubeadm join command"

forked/PrepareNode.ps1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ DownloadFile "$global:KubernetesPath\kubeadm.exe" https://dl.k8s.io/$KubernetesV
132132
if ($ContainerRuntime -eq "Docker") {
133133
# Create host network to allow kubelet to schedule hostNetwork pods
134134
# NOTE: For containerd the 0-containerd-nat.json network config template added by
135-
# Install-containerd.ps1 joins pods to the host network.
135+
# Install-containerd.ps1 joins pods to the host network. but it doesnt work .
136136
Write-Host "Creating Docker host network"
137137
docker network create -d nat host
138138
} elseif ($ContainerRuntime -eq "containerD") {

sync/shared/kubejoin.ps1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
$env:path += ";C:\Program Files\containerd"
22
[Environment]::SetEnvironmentVariable("Path", $env:Path, [System.EnvironmentVariableTarget]::Machine)
3-
kubeadm join 10.20.30.10:6443 --cri-socket "npipe:////./pipe/containerd-containerd" --token 86039w.99bp7lykobg831qx --discovery-token-ca-cert-hash sha256:6f4cac90bb19a1af3c620eb4bbd015d00b2181653ab6f36a3bf5ebce0dc01e76
3+
kubeadm join 10.20.30.10:6443 --cri-socket "npipe:////./pipe/containerd-containerd" --token fewn1r.evy8krm0f4xvqcac --discovery-token-ca-cert-hash sha256:f87ed7d225085d86c5b93b7dce2dc20d38aacea803d7af3f158ddf7804720dec

sync/windows/containerd1.ps1

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -25,17 +25,12 @@ $ProgressPreference = 'SilentlyContinue'
2525
#Write-Output "### Enabling Hyper-V-PowerShell-Module"
2626
#Enable-WindowsOptionalFeature -Online -FeatureName Microsoft-Hyper-V-Management-PowerShell
2727

28-
2928
Set-Location 'C:\k'
3029

31-
Write-Output "#Curling 'Install-Containerd.ps1'"
32-
33-
curl.exe -LO 'https://github.com/kubernetes-sigs/sig-windows-tools/releases/latest/download/Install-Containerd.ps1'
34-
3530
Write-Output "# Running 'Install-Containerd.ps1'"
3631

37-
PowerShell "C:\k\Install-Containerd.ps1"
38-
32+
# Our own version of install-containerd that omits the weird nat cni network thing
33+
PowerShell "C:/forked/Install-Containerd.ps1"
3934

4035
# To avoid the "crictl.exe not on the path error, we add containerd permanantly to the pathhhhh"
4136
# TODO THIS might not be needed ...

sync/windows/k.ps1

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,7 @@ $ErrorActionPreference = 'Stop'
2121
Write-Output "Kubernetes Version $KubernetesVersion"
2222

2323
dism /online /get-features
24-
curl.exe -LO https://github.com/kubernetes-sigs/sig-windows-tools/releases/latest/download/Install-Containerd.ps1
25-
.\Install-Containerd.ps1
24+
PowerShell C:/forked/Install-Containerd.ps1
2625
ctr.exe version
2726

2827
New-Item -ItemType Directory -Force -Path C:\k

0 commit comments

Comments
 (0)