<p>After upgrading Kubernetes to 1.25</p>
<p><code>helm upgrade --install ...</code> fails with the following error:</p>
<pre class="lang-bash prettyprint-override"><code>Error: UPGRADE FAILED: unable to recognize &quot;&quot;: no matches for kind &quot;HorizontalPodAutoscaler&quot; in version &quot;autoscaling/v2beta1&quot;
</code></pre>
<p>In order to resolve it I changed the HPA from <code>autoscaling/v2beta1</code> to <code>autoscaling/v2</code>
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?</p>

Maoz Zadok
<p>helm3 keeps the release state in secret, the last release helm state contains the old API <code>autoscaling/v2beta1</code>, and for some reason, it cause an error on the upgrade.
To resolve it, I edit the helm secret unpack the <code>.data.release</code> with base64 encode twice, and unzip replace  <code>autoscaling/v2beta1</code> with <code>autoscaling/v2</code> then zip it encode twice.</p>
<p>After this change and the change for the new API version (and syntax), the problem was solved, and I could upgrade the chart again.</p>
<p>My fix:</p>
<ul>
<li>Update the hpa template to the latest API version</li>
<li>Update (patch) the last helm secret (<code>secret/sh.helm.release.v1....</code>) with the following commands:</li>
</ul>
<pre class="lang-bash prettyprint-override"><code>UPDATE=$(kubectl get secret &quot;${SECRET}&quot; -n &quot;${NAMESPACE}&quot; -otemplate='{{.data.release |base64decode |base64decode }}'|gzip -d|sed 's#autoscaling/v2beta1#autoscaling/v2#'| gzip |base64 -w0 |base64 -w0)
kubectl patch secret &quot;${SECRET}&quot; -n &quot;${NAMESPACE}&quot; --patch=&quot;{\&quot;data\&quot;: { \&quot;release\&quot;: \&quot;$UPDATE\&quot; }}&quot;

</code></pre>
<p>I used this script for updating all helm secrets in all my namespaces.</p>
<pre><code>#!/bin/bash


SECRET=$1
NAMESPACE=$2

if [[ -z &quot;${SECRET}&quot; ]]
then
    echo &quot;Usage: $0 &lt;secret-name&gt; &lt;namespace&gt;&quot;
    exit
fi

if [[ -z &quot;${NAMESPACE}&quot; ]]
then
    echo &quot;Usage: $0 &lt;secret-name&gt; &lt;namespace&gt;&quot;
    exit
fi

UPDATE=$(kubectl get secret &quot;${SECRET}&quot; -n &quot;${NAMESPACE}&quot; -otemplate='{{.data.release |base64decode |base64decode }}'|gzip -d|sed 's#autoscaling/v2beta1#autoscaling/v2#'| gzip |base64 -w0 |base64 -w0)
kubectl patch secret &quot;${SECRET}&quot; -n &quot;${NAMESPACE}&quot; --patch=&quot;{\&quot;data\&quot;: { \&quot;release\&quot;: \&quot;$UPDATE\&quot; }}&quot;


# Running example:
## Fix single secret
# ./fix-helm-hpa.sh &lt;secret&gt; &lt;namespace&gt;

## Fix all secrets
#kubectl get secret --field-selector=type=helm.sh/release.v1 -otemplate='{{range .items}}{{printf &quot;%s %s\n&quot; .metadata.name .metadata.namespace }}{{end}}' |while read line ; do ./fix-helm-hpa.sh $line; done
</code></pre>
