Skip to content
This repository has been archived by the owner on Oct 24, 2023. It is now read-only.

Commit

Permalink
feat: Windows azure-cni with containerd
Browse files Browse the repository at this point in the history
  • Loading branch information
ksubrmnn committed Mar 28, 2020
1 parent 0313b9f commit 56ba200
Show file tree
Hide file tree
Showing 6 changed files with 130 additions and 62 deletions.
55 changes: 55 additions & 0 deletions examples/windows/kubernetes-hybrid.azure-containerd.json
@@ -0,0 +1,55 @@
{
"apiVersion": "vlabs",
"properties": {
"orchestratorProfile": {
"orchestratorType": "Kubernetes",
"orchestratorRelease": "1.18",
"kubernetesConfig": {
"networkPlugin": "azure",
"containerRuntime": "containerd",
"windowsContainerdURL": "https://aksenginee2etestimages.blob.core.windows.net/test-content/windows-cri-containerd.zip",
"windowsSdnPluginURL": "https://aksenginee2etestimages.blob.core.windows.net/test-content/windows-cni-containerd.zip"
}
},
"masterProfile": {
"count": 1,
"dnsPrefix": "",
"vmSize": "Standard_D2_v2"
},
"agentPoolProfiles": [
{
"name": "linuxpool1",
"count": 2,
"vmSize": "Standard_D2_v2",
"availabilityProfile": "AvailabilitySet"
},
{
"name": "windowspool2",
"count": 2,
"vmSize": "Standard_D2s_v3",
"availabilityProfile": "AvailabilitySet",
"osType": "Windows"
}
],
"windowsProfile": {
"adminUsername": "azureuser",
"adminPassword": "replacepassword1234$",
"enableAutomaticUpdates": false,
"sshEnabled": true
},
"linuxProfile": {
"adminUsername": "azureuser",
"ssh": {
"publicKeys": [
{
"keyData": ""
}
]
}
},
"servicePrincipalProfile": {
"clientId": "",
"secret": ""
}
}
}
9 changes: 7 additions & 2 deletions parts/k8s/kuberneteswindowssetup.ps1
Expand Up @@ -231,7 +231,13 @@ try
if ($useContainerD) {
Write-Log "Installing ContainerD"
$containerdTimer = [System.Diagnostics.Stopwatch]::StartNew()
Install-Containerd -ContainerdUrl $global:ContainerdUrl
$cniBinPath = $global:AzureCNIBinDir
$cniConfigPath = $global:AzureCNIConfDir
if ($global:NetworkPlugin -eq "kubenet") {
$cniBinPath = $global:CNIPath
$cniConfigPath = $global:CNIConfigPath
}
Install-Containerd -ContainerdUrl $global:ContainerdUrl -CNIBinDir $cniBinPath -CNIConfDir $cniConfigPath
$containerdTimer.Stop()
$global:AppInsightsClient.TrackMetric("Install-ContainerD", $containerdTimer.Elapsed.TotalSeconds)
# TODO: disable/uninstall Docker later
Expand Down Expand Up @@ -360,7 +366,6 @@ try
} else {
Update-WinCNI -CNIPath $global:CNIPath
}
Get-HnsPsm1 -HNSModule $global:HNSModule
}

New-ExternalHnsNetwork
Expand Down
57 changes: 30 additions & 27 deletions parts/k8s/windowscontainerdfunc.ps1
@@ -1,50 +1,53 @@
# this is $global to persist across all functions since this is dot-sourced
$global:ContainerdInstallLocation = "$Env:ProgramFiles\containerd"

