SVD
SVD

Reputation: 405

How to use sqlite3 database with Django on Kuberenets pod

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?

Dockerfile for my Django app:

FROM python:3.4

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

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

EXPOSE 8000
CMD ["python", "manage.py", "runserver", "0.0.0.0:8000"]  

Upvotes: 3

Views: 6538

Answers (1)

ruddra
ruddra

Reputation: 52018

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 read-only mode. 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.

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.

Potential solutions are:

  1. You can add persistant volume to sqlite file path, so it won't be lost after each deployment.

  2. Deploy a MySQL/Postgres DB in kubernetes, and create a Database there. Then connect your Django application to that DB.

  3. Even better, use a reliable/paid solution like AWS RDS or Cloud SQL.

Upvotes: 2

Related Questions