简体   繁体   English

如何在kubernetes中使用初始数据创建mysql容器?

[英]How to create mysql container with initial data in kubernetes?

I want to set initial data(script file which creates database and table) on MySQL of container.I have another pod which will talk with mysql pod and inserts data in the table.If I delete mysql pod,it creates an another pod but the previously inserted data is lost.I don't want to lose the data which was inserted before deleting the pod.How to accomplish this? 我想在容器的MySQL上设置初始数据(创建数据库和表的脚本文件)。我有另一个Pod,它将与mysql Pod对话并在表中插入数据。如果我删除mysql Pod,它将创建另一个Pod以前插入的数据会丢失。我不想丢失在删除吊舱之前插入的数据。如何完成此操作? I have created pv and pvc and the data is being lost after deleting the pod. 我已经创建了pv和pvc,并且删除了pod之后数据丢失了。

kind: PersistentVolume
apiVersion: v1
metadata:
  name: mysql-initdb-pv-volume
  labels:
    type: local
    app: mysql
spec:
  storageClassName: manual
  capacity:
    storage: 1Mi
  accessModes:
    - ReadOnlyMany
  hostPath:
    path: "/home/path to script file/script"
---
kind: PersistentVolumeClaim
apiVersion: v1
metadata:
  name: mysql-initdb-pv-claim
  labels:
    app: mysql
spec:
  storageClassName: manual
  accessModes:
    - ReadOnlyMany
  resources:
    requests:
      storage: 1Mi

This is the deployment.yaml 这是Deployment.yaml

       volumeMounts:
    - name: mysql-initdb
      mountPath: /docker-entrypoint-initdb.d
  volumes:
  - name: mysql-initdb
    persistentVolumeClaim:
      claimName: mysql-initdb-pv-claim

Write a script and attach it to post start hook. 编写脚本并将其附加到发布开始挂钩。 Verify that the database is present and online. 验证数据库是否存在并在线。 Then go ahead and run sql commands to create required data 然后继续运行sql命令以创建所需的数据

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM