<p>Considering other orchestration tools like <a href="https://github.com/dokku/dokku" rel="noreferrer">dokku</a>, dcos, deis, <a href="https://github.com/flynn/flynn" rel="noreferrer">flynn</a>, docker swarm, etc.. Kubernetes is no where near to them in terms of lines of code, on an average those tools are around 100k-200k lines of code.</p>

<p>Intuitively it feels strange that to manage containers i.e. to check health, scale containers up and down, kill them, restart them, etc.. doesn't have to consist of <em>2.4M+ lines of code</em> (which is the scale of an entire Operating System code base), I feel like there is something more to it.</p>

<p><strong>What is different in Kubernetes compared to other orchestration solutions that makes it so big?</strong></p>

<p>I dont have any knowledge of maintaining more than 5-6 servers. Please explain why it is so big, <em>what functionalities play big part in it</em>.</p>

<p><strong>First and foremost</strong>: don't be misled by the number of lines in the code, most of it are dependencies in the <code>vendor</code> folder that does not account for the core logic (<em>utilities, client libraries, gRPC, etcd,</em> etc.).</p>

<h2>Raw LoC Analysis with cloc</h2>

<p><em>To put things into perspective</em>, for <strong>Kubernetes</strong>:</p>

<pre><code>$ cloc kubernetes --exclude-dir=vendor,_vendor,build,examples,docs,Godeps,translations
    7072 text files.
    6728 unique files.                                          
    1710 files ignored.

github.com/AlDanial/cloc v 1.70  T=38.72 s (138.7 files/s, 39904.3 lines/s)
--------------------------------------------------------------------------------
Language                      files          blank        comment           code
--------------------------------------------------------------------------------
Go                             4485         115492         139041        1043546
JSON                             94              5              0         118729
HTML                              7            509              1          29358
Bourne Shell                    322           5887          10884          27492
YAML                            244            374            508          10434
JavaScript                       17           1550           2271           9910
Markdown                         75           1468              0           5111
Protocol Buffers                 43           2715           8933           4346
CSS                               3              0              5           1402
make                             45            346            868            976
Python                           11            202            305            958
Bourne Again Shell               13            127            213            655
sed                               6              5             41            152
XML                               3              0              0             88
Groovy                            1              2              0             16
--------------------------------------------------------------------------------
SUM:                           5369         128682         163070        1253173
--------------------------------------------------------------------------------
</code></pre>

<p>For <strong>Docker</strong> (and not Swarm or Swarm mode as this includes more features like volumes, networking, and plugins that are not included in these repositories). We do not include projects like <em>Machine</em>, <em>Compose</em>, <em>libnetwork</em>, so in reality the whole docker platform might include much more LoC:</p>

<pre><code>$ cloc docker --exclude-dir=vendor,_vendor,build,docs
    2165 text files.
    2144 unique files.                                          
     255 files ignored.

github.com/AlDanial/cloc v 1.70  T=8.96 s (213.8 files/s, 30254.0 lines/s)
-----------------------------------------------------------------------------------
Language                         files          blank        comment           code
-----------------------------------------------------------------------------------
Go                                1618          33538          21691         178383
Markdown                           148           3167              0          11265
YAML                                 6            216            117           7851
Bourne Again Shell                  66            838            611           5702
Bourne Shell                        46            768            612           3795
JSON                                10             24              0           1347
PowerShell                           2             87            120            292
make                                 4             60             22            183
C                                    8             27             12            179
Windows Resource File                3             10              3             32
Windows Message File                 1              7              0             32
vim script                           2              9              5             18
Assembly                             1              0              0              7
-----------------------------------------------------------------------------------
SUM:                              1915          38751          23193         209086
-----------------------------------------------------------------------------------
</code></pre>

<blockquote>
  <p>Please note that these are very raw estimations, using <strong>cloc</strong>. This might be worth a deeper analysis.</p>
</blockquote>

<p>Roughly, it seems like the project accounts for half of the LoC (<strong>~1250K LoC</strong>) mentioned in the question (whether you value dependencies or not, which is subjective).</p>

<h2>What is included in Kubernetes that makes it so big?</h2>

<p>Most of the <em>bloat</em> comes from libraries supporting various Cloud providers to ease the bootstrapping on their platform or to support specific features (volumes, etc.) through plugins. It also has a <strong>Lot</strong> of <a href="https://github.com/kubernetes/kubernetes/tree/master/examples" rel="noreferrer">Examples</a> to dismiss from the line count. A fair LoC estimation needs to exclude a lot of unnecessary documentation and example directories.</p>

<p>It is also <strong>much more feature rich</strong> compared to <em>Docker Swarm</em>, <em>Nomad</em> or <em>Dokku</em> to cite a few. It supports advanced networking scenarios, has load balancing built-in, includes <a href="https://kubernetes.io/docs/user-guide/petset/" rel="noreferrer">PetSets</a>, <a href="https://github.com/kubernetes/kubernetes/tree/master/federation" rel="noreferrer">Cluster Federation</a>, volume plugins or other features that other projects do not support yet.</p>

<p>It supports <strong>multiple container engines</strong>, so it is not exclusively running docker containers but could possibly run other engines (such as <strong>rkt</strong>).</p>

<p>A lot of the core logic involves interaction with other components: Key-Value stores, client libraries, plugins, etc. which extends far beyond simple scenarios.</p>

<p><em>Distributed Systems are notoriously hard</em>, and <em>Kubernetes</em> seems to support a majority of the tooling from key players in the container industry without compromise (where other solutions are making such compromise). As a result, the project can look artificially <strong>bloated</strong> and too big for its core mission (deploying containers at scale). In reality, these statistics are not that surprising.</p>

<h2>Key idea</h2>

<p>Comparing <em>Kubernetes</em> to <em>Docker</em> or <em>Dokku</em> is not really appropriate. The scope of the project is far bigger and it includes much more features as it is not limited to the Docker family of tooling.</p>

<p>While Docker has a lot of its features scattered across multiple libraries, Kubernetes tends to have everything under its core repository (which inflates the line count substantially but also explains the popularity of the project).</p>

<p>Considering this, the LoC statistic is not that surprising.</p>
