Created
October 30, 2018 16:57
-
-
Save hossainemruz/76adcfdaf51adf2ab7ab8e9b2d5d3d87 to your computer and use it in GitHub Desktop.
Sample MySQL deployment to initialize from *.sql file
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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 |
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
Could you please help me out with this
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
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.