<p>Our application consists of circa 20 modules. Each module contains a (Helm) chart with several deployments, services and jobs. Some of those jobs are defined as Helm pre-install and pre-upgrade hooks. Altogether there are probably about 120 yaml files, which eventualy result in about 50 running pods.</p>

<p>During development we are running Docker for Windows version 2.0.0.0-beta-1-win75 with Docker 18.09.0-ce-beta1 and Kubernetes 1.10.3. To simplify management of our Kubernetes yaml files we use Helm 2.11.0. Docker for Windows is configured to use 2 CPU cores (of 4) and 8GB RAM (of 24GB).</p>

<p><strong>When creating the application environment for the first time, it takes more that 20 minutes to become available. This seems far to slow; we are probably making an important mistake somewhere. We have tried to improve the (re)start time, but to no avail. Any help or insights to improve the situation would be greatly appreciated.</strong></p>

<p>A simplified version of our startup script:</p>

<pre><code>#!/bin/bash

# Start some infrastructure
helm upgrade --force --install modules/infrastructure/chart

# Start ~20 modules in parallel
helm upgrade --force --install modules/module01/chart &amp;
[...]
helm upgrade --force --install modules/module20/chart &amp;

await_modules()
</code></pre>

<p>Executing the same startup script again later to 'restart' the application still takes about 5 minutes. As far as I know, unchanged objects are not modified at all by Kubernetes. Only the circa 40 hooks are run by Helm.</p>

<p>Running a single hook manually with <code>docker run</code> is fast (~3 seconds). Running that same hook through Helm and Kubernetes regularly takes 15 seconds or more.</p>

<p>Some things we have discovered and tried are listed below.</p>

<h3>Linux staging environment</h3>

<p>Our staging environment consists of Ubuntu with native Docker. Kubernetes is installed through minikube with <code>--vm-driver none</code>.</p>

<p>Contrary to our local development environment, the staging environment retrieves the application code through a (deprecated) <code>gitRepo</code> volume for almost every deployment and job. Understandibly, this only seems to worsen the problem. Starting the environment for the first time takes over 25 minutes, restarting it takes about 20 minutes.</p>

<p>We tried replacing the <code>gitRepo</code> volume with a sidecar container that retrieves the application code as a TAR. Although we have not modified the whole application, initial tests indicate this is not particularly faster than the <code>gitRepo</code> volume.</p>

<p>This situation can probably be improved with an alternative type of volume that enables sharing of code between deployements and jobs. We would rather not introduce more complexity, though, so we have not explored this avenue any further. </p>

<h3>Docker run time</h3>

<p>Executing a single empty alpine container through <code>docker run alpine echo "test"</code> takes roughly 2 seconds. This seems to be overhead of the setup on Windows. That same command takes less 0.5 seconds on our Linux staging environment.</p>

<h3>Docker volume sharing</h3>

<p>Most of the containers - including the hooks - share code with the host through a <code>hostPath</code>. The command <code>docker run -v &lt;host path&gt;:&lt;container path&gt; alpine echo "test"</code> takes 3 seconds to run. Using volumes seems to increase runtime with aproximately 1 second.</p>

<h3>Parallel or sequential</h3>

<p>Sequential execution of the commands in the startup script does not improve startup time. Neither does it drastically worsen.</p>

<h3>IO bound?</h3>

<p>Windows taskmanager indicates that IO is at 100% when executing the startup script. Our hooks and application code are not IO intensive at all. So the IO load seems to originate from Docker, Kubernetes or Helm. We have tried to find the bottleneck, but were unable to pinpoint the cause.</p>

<h3>Reducing IO through ramdisk</h3>

<p>To test the premise of being IO bound further, we exchanged <code>/var/lib/docker</code> with a ramdisk in our Linux staging environment. Starting the application with this configuration was not significantly faster.</p>

<p>To compare Kubernetes with Docker, you need to consider that Kubernetes will run more or less the same Docker command on a final step. Before that happens many things are happening.
The authentication and authorization processes, creating objects in etcd, locating correct nodes for pods scheduling them and provisioning storage and many more.
Helm itself also adds an overhead to the process depending on size of chart.</p>

<p>I recommend reading <a href="https://techbeacon.com/one-year-using-kubernetes-production-lessons-learned" rel="nofollow noreferrer">One year using Kubernetes in production: Lessons learned</a>. Author goes into explaining what have they achieved by switching to Kubernetes as well differences in overhead:</p>

<blockquote>
  <h3>Cost calculation</h3>
  
  <p>Looking at costs, there are two sides to the story. To run Kubernetes, an etcd cluster is required, as well as a master node. While these are not necessarily expensive components to run, this overhead can be relatively expensive when it comes to very small deployments. For these types of deployments, it’s probably best to use a hosted solution such as Google's Container Service.</p>
  
  <p>For larger deployments, it’s easy to save a lot on server costs. The overhead of running etcd and a master node aren’t significant in these deployments. Kubernetes makes it very easy to run many containers on the same hosts, making maximum use of the available resources. This reduces the number of required servers, which directly saves you money. When running Kubernetes sounds great, but the ops side of running such a cluster seems less attractive, there are a number of hosted services to look at, including Cloud RTI, which is what my team is working on.</p>
</blockquote>
