2
votes

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.

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).

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.

A simplified version of our startup script:

#!/bin/bash

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

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

await_modules()

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.

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

Some things we have discovered and tried are listed below.

Linux staging environment

Our staging environment consists of Ubuntu with native Docker. Kubernetes is installed through minikube with --vm-driver none.

Contrary to our local development environment, the staging environment retrieves the application code through a (deprecated) gitRepo 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.

We tried replacing the gitRepo 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 gitRepo volume.

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.

Docker run time

Executing a single empty alpine container through docker run alpine echo "test" 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.

Docker volume sharing

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

Parallel or sequential

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

IO bound?

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.

Reducing IO through ramdisk

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

1
I still don't understand what is the exact question here. You are comparing different operating systems with different installations of Kubernetes. Re thing the architecture, add more nodes.Crou
Why does executing 40 hooks (jobs) take so excruciatingly long? The processes itself are quiet fast, but it takes forever to run them through Kubernetes. I am not comparing multiple environment, merely indicating that the (Linux) staging environment is just as slow as the local (Windows) development environment. Adding more nodes is not an option (because local environment) and shouldn't be necessary anyway. It seems like Helm / Kubernetes / Docker adds more than 5 minutes of overhead to something that should be very simple.Thanaton
You can test it on GCP using Free Tier, create a k8s cluster of 3 nodes and deploy those jobs. You will be able to see if those jobs are fairly simple and finish quickly or they are sluggish and you need to change something.Crou
We have a production cluster on AWS (made through kops), but it exhibits the same symptoms. So the question still stands: running the jobs manually on my local computer takes maybe 20 seconds (in total, not per job); where does the overhead in Kuberenetes come from or how can we find and debug the cause?Thanaton

1 Answers

1
votes

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.

I recommend reading One year using Kubernetes in production: Lessons learned. Author goes into explaining what have they achieved by switching to Kubernetes as well differences in overhead:

Cost calculation

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.

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.