function RegisterContainerDService
{
function RegisterContainerDService {
Assert-FileExists (Join-Path $global:ContainerdInstallLocation containerd.exe)

Write-Host "Registering containerd as a service"
$cdbinary = Join-Path $global:ContainerdInstallLocation containerd.exe
$svc = Get-Service -Name containerd -ErrorAction SilentlyContinue
if ($null -ne $svc) {
& $cdbinary --unregister-service
& $cdbinary --unregister-service
}
& $cdbinary --register-service
$svc = Get-Service -Name "containerd" -ErrorAction SilentlyContinue
if ($null -eq $svc) {
throw "containerd.exe did not get installed as a service correctly."
throw "containerd.exe did not get installed as a service correctly."
}
$svc | Start-Service
if ($svc.Status -ne "Running") {
throw "containerd service is not running"
throw "containerd service is not running"
}
}


function Install-Containerd
{
Param(
[Parameter(Mandatory = $true)][string]
$ContainerdUrl
)
$zipfile = [Io.path]::Combine($ENV:TEMP, "containerd.zip")
DownloadFileOverHttp -Url $ContainerdUrl -DestinationPath $zipfile
Expand-Archive -path $zipfile -DestinationPath $global:ContainerdInstallLocation
del $zipfile
function Install-Containerd {
Param(
[Parameter(Mandatory = $true)][string]
$ContainerdUrl,
[Parameter(Mandatory = $true)][string]
$CNIBinDir,
[Parameter(Mandatory = $true)][string]
$CNIConfDir
)
$zipfile = [Io.path]::Combine($ENV:TEMP, "containerd.zip")
DownloadFileOverHttp -Url $ContainerdUrl -DestinationPath $zipfile
Expand-Archive -path $zipfile -DestinationPath $global:ContainerdInstallLocation
del $zipfile

Add-SystemPathEntry $global:ContainerdInstallLocation
Add-SystemPathEntry $global:ContainerdInstallLocation

# TODO: remove if the node comes up without this code
# $configDir = [Io.Path]::Combine($ENV:ProgramData, "containerd")
# if (-Not (Test-Path $configDir)) {
# mkdir $configDir
# }
# TODO: remove if the node comes up without this code
# $configDir = [Io.Path]::Combine($ENV:ProgramData, "containerd")
# if (-Not (Test-Path $configDir)) {
# mkdir $configDir
# }

# TODO: call containerd.exe dump config, then modify instead of starting with hardcoded
$configFile = [Io.Path]::Combine($global:ContainerdInstallLocation, "config.toml")
@"
# TODO: call containerd.exe dump config, then modify instead of starting with hardcoded
$configFile = [Io.Path]::Combine($global:ContainerdInstallLocation, "config.toml")

@"
version = 2
root = "C:\\ProgramData\\containerd\\root"
state = "C:\\ProgramData\\containerd\\state"
Expand Down Expand Up @@ -131,8 +134,8 @@ oom_score = 0
runtime_root = ""
privileged_without_host_devices = false
[plugins."io.containerd.grpc.v1.cri".cni]
bin_dir = "C:\\k\\cni"
conf_dir = "C:\\k\\cni\\config"
bin_dir = "$(($CNIBinDir).Replace("\","//"))"
conf_dir = "$(($CNIConfDir).Replace("\","//"))"
max_conf_num = 1
conf_template = ""
[plugins."io.containerd.grpc.v1.cri".registry]
Expand All @@ -149,6 +152,6 @@ oom_score = 0
[plugins."io.containerd.service.v1.diff-service"]
default = ["windows", "windows-lcow"]
"@ | Out-File -Encoding ascii $configFile
RegisterContainerDService
RegisterContainerDService

}
3 changes: 0 additions & 3 deletions pkg/api/vlabs/validate.go
Expand Up @@ -1677,9 +1677,6 @@ func (a *Properties) validateContainerRuntime() error {

// TODO: These validations should be relaxed once ContainerD and CNI plugins are more readily available
if containerRuntime == Containerd && a.HasWindows() {
if a.OrchestratorProfile.KubernetesConfig.NetworkPlugin != "kubenet" {
return errors.Errorf("Windows only supports kubenet with containerd runtime. %q is not supported", a.OrchestratorProfile.KubernetesConfig.NetworkPlugin)
}
if a.OrchestratorProfile.KubernetesConfig.WindowsContainerdURL == "" {
return errors.Errorf("WindowsContainerdURL must be provided when using Windows with ContainerRuntime=containerd")
}
Expand Down
68 changes: 38 additions & 30 deletions pkg/engine/templates_generated.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 56ba200

Please sign in to comment.