Why should I store kubernetes deployment configuration into source control if kubernetes already keeps track of it?

4/27/2018

One of the documented best practices for Kubernetes is to store the configuration in version control. It is mentioned in the official best practices and also summed up in this Stack Overflow question. The reason is that this is supposed to speed-up rollbacks if necessary.

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 go back to a previous version of the configuration using for example kubectl? An example is a command like:

kubectl rollout history deployment/nginx-deployment

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

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.

-- Perennialista
kubernetes

2 Answers

5/1/2018

You can 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:

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

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.

Configuration expresses intent. 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.

The rollback command, then, is just a very fast shortcut to "please do this right now!". 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.

-- GManNickG
Source: StackOverflow

12/11/2018

Kubernetes cluster doesn't store your configuration it runs it, as you server runs your application code.

-- WHITECOLOR
Source: StackOverflow