Skip to content

Instantly share code, notes, and snippets.

@yxw
Forked from hossainemruz/mysql-init-demo.yaml
Created August 16, 2023 08:49
Show Gist options
  • Select an option

  • Save yxw/cd8c3ce7ef94aa5f6ec0792cd850ae88 to your computer and use it in GitHub Desktop.

Select an option

Save yxw/cd8c3ce7ef94aa5f6ec0792cd850ae88 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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment