<p>I run <code>kubent</code> and identify an outdated apiVersion</p>
<pre><code>&gt; kubent
...
KIND                  NAMESPACE                                                  NAME                                               API_VERSION      REPLACE_WITH (SINCE)
PodDisruptionBudget   mynamespace                                                mypdb                                              policy/v1beta1   policy/v1 (1.21.0)
</code></pre>
<p>I try to patch the resource in place but that doesn't seem to work:</p>
<pre><code>kubectl patch PodDisruptionBudget mypdb --namespace mynamespace -p'{&quot;apiVersion&quot;:&quot;policy/v1&quot;}'
poddisruptionbudget.policy/mypdb patched (no change)
</code></pre>
<p>Running <code>kubent</code> still shows it's outdated.</p>
<p>Why doesn't patch work for updating apiVersion? I need to do this for many resources in many namespaces I want to script it out.</p>
<p>Also, when I run <code>kubectl edit PodDisruptionBudget mypdb --namespace mynamespace</code> it shows the apiVersion is the updated one (&quot;policy/v1&quot;), but <code>kubent</code> still shows it as outdated (policy/v1beta1).</p>
<h2>Edit</h2>
<p>Per the suggested answer I did this, but it did not work. It applied without error, but running kubent again still shows the resources outdated:</p>
<pre><code>kubectl get PodDisruptionBudget \
        -A                      \
        -o yaml &gt; updated.yaml  \
        &amp;&amp; kubectl apply -f updated.yaml
</code></pre>
<h2>Edit 2</h2>
<p>Maybe kubent is not reporting the apiVersion correctly because after running apply if I run <code>kubectl get poddisruptionbudget.v1.policy -A</code> it returns the same resources <code>kubent</code> says are using outdated versions.</p>

red888
<p>Here is a solution for you.</p>
<pre class="lang-bash prettyprint-override"><code>kubent

### output:
(⎈ |minikube:default)[23:23:23] [~/repositories/KubernetesLabs] git(master) 🔥 ❱❱❱ kubent
11:23PM INF &gt;&gt;&gt; Kube No Trouble `kubent` &lt;&lt;&lt;
11:23PM INF version 0.5.1 (git sha a762ff3c6b5622650b86dc982652843cc2bd123c)
11:23PM INF Initializing collectors and retrieving data
11:23PM INF Target K8s version is 1.23.3
11:23PM INF Retrieved 52 resources from collector name=Cluster
11:23PM INF Retrieved 0 resources from collector name=&quot;Helm v2&quot;
11:23PM INF Retrieved 9 resources from collector name=&quot;Helm v3&quot;
11:23PM INF Loaded ruleset name=custom.rego.tmpl
11:23PM INF Loaded ruleset name=deprecated-1-16.rego
11:23PM INF Loaded ruleset name=deprecated-1-22.rego
11:23PM INF Loaded ruleset name=deprecated-1-25.rego
__________________________________________________________________________________________
&gt;&gt;&gt; Deprecated APIs removed in 1.25 &lt;&lt;&lt;
------------------------------------------------------------------------------------------
KIND                  NAMESPACE      NAME                   API_VERSION      REPLACE_WITH (SINCE)
PodDisruptionBudget   istio-system   istio-ingressgateway   policy/v1beta1   policy/v1 (1.21.0)
PodDisruptionBudget   istio-system   istiod                 policy/v1beta1   policy/v1 (1.21.0)
</code></pre>
<p><a href="https://i.stack.imgur.com/CBq5n.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/CBq5n.png" alt="enter image description here" /></a></p>
<hr />
<h1>How to update API?</h1>
<ul>
<li>The secret is this, when you &quot;get&quot; resource K8S will &quot;update&quot; the <code>apiVersion</code> and will display the correct one.</li>
<li>Then you can apply the &quot;update&quot; API back.</li>
<li>It will allow you to write script which does it for you as asked</li>
</ul>
<pre class="lang-bash prettyprint-override"><code># Get the list of outdated resources in a json format
kubent -o json &gt; outdated.json 

# Check the output
cat outdated.json 

# Grab the desired resource name(s) from the json and loop over them ==&gt; script
</code></pre>
<h3>Update script:</h3>
<ul>
<li>The content of the updated script will be:</li>
</ul>
<pre class="lang-bash prettyprint-override"><code># The content of your script will be 
# (loop over the list and run the following command):

 - Get the updated API using kubectl get
 - Save the updated content to file
 - apply the changes

kubectl get &lt;resourceType&gt; \
        &lt;resourceName&gt; \
        -n &lt;namespace&gt; \
        -o yaml &gt; newUpdatedApi.yaml \
        &amp;&amp; kubectl apply -f newUpdatedApi.yaml
</code></pre>
<h3>Demo:</h3>
<pre class="lang-bash prettyprint-override"><code>
# Print out the outdated resources
kubent 

# Get the updated apiVersion and save to file
# also apply the changes
kubectl get PodDisruptionBudget \
        istiod                  \
        -n istio-system         \
        -o yaml &gt; updated.yaml  \
        &amp;&amp; kubectl apply -f updated.yaml

# Check to verify that the updated.yaml indeed have the desired apiVersion
head -1 updated.yaml

# Verify that the &quot;patch&quot; is made
kubent
</code></pre>
<p><a href="https://i.stack.imgur.com/Hdq6Y.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/Hdq6Y.png" alt="enter image description here" /></a></p>
