Skip to content

Instantly share code, notes, and snippets.

@assertnotnull
Created July 27, 2018 14:26
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save assertnotnull/8e1f8307321081c1068b93c6b49b2b94 to your computer and use it in GitHub Desktop.
Save assertnotnull/8e1f8307321081c1068b93c6b49b2b94 to your computer and use it in GitHub Desktop.
kubernetes mysql init loading sql on entrypoint
---
apiVersion: v1
kind: Service
metadata:
name: mysql
spec:
ports:
- port: 3306
nodePort: 30306
selector:
app: mysql
type: NodePort
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: mysql
spec:
replicas: 1
selector:
matchLabels:
app: mysql
strategy:
type: Recreate
template:
metadata:
labels:
app: mysql
spec:
containers:
- image: mysql:5.7.17
name: mysql
env:
# Use secret in real usage
- name: MYSQL_ROOT_PASSWORD
value: root
- name: MYSQL_DATABASE
value: somedb
ports:
- containerPort: 3306
name: mysql
volumeMounts:
- name: mysql-persistent-storage
mountPath: /var/lib/mysql/
- name: mysql-host-path
mountPath: /docker-entrypoint-initdb.d/
volumes:
- name: mysql-persistent-storage
persistentVolumeClaim:
claimName: mysql-pv-claim
- name: mysql-host-path
hostPath:
path: /pathonhost/
# minikube mount /home/pgauthier/Projets/docker/someproject/database/:/pathonhost/
type: Directory
---
apiVersion: v1
kind: PersistentVolume
metadata:
name: mysql-pv-volume
labels:
type: local
spec:
storageClassName: manual
persistentVolumeReclaimPolicy: Reclaim
#Set it to Delete when removing the volume to delete the files - so it triggers the docker-entrypoint
capacity:
storage: 20Gi
accessModes:
- ReadWriteOnce
hostPath:
path: "/mnt/data"
---
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: mysql-pv-claim
spec:
storageClassName: manual
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 20Gi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment