I tried to deploy MySQL deployment with Kubernetes, having three replicas which are accessing the same storage(PVC). Here is the configuration
apiVersion: v1
kind: PersistentVolume
metadata:
name: mysql-pv
labels:
type: local
spec:
persistentVolumeReclaimPolicy: Retain
capacity:
storage: 1Gi
accessModes:
- ReadWriteMany
hostPath:
path: "/mnt/data"
---
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: mysql-pvc
spec:
accessModes:
- ReadWriteMany
resources:
requests:
storage: 1Gi
---
apiVersion: v1
kind: Service
metadata:
name: mysql-service
spec:
type: NodePort
ports:
- protocol: TCP
port: 3307
targetPort: 3306
nodePort: 30091
selector:
app: mysql
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: mysql
spec:
replicas: 2
selector:
matchLabels:
app: mysql
template:
metadata:
labels:
app: mysql
spec:
containers:
- image: mysql:latest
name: mysql
env:
- name: MYSQL_ROOT_PASSWORD
value: pwd
ports:
- containerPort: 3306
volumeMounts:
- name: mysql-storage
mountPath: /var/lib/mysql
volumes:
- name: mysql-storage
persistentVolumeClaim:
claimName: mysql-pvc
When you apply this configuration file kubectl apply -f file_name.yaml, you can create three pods, which are accessing the same storage for the databases. When you check the pods’ status kubectl get pods, you can see only one pod becomes running and others be in a CrashLoop state. What is happening is, when creating more than one instance to use a common storage, only one instance can acquire the lock of the ibdata1 file. That’s why only one pod becomes healthy and others in CrashLoop.( you can see this using kubectl logs pod-name).
I have tried this to mongoDB as well. Got the same issue as requiring lock for the mongo.in file failed.
What I need to know is,
Can I release the lock of the ibdata file and use the storage for all the pods?(this mostly can not, because of consistency issues) If not, how can I create the proposed idea?( accessing a single storage/volume using multiple pod instances)? Would you suggest other ideas to achieve accessing a single storage using multiple pod instances? Your answers and help are welcomed.
Sivaparan Sivakajan is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.