Skip to content

Instantly share code, notes, and snippets.

@hossainemruz
Created October 30, 2018 16:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save hossainemruz/76adcfdaf51adf2ab7ab8e9b2d5d3d87 to your computer and use it in GitHub Desktop.
Save hossainemruz/76adcfdaf51adf2ab7ab8e9b2d5d3d87 to your computer and use it in GitHub Desktop.
Sample MySQL deployment to initialize from *.sql file
# Here, I am using a gcePersistentDisk disk to store my init.sql file.
# You can you any Kubernetes volume such as hostPath,nfs etc.
apiVersion: apps/v1
kind: Deployment
metadata:
name: mysql-init-demo
spec:
selector:
matchLabels:
app: mysql
strategy:
type: Recreate
template:
metadata:
labels:
app: mysql
spec:
containers:
- image: mysql:5.6
name: mysql
env:
- name: MYSQL_ROOT_PASSWORD
value: password
ports:
- containerPort: 3306
name: mysql
volumeMounts:
- name: data
mountPath: /var/lib/mysql
- name: init-script
mountPath: /docker-entrypoint-initdb.d # we are mounting init-script volume in this directory. so init.sql file will be available here.
volumes:
- name: data # this volume will be used for database storage.
persistentVolumeClaim:
claimName: mysql-data-pvc
- name: init-script # this volume holds init.sql file.
gcePersistentDisk:
pdName: mysql-dump-storage
fsType: ext4
@hossainemruz
Copy link
Author

You can create a ConfigMap with the init.sql file. Then, you can mount the ConfigMap as volume.

If your init.sql file is large, then follow this example here.

@amenaafreen
Copy link

When I try to use the init containers thing I get the following error
error: error parsing mysql-initialization-with-init-container.yaml: error converting YAML to JSON: yaml: line 33: mapping values are not allowed in this context

@amenaafreen
Copy link

Screen Shot 2020-01-14 at 11 57 25 AM

@amenaafreen
Copy link

Could you please help me out with this

@hossainemruz
Copy link
Author

I don't see any reason why you are getting this error. Perhaps more context will help to debug.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment