Skip to content

Commit 5af636f

Browse files
committed
Enable gracefulshutdown
1 parent 458825d commit 5af636f

File tree

6 files changed

+217
-42
lines changed

6 files changed

+217
-42
lines changed

capz/templates/gmsa-ci.yaml

Lines changed: 36 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -62,13 +62,42 @@ spec:
6262
permissions: "0744"
6363
- content: |
6464
$ErrorActionPreference = "Stop"
65+
$FileContent = Get-Content -Path "$env:SYSTEMDRIVE/var/lib/kubelet/kubeadm-flags.env"
66+
$kubeAdmArgs = $FileContent.TrimStart('KUBELET_KUBEADM_ARGS=').Trim('"')
67+
68+
# Set the path to your kubelet config file
69+
$configFile = "$env:SYSTEMDRIVE/var/lib/kubelet/config.yaml"
70+
$content = Get-Content -Path $configFile
6571
# Check if NodeLogQuery feature gate was specified for the cluster and if so, also enable it via kubelet config
66-
$kubeletEnvContents = Get-Content -Path "/var/lib/kubelet/kubeadm-flags.env"
67-
if ($kubeletEnvContents.Contains("NodeLogQuery=true")) {
68-
Add-Content -Path "$env:SYSTEMDRIVE/var/lib/kubelet/config.yaml" -Value "enableSystemLogQuery: true" -Encoding ascii -NoNewLine
69-
nssm restart kubelet
72+
if ($kubeAdmArgs.Contains("NodeLogQuery=true")) {
73+
$content += "enableSystemLogQuery: true"
74+
}
75+
if ($kubeAdmArgs.Contains("WindowsGracefulNodeShutdown=true")) {
76+
# Remove existing lines that match the settings
77+
$content = $content | Where-Object { $_ -notmatch "^shutdownGracePeriod:" -and $_ -notmatch "^shutdownGracePeriodCriticalPods:" }
78+
# Append new values at the end
79+
$content += "shutdownGracePeriod: 1m"
80+
$content += "shutdownGracePeriodCriticalPods: 20s"
81+
}
82+
83+
# Write the updated content back to the file
84+
$content | Set-Content -Path $configFile -Encoding ascii
85+
path: C:/updateKubeletConfig.ps1
86+
permissions: "0744"
87+
- content: |
88+
# This script restarts the kubelet service.
89+
# It supports both nssm and Windows service configurations,
90+
# ensuring a smooth transition between service managers without interruption.
91+
# This script will eventually be removed once nssm is no longer used.
92+
$scriptPath = "$env:SYSTEMDRIVE/k/RestartKubelet.ps1"
93+
if (Test-Path $scriptPath) {
94+
Write-Host "Found RestartKubelet.ps1, executing..."
95+
& $scriptPath
96+
} else {
97+
Write-Host "RestartKubelet.ps1 not found. Running fallback command..."
98+
nssm set kubelet start SERVICE_AUTO_START
7099
}
71-
path: C:/NodeLogQueryKubeletConfig.ps1
100+
path: C:/KubeletRestart_nssm_sc.ps1
72101
permissions: "0744"
73102
- content: |
74103
mkdir -Force c:/localdumps
@@ -133,8 +162,8 @@ spec:
133162
windows-priorityclass: ABOVE_NORMAL_PRIORITY_CLASS
134163
name: '{{ ds.meta_data["local_hostname"] }}'
135164
postKubeadmCommands:
136-
- powershell C:/NodeLogQueryKubeletConfig.ps1
137-
- nssm set kubelet start SERVICE_AUTO_START
165+
- powershell C:/updateKubeletConfig.ps1
166+
- powershell C:/KubeletRestart_nssm_sc.ps1
138167
- powershell C:/defender-exclude-calico.ps1
139168
preKubeadmCommands:
140169
- powershell C:/create-temp-folder.ps1

capz/templates/gmsa-pr.yaml

Lines changed: 36 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -62,13 +62,42 @@ spec:
6262
permissions: "0744"
6363
- content: |
6464
$ErrorActionPreference = "Stop"
65+
$FileContent = Get-Content -Path "$env:SYSTEMDRIVE/var/lib/kubelet/kubeadm-flags.env"
66+
$kubeAdmArgs = $FileContent.TrimStart('KUBELET_KUBEADM_ARGS=').Trim('"')
67+
68+
# Set the path to your kubelet config file
69+
$configFile = "$env:SYSTEMDRIVE/var/lib/kubelet/config.yaml"
70+
$content = Get-Content -Path $configFile
6571
# Check if NodeLogQuery feature gate was specified for the cluster and if so, also enable it via kubelet config
66-
$kubeletEnvContents = Get-Content -Path "/var/lib/kubelet/kubeadm-flags.env"
67-
if ($kubeletEnvContents.Contains("NodeLogQuery=true")) {
68-
Add-Content -Path "$env:SYSTEMDRIVE/var/lib/kubelet/config.yaml" -Value "enableSystemLogQuery: true" -Encoding ascii -NoNewLine
69-
nssm restart kubelet
72+
if ($kubeAdmArgs.Contains("NodeLogQuery=true")) {
73+
$content += "enableSystemLogQuery: true"
74+
}
75+
if ($kubeAdmArgs.Contains("WindowsGracefulNodeShutdown=true")) {
76+
# Remove existing lines that match the settings
77+
$content = $content | Where-Object { $_ -notmatch "^shutdownGracePeriod:" -and $_ -notmatch "^shutdownGracePeriodCriticalPods:" }
78+
# Append new values at the end
79+
$content += "shutdownGracePeriod: 1m"
80+
$content += "shutdownGracePeriodCriticalPods: 20s"
81+
}
82+
83+
# Write the updated content back to the file
84+
$content | Set-Content -Path $configFile -Encoding ascii
85+
path: C:/updateKubeletConfig.ps1
86+
permissions: "0744"
87+
- content: |
88+
# This script restarts the kubelet service.
89+
# It supports both nssm and Windows service configurations,
90+
# ensuring a smooth transition between service managers without interruption.
91+
# This script will eventually be removed once nssm is no longer used.
92+
$scriptPath = "$env:SYSTEMDRIVE/k/RestartKubelet.ps1"
93+
if (Test-Path $scriptPath) {
94+
Write-Host "Found RestartKubelet.ps1, executing..."
95+
& $scriptPath
96+
} else {
97+
Write-Host "RestartKubelet.ps1 not found. Running fallback command..."
98+
nssm set kubelet start SERVICE_AUTO_START
7099
}
71-
path: C:/NodeLogQueryKubeletConfig.ps1
100+
path: C:/KubeletRestart_nssm_sc.ps1
72101
permissions: "0744"
73102
- content: |
74103
mkdir -Force c:/localdumps
@@ -128,8 +157,8 @@ spec:
128157
windows-priorityclass: ABOVE_NORMAL_PRIORITY_CLASS
129158
name: '{{ ds.meta_data["local_hostname"] }}'
130159
postKubeadmCommands:
131-
- powershell C:/NodeLogQueryKubeletConfig.ps1
132-
- nssm set kubelet start SERVICE_AUTO_START
160+
- powershell C:/updateKubeletConfig.ps1
161+
- powershell C:/KubeletRestart_nssm_sc.ps1
133162
- powershell C:/defender-exclude-calico.ps1
134163
preKubeadmCommands:
135164
- powershell C:/create-temp-folder.ps1

capz/templates/shared-image-gallery-ci.yaml

Lines changed: 36 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -62,13 +62,42 @@ spec:
6262
permissions: "0744"
6363
- content: |
6464
$ErrorActionPreference = "Stop"
65+
$FileContent = Get-Content -Path "$env:SYSTEMDRIVE/var/lib/kubelet/kubeadm-flags.env"
66+
$kubeAdmArgs = $FileContent.TrimStart('KUBELET_KUBEADM_ARGS=').Trim('"')
67+
68+
# Set the path to your kubelet config file
69+
$configFile = "$env:SYSTEMDRIVE/var/lib/kubelet/config.yaml"
70+
$content = Get-Content -Path $configFile
6571
# Check if NodeLogQuery feature gate was specified for the cluster and if so, also enable it via kubelet config
66-
$kubeletEnvContents = Get-Content -Path "/var/lib/kubelet/kubeadm-flags.env"
67-
if ($kubeletEnvContents.Contains("NodeLogQuery=true")) {
68-
Add-Content -Path "$env:SYSTEMDRIVE/var/lib/kubelet/config.yaml" -Value "enableSystemLogQuery: true" -Encoding ascii -NoNewLine
69-
nssm restart kubelet
72+
if ($kubeAdmArgs.Contains("NodeLogQuery=true")) {
73+
$content += "enableSystemLogQuery: true"
74+
}
75+
if ($kubeAdmArgs.Contains("WindowsGracefulNodeShutdown=true")) {
76+
# Remove existing lines that match the settings
77+
$content = $content | Where-Object { $_ -notmatch "^shutdownGracePeriod:" -and $_ -notmatch "^shutdownGracePeriodCriticalPods:" }
78+
# Append new values at the end
79+
$content += "shutdownGracePeriod: 1m"
80+
$content += "shutdownGracePeriodCriticalPods: 20s"
81+
}
82+
83+
# Write the updated content back to the file
84+
$content | Set-Content -Path $configFile -Encoding ascii
85+
path: C:/updateKubeletConfig.ps1
86+
permissions: "0744"
87+
- content: |
88+
# This script restarts the kubelet service.
89+
# It supports both nssm and Windows service configurations,
90+
# ensuring a smooth transition between service managers without interruption.
91+
# This script will eventually be removed once nssm is no longer used.
92+
$scriptPath = "$env:SYSTEMDRIVE/k/RestartKubelet.ps1"
93+
if (Test-Path $scriptPath) {
94+
Write-Host "Found RestartKubelet.ps1, executing..."
95+
& $scriptPath
96+
} else {
97+
Write-Host "RestartKubelet.ps1 not found. Running fallback command..."
98+
nssm set kubelet start SERVICE_AUTO_START
7099
}
71-
path: C:/NodeLogQueryKubeletConfig.ps1
100+
path: C:/KubeletRestart_nssm_sc.ps1
72101
permissions: "0744"
73102
- content: |
74103
mkdir -Force c:/localdumps
@@ -138,8 +167,8 @@ spec:
138167
windows-priorityclass: ABOVE_NORMAL_PRIORITY_CLASS
139168
name: '{{ ds.meta_data["local_hostname"] }}'
140169
postKubeadmCommands:
141-
- powershell C:/NodeLogQueryKubeletConfig.ps1
142-
- nssm set kubelet start SERVICE_AUTO_START
170+
- powershell C:/updateKubeletConfig.ps1
171+
- powershell C:/KubeletRestart_nssm_sc.ps1
143172
- powershell C:/defender-exclude-calico.ps1
144173
preKubeadmCommands:
145174
- powershell C:/create-temp-folder.ps1

capz/templates/windows-base.yaml

Lines changed: 37 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -62,13 +62,43 @@ spec:
6262
permissions: "0744"
6363
- content: |
6464
$ErrorActionPreference = "Stop"
65+
$FileContent = Get-Content -Path "$env:SYSTEMDRIVE/var/lib/kubelet/kubeadm-flags.env"
66+
$kubeAdmArgs = $FileContent.TrimStart('KUBELET_KUBEADM_ARGS=').Trim('"')
67+
68+
# Set the path to your kubelet config file
69+
$configFile = "$env:SYSTEMDRIVE/var/lib/kubelet/config.yaml"
70+
$content = Get-Content -Path $configFile
6571
# Check if NodeLogQuery feature gate was specified for the cluster and if so, also enable it via kubelet config
66-
$kubeletEnvContents = Get-Content -Path "/var/lib/kubelet/kubeadm-flags.env"
67-
if ($kubeletEnvContents.Contains("NodeLogQuery=true")) {
68-
Add-Content -Path "$env:SYSTEMDRIVE/var/lib/kubelet/config.yaml" -Value "enableSystemLogQuery: true" -Encoding ascii -NoNewLine
69-
nssm restart kubelet
72+
if ($kubeAdmArgs.Contains("NodeLogQuery=true")) {
73+
$content += "enableSystemLogQuery: true"
74+
}
75+
if ($kubeAdmArgs.Contains("WindowsGracefulNodeShutdown=true")) {
76+
# Remove existing lines that match the settings
77+
$content = $content | Where-Object { $_ -notmatch "^shutdownGracePeriod:" -and $_ -notmatch "^shutdownGracePeriodCriticalPods:" }
78+
# Append new values at the end
79+
$content += "shutdownGracePeriod: 1m"
80+
$content += "shutdownGracePeriodCriticalPods: 20s"
81+
}
82+
83+
# Write the updated content back to the file
84+
$content | Set-Content -Path $configFile -Encoding ascii
85+
86+
path: C:/updateKubeletConfig.ps1
87+
permissions: "0744"
88+
- content: |
89+
# This script restarts the kubelet service.
90+
# It supports both nssm and Windows service configurations,
91+
# ensuring a smooth transition between service managers without interruption.
92+
# This script will eventually be removed once nssm is no longer used.
93+
$scriptPath = "$env:SYSTEMDRIVE/k/RestartKubelet.ps1"
94+
if (Test-Path $scriptPath) {
95+
Write-Host "Found RestartKubelet.ps1, executing..."
96+
& $scriptPath
97+
} else {
98+
Write-Host "RestartKubelet.ps1 not found. Running fallback command..."
99+
nssm set kubelet start SERVICE_AUTO_START
70100
}
71-
path: C:/NodeLogQueryKubeletConfig.ps1
101+
path: C:/KubeletRestart_nssm_sc.ps1
72102
permissions: "0744"
73103
- content: |
74104
mkdir -Force c:/localdumps
@@ -100,8 +130,8 @@ spec:
100130
windows-priorityclass: ABOVE_NORMAL_PRIORITY_CLASS
101131
name: '{{ ds.meta_data["local_hostname"] }}'
102132
postKubeadmCommands:
103-
- powershell C:/NodeLogQueryKubeletConfig.ps1
104-
- nssm set kubelet start SERVICE_AUTO_START
133+
- powershell C:/updateKubeletConfig.ps1
134+
- powershell C:/KubeletRestart_nssm_sc.ps1
105135
- powershell C:/defender-exclude-calico.ps1
106136
preKubeadmCommands:
107137
- powershell C:/create-temp-folder.ps1

capz/templates/windows-ci.yaml

Lines changed: 36 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -62,13 +62,42 @@ spec:
6262
permissions: "0744"
6363
- content: |
6464
$ErrorActionPreference = "Stop"
65+
$FileContent = Get-Content -Path "$env:SYSTEMDRIVE/var/lib/kubelet/kubeadm-flags.env"
66+
$kubeAdmArgs = $FileContent.TrimStart('KUBELET_KUBEADM_ARGS=').Trim('"')
67+
68+
# Set the path to your kubelet config file
69+
$configFile = "$env:SYSTEMDRIVE/var/lib/kubelet/config.yaml"
70+
$content = Get-Content -Path $configFile
6571
# Check if NodeLogQuery feature gate was specified for the cluster and if so, also enable it via kubelet config
66-
$kubeletEnvContents = Get-Content -Path "/var/lib/kubelet/kubeadm-flags.env"
67-
if ($kubeletEnvContents.Contains("NodeLogQuery=true")) {
68-
Add-Content -Path "$env:SYSTEMDRIVE/var/lib/kubelet/config.yaml" -Value "enableSystemLogQuery: true" -Encoding ascii -NoNewLine
69-
nssm restart kubelet
72+
if ($kubeAdmArgs.Contains("NodeLogQuery=true")) {
73+
$content += "enableSystemLogQuery: true"
74+
}
75+
if ($kubeAdmArgs.Contains("WindowsGracefulNodeShutdown=true")) {
76+
# Remove existing lines that match the settings
77+
$content = $content | Where-Object { $_ -notmatch "^shutdownGracePeriod:" -and $_ -notmatch "^shutdownGracePeriodCriticalPods:" }
78+
# Append new values at the end
79+
$content += "shutdownGracePeriod: 1m"
80+
$content += "shutdownGracePeriodCriticalPods: 20s"
81+
}
82+
83+
# Write the updated content back to the file
84+
$content | Set-Content -Path $configFile -Encoding ascii
85+
path: C:/updateKubeletConfig.ps1
86+
permissions: "0744"
87+
- content: |
88+
# This script restarts the kubelet service.
89+
# It supports both nssm and Windows service configurations,
90+
# ensuring a smooth transition between service managers without interruption.
91+
# This script will eventually be removed once nssm is no longer used.
92+
$scriptPath = "$env:SYSTEMDRIVE/k/RestartKubelet.ps1"
93+
if (Test-Path $scriptPath) {
94+
Write-Host "Found RestartKubelet.ps1, executing..."
95+
& $scriptPath
96+
} else {
97+
Write-Host "RestartKubelet.ps1 not found. Running fallback command..."
98+
nssm set kubelet start SERVICE_AUTO_START
7099
}
71-
path: C:/NodeLogQueryKubeletConfig.ps1
100+
path: C:/KubeletRestart_nssm_sc.ps1
72101
permissions: "0744"
73102
- content: |
74103
mkdir -Force c:/localdumps
@@ -133,8 +162,8 @@ spec:
133162
windows-priorityclass: ABOVE_NORMAL_PRIORITY_CLASS
134163
name: '{{ ds.meta_data["local_hostname"] }}'
135164
postKubeadmCommands:
136-
- powershell C:/NodeLogQueryKubeletConfig.ps1
137-
- nssm set kubelet start SERVICE_AUTO_START
165+
- powershell C:/updateKubeletConfig.ps1
166+
- powershell C:/KubeletRestart_nssm_sc.ps1
138167
- powershell C:/defender-exclude-calico.ps1
139168
preKubeadmCommands:
140169
- powershell C:/create-temp-folder.ps1

capz/templates/windows-pr.yaml

Lines changed: 36 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -62,13 +62,42 @@ spec:
6262
permissions: "0744"
6363
- content: |
6464
$ErrorActionPreference = "Stop"
65+
$FileContent = Get-Content -Path "$env:SYSTEMDRIVE/var/lib/kubelet/kubeadm-flags.env"
66+
$kubeAdmArgs = $FileContent.TrimStart('KUBELET_KUBEADM_ARGS=').Trim('"')
67+
68+
# Set the path to your kubelet config file
69+
$configFile = "$env:SYSTEMDRIVE/var/lib/kubelet/config.yaml"
70+
$content = Get-Content -Path $configFile
6571
# Check if NodeLogQuery feature gate was specified for the cluster and if so, also enable it via kubelet config
66-
$kubeletEnvContents = Get-Content -Path "/var/lib/kubelet/kubeadm-flags.env"
67-
if ($kubeletEnvContents.Contains("NodeLogQuery=true")) {
68-
Add-Content -Path "$env:SYSTEMDRIVE/var/lib/kubelet/config.yaml" -Value "enableSystemLogQuery: true" -Encoding ascii -NoNewLine
69-
nssm restart kubelet
72+
if ($kubeAdmArgs.Contains("NodeLogQuery=true")) {
73+
$content += "enableSystemLogQuery: true"
74+
}
75+
if ($kubeAdmArgs.Contains("WindowsGracefulNodeShutdown=true")) {
76+
# Remove existing lines that match the settings
77+
$content = $content | Where-Object { $_ -notmatch "^shutdownGracePeriod:" -and $_ -notmatch "^shutdownGracePeriodCriticalPods:" }
78+
# Append new values at the end
79+
$content += "shutdownGracePeriod: 1m"
80+
$content += "shutdownGracePeriodCriticalPods: 20s"
81+
}
82+
83+
# Write the updated content back to the file
84+
$content | Set-Content -Path $configFile -Encoding ascii
85+
path: C:/updateKubeletConfig.ps1
86+
permissions: "0744"
87+
- content: |
88+
# This script restarts the kubelet service.
89+
# It supports both nssm and Windows service configurations,
90+
# ensuring a smooth transition between service managers without interruption.
91+
# This script will eventually be removed once nssm is no longer used.
92+
$scriptPath = "$env:SYSTEMDRIVE/k/RestartKubelet.ps1"
93+
if (Test-Path $scriptPath) {
94+
Write-Host "Found RestartKubelet.ps1, executing..."
95+
& $scriptPath
96+
} else {
97+
Write-Host "RestartKubelet.ps1 not found. Running fallback command..."
98+
nssm set kubelet start SERVICE_AUTO_START
7099
}
71-
path: C:/NodeLogQueryKubeletConfig.ps1
100+
path: C:/KubeletRestart_nssm_sc.ps1
72101
permissions: "0744"
73102
- content: |
74103
mkdir -Force c:/localdumps
@@ -128,8 +157,8 @@ spec:
128157
windows-priorityclass: ABOVE_NORMAL_PRIORITY_CLASS
129158
name: '{{ ds.meta_data["local_hostname"] }}'
130159
postKubeadmCommands:
131-
- powershell C:/NodeLogQueryKubeletConfig.ps1
132-
- nssm set kubelet start SERVICE_AUTO_START
160+
- powershell C:/updateKubeletConfig.ps1
161+
- powershell C:/KubeletRestart_nssm_sc.ps1
133162
- powershell C:/defender-exclude-calico.ps1
134163
preKubeadmCommands:
135164
- powershell C:/create-temp-folder.ps1

0 commit comments

Comments
 (0)