英文:
helm upgrade fail after upgrade to Kubernetes 1.25 due to change in HorizontalPodAutoscaler API version
问题
升级 Kubernetes 到 1.25 后,
helm upgrade --install ...
失败,显示以下错误:
Error: UPGRADE FAILED: unable to recognize "": no matches for kind "HorizontalPodAutoscaler" in version "autoscaling/v2beta1"
为了解决这个问题,我将 HPA 从 autoscaling/v2beta1
更改为 autoscaling/v2
并更新了新的 API 语法,但在尝试升级 Helm 发布时仍然遇到相同的错误。唯一的解决方法是卸载并重新安装发布。有人能解释错误的原因以及如何在不删除和重新安装的情况下修复它吗?
英文:
After upgrading Kubernetes to 1.25
helm upgrade --install ...
fails with the following error:
Error: UPGRADE FAILED: unable to recognize "": no matches for kind "HorizontalPodAutoscaler" in version "autoscaling/v2beta1"
In order to resolve it I changed the HPA from autoscaling/v2beta1
to autoscaling/v2
and update the new API syntax. but I keep getting the same error when trying to upgrade the helm release.
The only way to resolve it was to uninstall and reinstall the release.
can someone explain the reason for the error and how to fix it without deleting and reinstall it?
答案1
得分: 5
helm3将发布状态保存在密钥中,上次发布的helm状态包含了旧的API autoscaling/v2beta1
,由于某种原因,在升级时引发了错误。
为了解决这个问题,我编辑了helm密钥,对 .data.release
使用了两次base64编码解压缩,然后用 autoscaling/v2
替换了 autoscaling/v2beta1
,然后再次进行编码和压缩。
在进行这些更改和新API版本(以及语法)的更改后,问题得以解决,我可以再次升级图表。
我的修复步骤:
- 更新hpa模板至最新API版本
- 使用以下命令更新(修补)上次的helm密钥(
secret/sh.helm.release.v1....
):
UPDATE=$(kubectl get secret "${SECRET}" -n "${NAMESPACE}" -otemplate='{{.data.release |base64decode |base64decode }}'|gzip -d|sed 's#autoscaling/v2beta1#autoscaling/v2#' | gzip | base64 -w0 | base64 -w0)
kubectl patch secret "${SECRET}" -n "${NAMESPACE}" --patch="{"data": { "release": "$UPDATE" }}"
我使用这个脚本来更新所有命名空间中的所有helm密钥。
#!/bin/bash
SECRET=$1
NAMESPACE=$2
if [[ -z "${SECRET}" ]]
then
echo "Usage: $0 <secret-name> <namespace>"
exit
fi
if [[ -z "${NAMESPACE}" ]]
then
echo "Usage: $0 <secret-name> <namespace>"
exit
fi
UPDATE=$(kubectl get secret "${SECRET}" -n "${NAMESPACE}" -otemplate='{{.data.release |base64decode |base64decode }}'|gzip -d|sed 's#autoscaling/v2beta1#autoscaling/v2#' | gzip | base64 -w0 | base64 -w0)
kubectl patch secret "${SECRET}" -n "${NAMESPACE}" --patch="{"data": { "release": "$UPDATE" }}"
# 运行示例:
## 修复单个密钥
# ./fix-helm-hpa.sh <secret> <namespace>
## 修复所有密钥
#kubectl get secret --field-selector=type=helm.sh/release.v1 -otemplate='{{range .items}}{{printf "%s %s\n" .metadata.name .metadata.namespace }}{{end}}' | while read line ; do ./fix-helm-hpa.sh $line; done
请注意,这只是代码的一部分,我已经为您提供了翻译。如果需要进一步的帮助,请随时提问。
英文:
helm3 keeps the release state in secret, the last release helm state contains the old API autoscaling/v2beta1
, and for some reason, it cause an error on the upgrade.
To resolve it, I edit the helm secret unpack the .data.release
with base64 encode twice, and unzip replace autoscaling/v2beta1
with autoscaling/v2
then zip it encode twice.
After this change and the change for the new API version (and syntax), the problem was solved, and I could upgrade the chart again.
My fix:
- Update the hpa template to the latest API version
- Update (patch) the last helm secret (
secret/sh.helm.release.v1....
) with the following commands:
UPDATE=$(kubectl get secret "${SECRET}" -n "${NAMESPACE}" -otemplate='{{.data.release |base64decode |base64decode }}'|gzip -d|sed 's#autoscaling/v2beta1#autoscaling/v2#'| gzip |base64 -w0 |base64 -w0)
kubectl patch secret "${SECRET}" -n "${NAMESPACE}" --patch="{\"data\": { \"release\": \"$UPDATE\" }}"
I used this script for updating all helm secrets in all my namespaces.
#!/bin/bash
SECRET=$1
NAMESPACE=$2
if [[ -z "${SECRET}" ]]
then
echo "Usage: $0 <secret-name> <namespace>"
exit
fi
if [[ -z "${NAMESPACE}" ]]
then
echo "Usage: $0 <secret-name> <namespace>"
exit
fi
UPDATE=$(kubectl get secret "${SECRET}" -n "${NAMESPACE}" -otemplate='{{.data.release |base64decode |base64decode }}'|gzip -d|sed 's#autoscaling/v2beta1#autoscaling/v2#'| gzip |base64 -w0 |base64 -w0)
kubectl patch secret "${SECRET}" -n "${NAMESPACE}" --patch="{\"data\": { \"release\": \"$UPDATE\" }}"
# Running example:
## Fix single secret
# ./fix-helm-hpa.sh <secret> <namespace>
## Fix all secrets
#kubectl get secret --field-selector=type=helm.sh/release.v1 -otemplate='{{range .items}}{{printf "%s %s\n" .metadata.name .metadata.namespace }}{{end}}' |while read line ; do ./fix-helm-hpa.sh $line; done
答案2
得分: 1
Helm还在Kubernetes API在helm图表升级之前被移除时提供了一些文档。它遵循与Maoz的答案相同的流程。
https://helm.sh/docs/topics/kubernetes_apis/
获取发布密钥,解码blob,更新有问题的API版本,重新编码密钥,然后应用生成的yaml文件。
我花了大约一个小时才找到这篇帖子!
英文:
Helm also has some documentation when an Kubernetes API is removed before a helm chart is upgraded. It follows the same procedure as Maoz's answer
https://helm.sh/docs/topics/kubernetes_apis/
Grab the release secret, decode the blob, update the offending API version, re-encode the secret, and apply the resulting yaml file.
It took me about an hour to find this post!
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论