简体   繁体   English

通过 Kubernetes 作业和持久卷声明进行 Django 迁移

[英]Django migrations by Kubernetes Job and persistent Volume Claim

Is the best approach to make migrations and migrate models using a Job and a Persistent Volume Claim on Kubernetes Django deployed app?在 Kubernetes Django 部署的应用程序上使用 Job 和 Persistent Volume Claim 进行迁移和迁移模型的最佳方法是什么?

Persistent Volume持久卷

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

Job工作

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

Looks fine for me.对我来说看起来不错。 Not sure if you need run this job once or every time, when a new pod is up?不确定是否需要在新 Pod 启动时运行此作业一次或每次?

If it is running before Django service pod started every time, maybe you can get help with Init Containers如果它每次都在 Django 服务 pod 启动之前运行,也许你可以得到Init Containers 的帮助

Example:例子:

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! && 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;']

you can do the same for deployment你可以为部署做同样的事情

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 kubernetes 创建一个持久卷并在我的 django 应用程序中使用 - kubernetes create a persistent volume and use in my django app Django 关于 Kube.netes 部署:数据库迁移的最佳实践 - Django on Kubernetes Deployment: Best practices for DB Migrations 如何在 kubernetes 中运行 Django 迁移并将更改应用于数据库 pod? - How to run Django migrations inside kubernetes and apply changes to the database pod? 在Kubernetes / Google CloudSQL中为每个部署应用程序一次应用Django迁移 - Applying Django migrations once per deployment application in Kubernetes/Google CloudSQL 我对 django 应用程序的迁移是否会反映在 Kubernetes 中存在的数据库上? - Will migrations that I make to a django app reflect on the DB that is present in Kubernetes? Django迁移 - Django migrations 在“docker-compose run”命令(Django的collectstatic)之后,卷更改不会持久 - Volume changes not persistent after “docker-compose run” command (Django's collectstatic) ConfingExeption 同时向 django 内部的 kubernetes 发送作业信号以激活 pod - ConfingExeption while Sending a job signal to kubernetes inside django to activate a pod Django google kubernetes 客户端未在作业中运行 exe - Django google kubernetes client not running exe inside the job 如何将机密从 Kubernetes 提取到 GitHub 操作中以运行 Django 迁移以进行 AKS 部署? - How to pull secrets from Kubernetes into GitHub action to run Django migrations for AKS deployment?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM