<p>I tried to find useful information when should i use <code>--record</code>. I created 3 commands:</p>
<ul>
<li><code>k set image deployment web1 nginx=lfccncf/nginx:latest --record</code></li>
<li><code>k rollout undo deployment/web1  --record</code></li>
<li><code>k -n kdpd00202 edit deployment web1 --record</code></li>
</ul>
<p>Could anyone tell me if I need to use <code>--record</code> in each of these 3 commands?</p>
<p>When is it necessary to use <code>--record</code> and when is it useless?</p>

<p>Kubernetes desired state can be updated/mutated thru two paradigms :</p>
<ol>
<li>Either <strong>imperatively</strong> using kubectl adhoc commands ( <code>k set</code>, <code>k create</code>, <code>k run</code>, <code>k rollout</code> ,..)</li>
<li>Or <strong>declaratively</strong> using YAML manifests with a single <code>k apply</code></li>
</ol>
<p>The declarative way is ideal for treating your k8s manifests as Code, then you can share this Code with the team, version it thru Git for example, and keep tracking its history leveraging GitOps practices ( branching models, Code Review, CI/CD ).</p>
<p>However, the imperative way cannot be reviewed by the team as these adhoc-commands will be run by an individual and no one else can easily find out the <strong>cause of the change</strong> after the change has been made.</p>
<p>To overcome the absence of an audit trail with imperative commands, the <code>--record</code> option is there to bind the root cause of the change as annotation called <code>kubernetes.io/change-cause</code> and the value of this annotation is the imperative command itself.</p>
<p>(note below is from the <a href="https://kubernetes.io/docs/concepts/workloads/controllers/deployment/" rel="noreferrer">official doc</a>)</p>
<blockquote>
<p>Note: You can specify the --record flag to write the command executed in the resource annotation kubernetes.io/change-cause. The recorded change is useful for future introspection. For example, to see the commands executed in each Deployment revision.</p>
</blockquote>
<p>As conclusion :</p>
<ul>
<li>Theoretically ,<code>--record</code> is not mandatory</li>
<li>Practically, it's mandatory in order to ensure the changes leave a rudimentary audit trail behind and comply with SRE process and DevOps culture.</li>
</ul>
