How to create mysql container with initial data in kubernetes?

42
March 15, 2019, at 7:00 PM

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? I have created pv and pvc and the data is being lost after deleting the 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

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

Write a script and attach it to post start hook. Verify I is database is present. If not go ahead and run sql commands to create required data

READ ALSO
Tableview not showing new added data, only shows after restarting program (javafx)

Tableview not showing new added data, only shows after restarting program (javafx)

The tableview only shows new added data when I restart the programPlease help !

54
My SQL: I cannot count values from my table

My SQL: I cannot count values from my table

I am assigning my variable

39
It works local with xampp. The login works live, but the register does not

It works local with xampp. The login works live, but the register does not

Everything works fineThe error log does not show a thing

58
No queries working on table after LOAD DATA INFILE

No queries working on table after LOAD DATA INFILE

I've tried to upload a large CSV file (148GB) to a MySQL DB using InnoDB engine and the LOAD DATA INFILE command

27