<p>Is the best approach to make migrations and migrate models using a Job and a Persistent Volume Claim on Kubernetes Django deployed app?</p>

<p>Persistent Volume</p>

<pre><code>apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  name: csi-pvc
spec:
  accessModes:
  - ReadWriteOnce
  resources:
    requests:
      storage: 5Gi
  storageClassName: do-block-storage
</code></pre>

<p>Job</p>

<pre><code>apiVersion: batch/v1
kind: Job
metadata:
  name: django-migrations-job
spec:
  template:
    spec:
      containers:
        - name: app
          image: user/app:latest
          command: ["/bin/sh", "-c"]
          args: ["python manage.py makemigrations app; python manage.py migrate"]
          volumeMounts:
           - mountPath: "/container-code-dir/app/migrations"
             name: my-do-volume
      volumes:
        - name: my-do-volume
          persistentVolumeClaim:
           claimName: csi-pvc
</code></pre>

<p>Looks fine for me. Not sure if you need run this job once or every time, when a new pod is up?</p>

<p>If it is running before Django service pod started every time, maybe you can get help with <a href="https://kubernetes.io/docs/concepts/workloads/pods/init-containers/" rel="nofollow noreferrer">Init Containers</a></p>

<p>Example: </p>

<pre><code>apiVersion: v1
kind: Pod
metadata:
  name: myapp-pod
  labels:
    app: myapp
spec:
  containers:
  - name: myapp-container
    image: busybox:1.28
    command: ['sh', '-c', 'echo The app is running! &amp;&amp; sleep 3600']
  initContainers:
  - name: init-myservice
    image: busybox:1.28
    command: ['sh', '-c', 'until nslookup myservice; do echo waiting for myservice; sleep 2; done;']
  - name: init-mydb
    image: busybox:1.28
    command: ['sh', '-c', 'until nslookup mydb; do echo waiting for mydb; sleep 2; done;']
</code></pre>

<p>you can do the same for deployment</p>
