<p>I have 15 pods that run different PHP applications in a Kubernetes cluster, each application must include a PHP library updated regularly, it's always the same lib/version for all pods.
What is the best approach to share a library with all pods?</p>
<p>I tried to find out a solution but my doubts persist.
What I thought:</p>
<ol>
<li><p>Include the lib in the application container during the build, this solution create a consistent application but I have to re-deploy all 15 applications. Make sense?</p>
</li>
<li><p>Include the lib as shared volume among all pods, in this case I can update only the lib and all application will be updated. It seems better even if I don't like this option because each application depends on the shared volume.</p>
</li>
</ol>
<p>What are your thoughts regarding this issue?</p>

Fabio Ferrari
<p>Always make your images be self-contained.  Don't build an image that can't run unless something outside the container space is present, or try to use a volume to share code.  (That is, pick your first option over the second.)</p>
<hr />
<p>Say you have your shared library, and you have your 15 applications A through O that depend on it.  Right now they're running last week's build <code>image: service-a:20210929</code> and so on.  Service A needs a new feature with support in the shared library, so you update that and redeploy it and announce the feature to your users.  But then you discover that the implementation in the shared library causes a crash in service B on some specific customer requests.  What now?</p>
<p>If you've built each service as a standalone image, this is easy.  <code>helm rollback service-b</code>, or otherwise change service B back to the <code>20210929</code> tag while service A is still using the updated <code>20211006</code> tag.  You're running mixed versions, but that's probably okay, and you can fix the library and redeploy everything tomorrow, and your system as a whole is still online.</p>
<p>But if you're trying to share the library, you're stuck.  The new version breaks a service, so you need to roll it back; but rolling back the library would require you to also know to roll back the service that depends on the newer version, and so on.  You'd have to undeploy your new feature even though the thing that's broken is only indirectly related to it.</p>
<hr />
<p>If the library is really used everywhere, and if disk space is actually your limiting factor, you could restructure your image setup to have three layers:</p>
<ol>
<li>The language interpreter itself;</li>
<li><code>FROM language-interpreter</code>, plus the shared library;</li>
<li><code>FROM shared-library:20211006</code>, plus this service's application code.</li>
</ol>
<p>If they're identical, the lower layers can be shared between images, and the image pull mechanics know to not pull layers that are already present on the system.  However, this can lead to a more complex build setup that might be a little trickier to replicate in developer environments.</p>
