<p>I am trying to update a deployment via the YAML file, similar to <a href="https://stackoverflow.com/questions/48191853/how-to-update-a-deployment-via-editing-yml-file">this question</a>. I have the following yaml file...</p>
<pre><code>apiVersion: apps/v1
kind: Deployment
metadata: 
  name: simple-server-deployment
  labels:
    app: simple-server
spec: 
  replicas: 3
  selector: 
    matchLabels:
      app: simple-server
  template:
    metadata:
      labels:
        app: simple-server
    spec:
      containers:
      - name: simple-server
        image: nginx
        ports:
        - name: http
          containerPort: 80
</code></pre>
<p>I tried changing the code by changing <code>replicas: 3</code> to <code>replicas: 1</code>. Next I redeployed like <code>kubectl apply -f simple-deployment.yml</code> and I get <code>deployment.apps/simple-server-deployment configured</code>. However, when I run <code>kubectl rollout history deployment/simple-server-deployment</code> I only see 1 entry...</p>
<pre><code>REVISION  CHANGE-CAUSE
1         &lt;none&gt;
</code></pre>
<p>How do I do the same thing while increasing the revision so it is possible to rollback?</p>
<p><em>I know this can be done without the YAML but this is just an example case. In the real world I will have far more changes and need to use the YAML.</em></p>

Jackie
<p>You can use <a href="https://stackoverflow.com/questions/61875309/what-does-record-do-in-kubernetes-deployment"><code>--record</code> flag</a> so in your case the command will look like:</p>
<pre><code>kubectl apply -f simple-deployment.yml --record
</code></pre>
<p>However, a few notes.</p>
<p>First, <a href="https://github.com/kubernetes/kubernetes/issues/40422" rel="nofollow noreferrer"> <code>--record</code> flag is deprecated</a> - you will see following message when you will run <code>kubectl apply</code> with the <code>--record</code> flag:</p>
<pre><code>Flag --record has been deprecated, --record will be removed in the future
</code></pre>
<p>However, <a href="https://github.com/kubernetes/kubernetes/issues/40422#issuecomment-995371023" rel="nofollow noreferrer">there is no replacement for this flag yet</a>, but keep in mind that in the future there probably will be.</p>
<p>Second thing, not every change will be recorded (even with <code>--record</code> flag) - I tested your example from the main question and there is no new revision. Why? <a href="https://github.com/kubernetes/kubernetes/issues/23989#issuecomment-207226153" rel="nofollow noreferrer">It's because:</a>:</p>
<blockquote>
<p><a href="https://github.com/deech" rel="nofollow noreferrer">@deech</a> this is expected behavior. The <code>Deployment</code> only create a new revision (i.e. another <code>Replica Set</code>) when you update its pod template. Scaling it won't create another revision.</p>
</blockquote>
<p>Considering the two above, you need to think (and probably test) if the <code>--record</code> flag is suitable for you. Maybe it's better to use some <a href="https://en.wikipedia.org/wiki/Version_control" rel="nofollow noreferrer">version control system</a> like <a href="https://git-scm.com/" rel="nofollow noreferrer">git</a>, but as I said, it depends on your requirements.</p>
