

【Azure K8S】AKS升级 Kubernetes version 失败问题的分析与解决 - 路边两盏灯
source link: https://www.cnblogs.com/lulight/p/17461532.html
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

【Azure K8S】AKS升级 Kubernetes version 失败问题的分析与解决
创建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
Recommend
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK