apiVersion: v1 kind: PersistentVolume metadata: name: mysql-pv labels: type: local spec: storageClassName: manual capacity: storage: 5Gi accessModes: - ReadWriteOnce persistentVolumeReclaimPolicy: Retain hostPath: path: "/mnt/data/mysql" # DirectoryOrCreate: kubelet will create the dir if it doesn't exist, # preventing MySQL CrashLoopBackOff due to missing mount path. type: DirectoryOrCreate # IMPORTANT for multi-node clusters: uncomment nodeAffinity and set your # node's hostname so MySQL always schedules on the node that has the data. # Run: kubectl get nodes to find the hostname. # nodeAffinity: # required: # nodeSelectorTerms: # - matchExpressions: # - key: kubernetes.io/hostname # operator: In # values: # - YOUR-NODE-HOSTNAME