Skip to content

Commit

Permalink
Add containerd support to PrepareNode script
Browse files Browse the repository at this point in the history
Signed-off-by: Naman Agarwal <naman.agarwal75@gmail.com>
  • Loading branch information
NamanAg30 committed Jun 1, 2023
1 parent 6590c2a commit e5b9708
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 12 deletions.
7 changes: 5 additions & 2 deletions docs/windows.md
Original file line number Diff line number Diff line change
Expand Up @@ -313,12 +313,15 @@ Set-NetFirewallProfile -Profile Domain,Public,Private -Enabled False
Firstly, install wins, kubelet, kubeadm using script `PrepareNode.ps1` provided
by kubernetes. The third component [`wins`](https://github.com/rancher/wins) is
used to run kube-proxy and antrea-agent on Windows host inside the Windows
container.
container.Specify the Node IP , Kubernetes Version and Container Runtime while
running the script.You can also specify whether you want to install OVS on the
node.

```powershell
# Example:
curl.exe -LO "https://github.com/kubernetes-sigs/sig-windows-tools/releases/download/v0.1.5/PrepareNode.ps1"
.\PrepareNode.ps1 -KubernetesVersion v1.23.5
.\Prepare-Node.ps1 -KubernetesVersion v1.25.0 -InstallOVS -NodeIP 192.168.1.10 -ContainerRuntime ContainerD
```

#### 4. Prepare Node environment needed by antrea-agent
Expand Down
51 changes: 41 additions & 10 deletions hack/windows/Prepare-Node.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,11 @@ Install OVS
.PARAMETER NodeIP
The node ip used by kubelet
.PARAMETER ContainerRuntime
The Container runtime that Kubernets will use
.EXAMPLE
PS> .\Prepare-Node.ps1 -KubernetesVersion v1.18.0 -InstallOVS -NodeIP 192.168.1.10
PS> .\Prepare-Node.ps1 -KubernetesVersion v1.18.0 -InstallOVS -NodeIP 192.168.1.10 -ContainerRuntime ContainerD
#>

Expand All @@ -32,6 +35,9 @@ Param(
[parameter(Mandatory = $true, HelpMessage="Node IP")] [string] $NodeIP,
[parameter(Mandatory = $false)] [switch] $InstallOVS = $false,
[parameter(Mandatory = $false, HelpMessage="Kubernetes download")] [string] $KubernetesURL="dl.k8s.io"
[parameter(HelpMessage="Container runtime that Kubernets will use")]
[ValidateSet("ContainerD", "Docker")]
[string] $ContainerRuntime = "Docker"
)
$ErrorActionPreference = 'Stop'

Expand All @@ -50,6 +56,20 @@ If (Get-Service kubelet -ErrorAction SilentlyContinue) {
exit 0
}

if ($ContainerRuntime -eq "Docker") {
if (-not(Test-Path "//./pipe/docker_engine")) {
Write-Error "Docker service was not detected - please install start Docker before calling
PrepareNode.ps1 with -ContainerRuntime Docker"
exit 1
}
} elseif ($ContainerRuntime -eq "ContainerD") {
if (-not(Test-Path "//./pipe/containerd-containerd")) {
Write-Error "ContainerD service was not detected - please install and start ContainerD
before calling PrepareNode.ps1 with -ContainerRuntime ContainerD"
exit 1
}
}

if (!$KubernetesVersion.StartsWith("v")) {
$KubernetesVersion = "v" + $KubernetesVersion
}
Expand All @@ -71,8 +91,15 @@ DownloadFile "$global:KubernetesPath\kubeadm.exe" "https://$KubernetesURL/$Kuber
DownloadFile "$global:KubernetesPath\wins.exe" https://github.com/rancher/wins/releases/download/v0.0.4/wins.exe

# Create host network to allow kubelet to schedule hostNetwork pods
Write-Host "Creating Docker host network"
docker network create -d nat host
if ($ContainerRuntime -eq "Docker") {
Write-Host "Creating Docker host network"
docker network create -d nat host
} elseif ($ContainerRuntime -eq "ContainerD") {
Write-Host "Creating ContainerD host network"
DownloadFile "c:\k\hns.psm1" https://github.com/Microsoft/SDN/raw/master/Kubernetes/windows/hns.psm1
Import-Module "c:\k\hns.psm1"
New-HnsNetwork -Type NAT -Name nat
}

Write-Host "Registering wins service"
wins.exe srv app run --register
Expand All @@ -86,17 +113,21 @@ New-Item -path C:\var\lib\kubelet\etc\kubernetes\pki -type SymbolicLink -value C
$StartKubeletFileContent = '$FileContent = Get-Content -Path "/var/lib/kubelet/kubeadm-flags.env"
$global:KubeletArgs = $FileContent.Trim("KUBELET_KUBEADM_ARGS=`"")
$netId = docker network ls -f name=host --format "{{ .ID }}"
$global:containerRuntime = {{CONTAINER_RUNTIME}}
if ($global:containerRuntime -eq "Docker") {
$netId = docker network ls -f name=host --format "{{ .ID }}"
if ($netId.Length -lt 1) {
if ($netId.Length -lt 1) {
docker network create -d nat host
}
}
& C:\k\Prepare-ServiceInterface.ps1 -InterfaceAlias "HNS Internal NIC"
$cmd = "C:\k\kubelet.exe $global:KubeletArgs --cert-dir=$env:SYSTEMDRIVE\var\lib\kubelet\pki --config=/var/lib/kubelet/config.yaml --bootstrap-kubeconfig=/etc/kubernetes/bootstrap-kubelet.conf --kubeconfig=/etc/kubernetes/kubelet.conf --hostname-override=$(hostname) --pod-infra-container-image=`"mcr.microsoft.com/oss/kubernetes/pause:1.3.0`" --enable-debugging-handlers --cgroups-per-qos=false --enforce-node-allocatable=`"`" --network-plugin=cni --resolv-conf=`"`" --log-dir=/var/log/kubelet --logtostderr=false --image-pull-progress-deadline=20m --node-ip=$env:NODE_IP"
$cmd = "C:\k\kubelet.exe $global:KubeletArgs --cert-dir=$env:SYSTEMDRIVE\var\lib\kubelet\pki --config=/var/lib/kubelet/config.yaml --bootstrap-kubeconfig=/etc/kubernetes/bootstrap-kubelet.conf --kubeconfig=/etc/kubernetes/kubelet.conf --hostname-override=$(hostname) --pod-infra-container-image=`"mcr.microsoft.com/oss/kubernetes/pause:1.4.1`" --enable-debugging-handlers --cgroups-per-qos=false --enforce-node-allocatable=`"`" --resolv-conf=`"`" --log-dir=/var/log/kubelet --logtostderr=false --container-runtime=remote --container-runtime-endpoint=npipe:\\\\.\\pipe\\containerd-containerd --node-ip=$env:NODE_IP --feature-gates=WindowsHostProcessContainers=true"
Invoke-Expression $cmd'
$StartKubeletFileContent = $StartKubeletFileContent -replace "{{CONTAINER_RUNTIME}}",
"`"$ContainerRuntime`""
Set-Content -Path $global:StartKubeletScript -Value $StartKubeletFileContent

Write-Host "Installing nssm"
Expand All @@ -123,9 +154,9 @@ nssm set kubelet DependOnService docker
New-NetFirewallRule -Name kubelet -DisplayName 'kubelet' -Enabled True -Direction Inbound -Protocol TCP -Action Allow -LocalPort 10250

# Create netadapter for kube-proxy, the default full name of the adapter is "vEthernet (HNS Internal NIC)"
& ./Prepare-ServiceInterface.ps1
& .\Prepare-ServiceInterface.ps1 -InterfaceAlias "HNS Internal NIC"

if ($InstallOVS) {
Write-Host "Installing OVS"
& .\Install-OVS.ps1
}
}

0 comments on commit e5b9708

Please sign in to comment.