0

Need to create a single pod with multiple containers for MySQL, MongoDB, MySQL. My question is should I need to create persistence volume and persistence volume claim for each container and specify the volume in pod configuration or single PV & PVC is enough for all the containers in a single pod-like below configs.

Could you verify below configuration is enough or not?

PV:

    apiVersion: v1
kind: PersistentVolume
metadata:
  name: mypod-pv
  labels:
    type: local
spec:
  storageClassName: manual
  capacity:
    storage: 10Gi
  accessModes:
    - ReadWriteOnce
  hostPath:
    path: "/mnt/data"
---

PVC

    apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  name: mypod-pvc
spec:
  storageClassName: manual
  accessModes:
    - ReadWriteOnce
  resources:
    requests:
      storage: 3Gi
---

Deployment:

    apiVersion: apps/v1
kind: Deployment
metadata:
  name: mypod
  labels:
    app: mypod
spec:
  replicas: 1
  selector:
    matchLabels:
      app: mypod
  template:
    metadata:
      labels:
        app: mypod
    spec:
      volumes:
        - name: task-pv-storage
          persistentVolumeClaim:
            claimName: mypod-pvc
      containers:
        - name: mysql
          image: mysql/mysql-server:latest
          ports:
            - containerPort: 3306
          imagePullPolicy: IfNotPresent
          volumeMounts:
            - mountPath: "/var/lib/mysql"
              name: task-pv-storage
        - name: mongodb
          image: openshift/mongodb-24-centos7
          ports:
            - containerPort: 27017
          imagePullPolicy: IfNotPresent
          volumeMounts:
            - mountPath: "/var/lib/mongodb"
              name: task-pv-storage
        - name: mssql
          image: mcr.microsoft.com/mssql/server
          ports:
            - containerPort: 1433
          imagePullPolicy: IfNotPresent
          volumeMounts:
            - mountPath: "/var/opt/mssql"
              name: task-pv-storage
      imagePullSecrets:
        - name: devplat

1 Answer 1

1

You should not be running multiple database containers inside a single pod.

Consider running each database in a separate statefulset.

follow below reference for mysql

https://kubernetes.io/docs/tasks/run-application/run-replicated-stateful-application/

You need to adopt similar approach for mongodb or other databases as well.

Sign up to request clarification or add additional context in comments.

2 Comments

@P Ekambaram, I agreed with you. Also i am going to have single replica for all the containers. For this case, statefulset or deployment with pv & pvc? which one is suitable for me.
statefulset is preferred for databases

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.