【Azure K8S】AKS升级 Kubernetes version 失败问题的分析与解决

AKS,问题,分析,升级 · 浏览次数 : 103

小编点评

## Solution to Upgrade AKS Cluster Kubernetes Version This document outlines the steps to resolve the "Failed to save Kubernetes service" error while upgrading the Kubernetes version on your AKS cluster. **Root Cause:** The upgrade failed because the PDB (Pod Disruption Budget) strategy is blocking the update due to insufficient available pods. **Solutions:** **1. Modify PDB Settings:** * Use `kubectl get pdb` to retrieve the current PDB configuration. * Update the `MIN AVAILABLE` and `ALLOWED DISRUPTION` values to a higher value, such as 100 or 200. * This will allow the upgrade to proceed, but it's important to understand the implications and potential impact on your cluster. **2. Remove PDB and Re-create:** * Save the current PDB configuration to a file named `pdb.yaml` using `kubectl get pdb -A`. * Remove the PDB object using `kubectl delete pdb --namespace `. * Execute the upgrade with the new PDB settings using `kubectl apply -f pdb.yaml --namespace `. **3. Use NodePool Upgrade:** * Stop any running pods on the cluster. * Use `az aks nodepool upgrade` to upgrade the node pool. * Provide the following parameters: * `group name`: The name of the cluster group. * `cluster name`: The name of the cluster. * `node name`: The name of the node. * `kubernetes version`: The desired Kubernetes version to upgrade to. * `no-wait`: Disables the wait for the upgrade to finish. **4. Restore PDB:** * After the upgrade, restore the saved PDB configuration using `kubectl apply -f pdb.yaml --namespace `. **Additional Resources:** * **Specifying a Disruption Budget for your Application:** * Kubernetes documentation: `kubectl docs tasks run application configure pdb` * **PodDrainFailure error code:** * Learn how to troubleshoot the `PodDrainFailure` error: * Kubernetes documentation: `kubectl docs troubleshoot poddrainfailure` * **Recovering PDB:** * Kubernetes documentation: `kubectl docs apply -f pdb.yaml --namespace `

正文

问题描述

创建Azure Kubernetes Service服务后,需要升级AKS集群的 kubernetes version。在AKS页面的 Cluster configuration 页面中,选择新的版本 1.25.5,确认升级。等待50分钟左右,却等到了升级失败的消息:

Failed to save Kubernetes service 'xxxx-aks3'. Error: Drain of aks-agentpool-xxxxxxxx-vmss00000j did not complete: Too many req pod aks-helloworld-one-9df87f7df-zxnbq on node aks-agentpool-xxxxxxxx-vmss00000j: ingress-basic/aks-helloworld-one-9df87f7df-zxnbq blocked by pdb pdbforhelloworldone with unready pods []. See  http://aka.ms/aks/debugdrainfailures

 

问题解答

查看错误消息,其中提到 “... blocked by pdb pdbforhelloworldone with unready pods ... ” ,所以需要检查AKS集群中PDB(Pod Disruption Budget:Pod中断预算 --  https://kubernetes.io/docs/tasks/run-application/configure-pdb/#create-the-pdb-object). 

 

第一步:查看AKS集群中的事件,检查错误内容

使用指令:kubectl get event , 得到错误信息 :Eviction blocked by too many Requests ( usually a pdb)

 

第二步:查看AKS集群中PDB的配置信息

使用指令  kubectl get pdb -A , 查看到其中一个配置为 MIN AVAILABLE : 100%, ALLOWED DISRUPTIONS: 0

MIN AVAILABLE 为 100%, 说明POD都需要处于活跃状态,不能中断。

ALLOWED DISRUPTIONS为0,也表明POD可以中断的数量为0,即全部的POD都不能中断。

所以,升级失败的根源就是PDB策略的阻挡,升级的时候POD需要中断替换,而PDB策略不允许有POD中断,所以无法完成升级。

 

解决方案:

方案一:修改PDB设置,根据情况改变MIN AVAILABLE和ALLOWED DISRUPITIONS的值。

方案二:(当不能修改PDB设置时),可以先把PDB保存到本地,然后删除它,在执行升级,当升级完成后,恢复PDB设置即可。

第一种方式很简单,修改POD YAML中的配置即可。而本文中主要使用的是第二种方式:

 

1)保存PDB配置到本地(如pdb.yaml)

使用命令:kubectl get pdb <the block pdb name> -o yaml --namespace <the pdb namespace> 

然后把输出的内容复制到文件 pdb.yaml 中

 

2)删除阻挡升级操作的PDB设置

使用命令删除pdb:kubectl delete pdb <your pdb name> --namespace <right namespace>

 

 

3)执行升级操作

因为在门户上,先前的升级操作报错,锁定了页面上的升级操作(即无法继续在页面中执行升级), 并且ASK 控制层面(Control panel)的版本升级已经完成,只是Node的升级是失败的。所以可以通过az aks nodepool upgrade 指令,执行对NodePool的升级。

