<p>I am having one python-django project which consist of sqlite3 database, I am deploying it on Kubernetes pod, wanted to know how to access the sqlite3 database, once I deploy the app on Kubernetes. Generally If I was using postgres or mysql, I would have created another pod and then expose my services, not sure for sqlite3 database. How to access it and use the database, or I have to create a new pod for sqlite3?</p>
<p>Dockerfile for my Django app:</p>
<pre><code>FROM python:3.4

RUN apt-get update \
    &amp;&amp; apt-get install -y --no-install-recommends \
        sqlite3 \
    &amp;&amp; rm -rf /var/lib/apt/lists/*

WORKDIR /usr/src/app
COPY requirements.txt ./
RUN pip install -r requirements.txt
COPY . .

EXPOSE 8000
CMD [&quot;python&quot;, &quot;manage.py&quot;, &quot;runserver&quot;, &quot;0.0.0.0:8000&quot;]  

</code></pre>

<p>The sqlite file should be created in the root of the project inside the pod. But, you should not use sqlite in Kuberneters. Because inside the pods, all the codes are <a href="https://kubernetes.io/docs/concepts/policy/pod-security-policy/" rel="nofollow noreferrer">read-only mode</a>. Hence even if you want to update the sqlite file, you won't be able to do that unless you give it write permission from dockerfile.</p>
<p>Also, you need to keep in mind, after each deployment pods are recreated, so the sqlite file will be replaced by new one on each deployment and you will lose all your data.</p>
<p>Potential solutions are:</p>
<ol>
<li><p>You can add <a href="https://kubernetes.io/docs/concepts/storage/persistent-volumes/" rel="nofollow noreferrer">persistant volume</a> to sqlite file path, so it won't be lost after each deployment.</p>
</li>
<li><p>Deploy a MySQL/Postgres DB in kubernetes, and create a Database there. Then connect your Django application to that DB.</p>
</li>
<li><p>Even better, use a reliable/paid solution like AWS RDS or Cloud SQL.</p>
</li>
</ol>
