<p>One of the documented best practices for Kubernetes is to store the configuration in version control. It is mentioned in <a href="https://kubernetes.io/docs/concepts/configuration/overview/#general-configuration-tips" rel="nofollow noreferrer">the official best practices</a> and also summed up in <a href="https://stackoverflow.com/questions/47168381/best-practices-for-storing-kubernetes-configuration-in-source-control">this</a> Stack Overflow question. The reason is that this is supposed to speed-up rollbacks if necessary. </p>

<p>My question is, why do we need to store this configuration if this is already stored by Kubernetes and there are ways with which we can easily <a href="https://kubernetes.io/docs/concepts/workloads/controllers/deployment/#checking-rollout-history-of-a-deployment" rel="nofollow noreferrer">go back to a previous version of the configuration using for example kubectl</a>? An example is a command like:</p>

<pre><code>kubectl rollout history deployment/nginx-deployment
</code></pre>

<p>Isn't storing the configuration an unnecessary duplication of a piece of information that we will then have to keep synchronized? </p>

<p>The reason I am asking this is that we are building a configuration service on top of Kubernetes. The user will interact with it to configure multiple deployments, I was wondering if we should keep a history of the Kubernetes configuration and the content of configMaps in a database for possible roll backs or if we should just rely on kubernetes to retrieve the current configuration and rolling back to previous versions of the configuration.</p>

<p>You <em>can</em> use Kubernetes as your store of configuration, to your point, it's just that you probably shouldn't want to. By storing configuration as code, you get several benefits:</p>

<ul>
<li>Configuration changes get regular code reviews.</li>
<li>They get versioned, are diffable, etc.</li>
<li>They can be tested, linted, and whatever else you desired.</li>
<li>They can be refactored, share code, and be documented.</li>
<li>And all this happens <em>before</em> actually being pushed to Kubernetes.</li>
</ul>

<p>That may seem bad ("but then my configuration is out of date!"), but keep in mind that configuration is actually never in date - just because you told Kubernetes you want 3 replicas running doesn't mean there are, or if there were that 1 isn't temporarily down right now, and so on.</p>

<p>Configuration expresses <strong>intent</strong>. It takes a different process to actually notice when your intent changes or doesn't match reality, and make it so. For Kubernetes, that storage is etcd and it's up to the master to, in a loop forever, ensure the stored intent matches reality. For you, the storage is source control and whatever process you want, automated or not, can, in a loop forever, ensure your code eventually becomes reflected in Kubernetes.</p>

<p>The rollback command, then, is just a very fast shortcut to "please do this <em>right now</em>!". It's for when your configuration intent was wrong and you don't have time to fix it. As soon as you roll back, you should chase your configuration and update it there as well. In a sense, this is indeed duplication, but it's a rare event compared to the normal flow, and the overall benefits outweigh this downside.</p>
