[英]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.