<p>I'm experiencing an issue where an image I'm running as part of a Kubernetes deployment is behaving differently from the expected and consistent behavior of the same image run with <code>docker run &lt;...&gt;</code>. My understanding of the main purpose of containerizing a project is that it will always run the same way, regardless of the host environment (ignoring the influence of the user and of outside data. Is this wrong?</p>

<p>Without going into too much detail about my specific problem (since I feel the solution may likely be far too specific to be of help to anyone else on SO, and because I've already detailed it <a href="https://stackoverflow.com/questions/53714029/gunicorn-continually-booting-workers-when-run-in-a-docker-image-on-kubernetes">here</a>), I'm curious if someone can detail possible reasons to look into as to why an image might run differently in a Kubernetes environment than locally through Docker.</p>

Mike S
<p>The general answer of why they're different is <em>resources</em>, but the real answer is that they should both be identical given identical resources.</p>

<p>Kubernetes uses <code>docker</code> for its container runtime, at least in most cases I've seen. There are some other runtimes (<a href="https://cri-o.io/" rel="nofollow noreferrer"><code>cri-o</code></a> and <a href="https://coreos.com/rkt/" rel="nofollow noreferrer"><code>rkt</code></a>) that are less widely adopted, so using those may also contribute to variance in how things work.</p>

<p>On your local <code>docker</code> it's pretty easy to mount things like directories (volumes) into the image, and you can populate the directory with some content. Doing the same thing on <code>k8s</code> is more difficult, and probably involves more complicated mappings, persistent volumes or an init container.</p>

<p>Running <code>docker</code> on your laptop and <code>k8s</code> on a server somewhere may give you different hardware resources:</p>

<ul>
<li>different amounts of RAM</li>
<li>different size of hard disk</li>
<li>different processor features</li>
<li>different core counts</li>
</ul>

<p>The last one is most likely what you're seeing, <code>flask</code> is probably looking up the core count for both systems and seeing two different values, and so it runs two different thread / worker counts.</p>
