<p>I am looking for any existing implementation of sharing a read only in-memory cache across pods on the same node. This setup would allow fast access without the need to load the entire cache into each pods memory.</p>
<p>Example: 1GB lookup dictionary is kept up to date, each pod has read access to the data allowing fast lookup without effectively cloning the data into memory. So end result would be just 1GB of memory utilized on the node, and not 1GB * N(number of pods)</p>
<p>Imagined solution for k8s:</p>
<ol>
<li>A single (Daemon) pod that has the tmpfs volume RW, maintaining an up to date cache data</li>
<li>Multiple pods that have the same tmpfs volume R(only), mapping the data file(s) to read data out
<ol>
<li>Naturally reading out values and operating on them is expected to create transitive memory usage</li>
</ol>
</li>
</ol>
<p>Notes:</p>
<ul>
<li>I have found <a href="https://stackoverflow.com/questions/64928844/kubernetes-shared-file-system-across-pods">multiple entries regarding volume sharing between pods</a>, but no complete solution reference for the above</li>
<li>tmpfs is ideal for cache speed of R/W, however obviously it can be over regular fs</li>
<li>Looking for solutions that can be language specific or agnostic for reference
<ul>
<li>Language specific would be utilizing a specific language to map a file data as a Dictionary / other KV lookup</li>
<li>Language agnostic and more generalized solution could be utilizing <a href="https://stackoverflow.com/questions/1063438/sqlite3-and-multiple-processes">sqlite</a> where processes in our case here would be pods</li>
</ul>
</li>
</ul>

<p>You could use <a href="https://kubernetes.io/docs/concepts/policy/pod-security-policy/#host-namespaces" rel="nofollow noreferrer"><code>hostIPC</code></a> and/or <a href="https://kubernetes.io/docs/concepts/storage/volumes/#hostpath" rel="nofollow noreferrer"><code>hostPath</code></a> mounted on <code>tmpfs</code>, but that comes with a swathe of issues:</p>
<ol>
<li><code>hostPath</code> by itself poses a security risk, and when used, should be scoped to only the required file or directory, and mounted as ReadOnly. It also comes with the caveat of not knowing who will get &quot;charged&quot;
for the memory, so every pod has to be provisioned to be able to
absorb it, depending how it is written. It also might &quot;leak&quot; up to
the root namespace and be charged to nobody but appear as &quot;overhead&quot;</li>
<li><code>hostIPC</code> is  a part of <a href="https://kubernetes.io/docs/concepts/policy/pod-security-policy/" rel="nofollow noreferrer">Pod Security Policies
</a>, which are depracted as of <em>1.21</em>, and will be removed in the future</li>
</ol>
<p>Generally, the best idea is to use <a href="https://redis.io/" rel="nofollow noreferrer">Redis</a>, it is one of the most used tools in such scenarios.</p>
