Skip to content

Commit

Permalink
fix: upgrade from k8s v1.26.x to v1.27.y, kubelet restart failed (#4850)
Browse files Browse the repository at this point in the history
  • Loading branch information
yangxggo authored Jul 9, 2024
1 parent 74e80c5 commit b5a1ef6
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions pkg/runtime/kubernetes/upgrade.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,13 @@ func (k *KubeadmRuntime) upgradeMaster0(conversion *types.ConvertedKubeadmConfig
return err
}
}

if gte(sver, V1270) {
if err := k.changeKubeletExtraArgs(master0ip); err != nil {
return err
}
}

master0Name, err := k.remoteUtil.Hostname(master0ip)
if err != nil {
return err
Expand Down Expand Up @@ -139,6 +146,13 @@ func (k *KubeadmRuntime) upgradeOtherNodes(ips []string, version string) error {
return err
}
}

if gte(sver, V1270) {
if err := k.changeKubeletExtraArgs(ip); err != nil {
return err
}
}

nodename, err := k.remoteUtil.Hostname(ip)
if err != nil {
return err
Expand Down Expand Up @@ -290,3 +304,11 @@ func (k *KubeadmRuntime) changeCRIVersion(ip string) error {
"systemctl restart kubelet",
)
}

func (k *KubeadmRuntime) changeKubeletExtraArgs(ip string) error {
return k.sshCmdAsync(ip,
`FILE="/etc/systemd/system/kubelet.service.d/10-kubeadm.conf" && [ -f "$FILE" ] && sed -i 's/\(--container-runtime=\|--pod-infra-container-image=\)\([^ ]*\)\?//g' "$FILE"`,
"systemctl daemon-reload",
"systemctl restart kubelet",
)
}

0 comments on commit b5a1ef6

Please sign in to comment.