<p>I would like to control the number of revision in the resultset of this command in my k8s cluster:</p>
<pre><code>kubectl rollout history deployment.v1.apps/&lt;&lt;my_deployment&gt;&gt;
</code></pre>
<p>Here it is what I have:</p>
<pre><code> REVISION  CHANGE-CAUSE
10        set app version to 1.1.10
11        set app version to 1.1.11
12        set app version to 1.1.12
13        set app version to 1.1.13
14        set app version to 1.1.14
15        set app version to 1.1.15
16        set app version to 1.1.16
17        set app version to 1.1.17
18        set app version to 1.1.18
19        set app version to 1.1.19
20        set app version to 1.1.20
21        set app version to 1.1.21
</code></pre>
<p>I would like to have only:</p>
<pre><code>21        set app version to 1.1.21
</code></pre>
<p>Is there a magical command like:</p>
<pre><code>kubectl rollout history clean deployment.v1.apps/&lt;&lt;my_deployment&gt;&gt;
</code></pre>

Sylvain Martin
<p>Yes, as per <a href="https://kubernetes.io/docs/concepts/workloads/controllers/deployment/#clean-up-policy" rel="nofollow noreferrer">the documentation</a>, it can be done by setting <code>.spec.revisionHistoryLimit</code> in your <code>Deployment</code> to <code>0</code>:</p>
<blockquote>
<h2>Clean up Policy<a href="https://kubernetes.io/docs/concepts/workloads/controllers/deployment/#clean-up-policy" rel="nofollow noreferrer"></a></h2>
<p>You can set  <code>.spec.revisionHistoryLimit</code>  field in a Deployment to
specify how many old ReplicaSets for this Deployment you want to
retain. The rest will be garbage-collected in the background. By
default, it is 10.</p>
<blockquote>
<p><strong>Note:</strong>  Explicitly setting this field to 0, will result in cleaning up all the history of your Deployment thus that Deployment
will not be able to roll back.</p>
</blockquote>
</blockquote>
<p>The easiest way to do it is by <a href="https://kubernetes.io/docs/tasks/manage-kubernetes-objects/update-api-object-kubectl-patch/" rel="nofollow noreferrer">patching</a> your <code>Deployment</code>. It can be done by executing the following command:</p>
<pre><code>kubectl patch deployment nginx-deployment --type json -p '[{ &quot;op&quot;: &quot;replace&quot;, &quot;path&quot;: &quot;/spec/revisionHistoryLimit&quot;,&quot;value&quot;: 0}]'
</code></pre>
<p>Then you can set it back to the previous value:</p>
<pre><code>kubectl patch deployment nginx-deployment --type json -p '[{ &quot;op&quot;: &quot;replace&quot;, &quot;path&quot;: &quot;/spec/revisionHistoryLimit&quot;,&quot;value&quot;: 10}]'
</code></pre>
<h3>UPDATE:</h3>
<blockquote>
<p>Thx, I have already try this. The history revision table is still
present. The only way I have found is to delete the deployment
configuration. – Sunitrams 20 mins ago</p>
</blockquote>
<p>Are you sure you did it the same way ? 🤔 Take a quick look and see how it works in my case:</p>
<pre><code>$ kubectl rollout history deployment nginx-deployment
deployment.apps/nginx-deployment
REVISION  CHANGE-CAUSE
1         &lt;none&gt;
2         &lt;none&gt;
3         &lt;none&gt;
4         &lt;none&gt;
</code></pre>
<p>After running:</p>
<pre><code>$ kubectl patch deployment nginx-deployment --type json -p '[{ &quot;op&quot;: &quot;replace&quot;, &quot;path&quot;: &quot;/spec/revisionHistoryLimit&quot;,&quot;value&quot;: 0}]'
deployment.apps/nginx-deployment patched
</code></pre>
<p>the revision history is reduced to the latest one:</p>
<pre><code>$ kubectl rollout history deployment nginx-deployment 
deployment.apps/nginx-deployment
REVISION  CHANGE-CAUSE
4         &lt;none&gt;
</code></pre>
<p>When I set <code>.spec.revisionHistoryLimit</code> back to 10:</p>
<pre><code>$ kubectl patch deployment nginx-deployment --type json -p '[{ &quot;op&quot;: &quot;replace&quot;, &quot;path&quot;: &quot;/spec/revisionHistoryLimit&quot;,&quot;value&quot;: 10}]'
deployment.apps/nginx-deployment patched
</code></pre>
<p>there is still only latest revision:</p>
<pre><code>$ kubectl rollout history deployment nginx-deployment 
deployment.apps/nginx-deployment
REVISION  CHANGE-CAUSE
4         &lt;none&gt;
</code></pre>