az aks nodepool upgrade -g <group name> --cluster-name <name> --name <node name> --kubernetes-version 1.25.5 --no-wait

 

升级过程中,节点由2个 变为 3个,然后节点的kubernetes Version也在改变中

 

升级完成后, 节点数恢复为2,kubernetes Version都变为新的 1.25.5 

完成此步后,整个AKS集群的升级表示完成,下一步就是根据第一步保存的pdb.yaml,重新创建PDB

4)恢复原有的PDB设置

使用指令

kubectl apply -f pdb.yaml --namespace <the pdb namespace>

kubectl get pdb -A

 

 


参考资料

Specifying a Disruption Budget for your Application :  https://kubernetes.io/docs/tasks/run-application/configure-pdb/#create-the-pdb-object

排查“PodDrainFailure”错误代码 :  https://learn.microsoft.com/zh-cn/troubleshoot/azure/azure-kubernetes/error-code-poddrainfailure

 

与【Azure K8S】AKS升级 Kubernetes version 失败问题的分析与解决相似的内容:

【Azure K8S】AKS升级 Kubernetes version 失败问题的分析与解决

问题描述 创建Azure Kubernetes Service服务后,需要升级AKS集群的 kubernetes version。在AKS页面的 Cluster configuration 页面中,选择新的版本 1.25.5,确认升级。等待50分钟左右,却等到了升级失败的消息: Failed to

【Azure K8S | AKS】在中国区AKS上遇见ImagePullBackOff时的替代方案

Failed to pull image "k8s.gcr.io/cluster-proportional-autoscaler-amd64:1.1.2-r2": rpc error: code = Unknown desc = Error response from daemon: Get https://k8s.gcr.io/v2/: net/http: request canceled wh

【Azure K8S | AKS】在不丢失文件/不影响POD运行的情况下增加PVC的大小

问题描述 在前两篇文章中,创建了Disk + PV + PVC + POD 方案后,并且进入POD中增加文件。 【Azure K8S | AKS】在AKS集群中创建 PVC(PersistentVolumeClaim)和 PV(PersistentVolume) 示例 【Azure K8S|AKS】

【Azure K8S | AKS】分享从AKS集群的Node中查看日志的方法(/var/log)

问题描述 使用Azure Kubernetes服务(AKS),可以通过kubectl连接 pod 中查看日志,但是如何来查看节点的系统日志呢?如是否有ubuntu系统升级的记录? 问题解答 是的,可以进入AKS的节点查看系统文件,如日志文件(/var/log) 或者由应用生产的其他日志。 具体的操作

【Azure K8S】记录AKS VMSS实例日志收集方式

问题描述 如何从AKS的VMSS集群中收集实例日志? 参考步骤 第一步:登陆VMSS实例 参考官网步骤:使用 SSH 连接到 Azure Kubernetes 服务 (AKS) 群集节点以进行维护或故障排除: https://docs.azure.cn/zh-cn/aks/ssh#configure

【Azure K8S | AKS】在AKS集群中创建 PVC(PersistentVolumeClaim)和 PV(PersistentVolume) 示例

问题描述 在AKS集群中创建 PVC(PersistentVolumeClaim)和 PV(PersistentVolume) 示例 问题解答 在Azure Kubernetes Service(AKS)的官方网站中,关于存储的选项介绍中,并没有具体的yaml实例来创建PV, PVC。特别是使用自定

【Azure K8S | AKS】在AKS中创建 StatefulSet 示例

问题描述 【Azure K8S | AKS】在AKS集群中创建 PVC(PersistentVolumeClaim)和 PV(PersistentVolume) 示例 【Azure K8S|AKS】进入AKS的POD中查看文件,例如PVC Volume Mounts使用情况 【Azure K8S |

【Azure K8S】演示修复因AKS密钥过期而导致创建服务不成功的问题(The provided client secret keys for app ****** are expired)

问题描述 在Azure Kubernetes 服务中,创建一个Internal Load Balancer服务,使用以下yaml内容: internallb.yaml apiVersion: v1 kind: Service metadata: name: ilb-myapp annotations

【Azure APIM】APIM self-host 部署在K8S中,如何更换证书呢?

问题描述 APIM self-host(自建网关)部署在K8S中,如何在本地上传及更换证书呢? 问题解答 如果使用Self-host网关,则不支持使用上传到 APIM的 CA 根证书验证服务器和客户端证书。 若要建立信任,请配置特定的客户端证书,使其被网关作为一个自定义的证书颁发机构所信任,使用网关

【Azure App Service】.NET代码实验App Service应用中获取TLS/SSL 证书 (App Service Linux/Linux Container)

在前一篇文章中,我们是把.NET 8应用读取SSL证书(X509)示例部署在App Service Windows环境中,那么如果部署在Linux环境,以及Linux Container中呢? 根据前文中的第一种方法,直接在把证书文件包含在源文件中,通过相对路径读取证书文件的方式,经测试,可以正常工