步骤1:应用启动时,会将数据从持久卷同步到应用中。因为hostpath: /data为空,故第一次部署时,数据库是空的。
步骤2:应用启动后,数据会从应用同步到持久卷。故在部署后的应用网站上传数据后,数据会同步到hostpath: /data。
步骤3:应用关闭后,数据会保存在持久卷中。
步骤4:将重启pod或deployment后,持久卷会重复步骤1-----应用启动时,会将数据从持久卷同步到应用中。
settings.py
# Database
# https://docs.djangoproject.com/en/3.2/ref/settings/#databases
print(Path(__file__).resolve().parent)
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3',
#'NAME': BASE_DIR / 'db.sqlite3',
'NAME': Path(__file__).resolve().parent /'SQL' /'db.sqlite3',
}
}
yamal设定PVC
yaml档案
apiVersion: apps/v1
kind: Deployment
metadata:
name: ci-dp
spec:
replicas: 1
selector:
matchLabels:
app: ci-pod
template:
metadata:
labels:
app: ci-pod
spec:
containers:
- name: ci
image: seasonzhang/civ2:5.0
imagePullPolicy: Always
resources:
requests:
cpu: 500m
memory: 500Mi
limits:
cpu: 800m
memory: 1000Mi
ports:
- containerPort: 8000
name: ci-pod
protocol: TCP
volumeMounts:
- name: ci-pvcc
mountPath: "/code/package/training_system/SQL"
volumes:
- name: ci-pvcc
persistentVolumeClaim:
hostPath:
# directory location on host
path: /data
# this field is optional
type: Directory
---
apiVersion: v1
kind: Service
metadata:
name: ci-svc
spec:
type: LoadBalancer
ports:
- port: 8330
targetPort: 8000
protocol: TCP
selector:
app: ci-pod
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)