栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 系统运维 > 运维 > Linux

【Django-CI系统】Volume解法1--SQLite持久化保存到虚拟机hostPath-20220516

Linux 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

【Django-CI系统】Volume解法1--SQLite持久化保存到虚拟机hostPath-20220516

效果:deployment的pod重新启动后,SQLite可以持久化保存数据。 9K. SQLite可保存至hostPath

步骤1:应用启动时,会将数据从持久卷同步到应用中。因为hostpath: /data为空,故第一次部署时,数据库是空的。
步骤2:应用启动后,数据会从应用同步到持久卷。故在部署后的应用网站上传数据后,数据会同步到hostpath: /data。

步骤3:应用关闭后,数据会保存在持久卷中。
步骤4:将重启pod或deployment后,持久卷会重复步骤1-----应用启动时,会将数据从持久卷同步到应用中。

重新设定SQLite的位置到training_systemSQL,方便挂hostPath的volume

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
转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/893070.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号