<p>I am an computer enginering student. In my freetime I am working an a K8s project.</p>
<p>I was wondering how PVC works, I understand the basic concept. But here is my question.
So this is the code for a basic wordpress with mysql application.</p>
<p>I was wondering if I want to make multiple instaces of this application, do I need to change the mountpath? Or is the mountpath the location within the container.</p>
<pre><code>apiVersion: v1
kind: Service
metadata:
  name: wordpress-mysql
  labels:
    app: wordpress
spec:
  ports:
    - port: 3306
  selector:
    app: wordpress
    tier: mysql
  clusterIP: None
---
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  name: mysql-pv-claim
  labels:
    app: wordpress
spec:
  accessModes:
    - ReadWriteOnce
  resources:
    requests:
      storage: 20Gi
---
apiVersion: apps/v1
kind: Deployment
metadata:
  name: wordpress-mysql
  labels:
    app: wordpress
spec:
  selector:
    matchLabels:
      app: wordpress
      tier: mysql
  strategy:
    type: Recreate
  template:
    metadata:
      labels:
        app: wordpress
        tier: mysql
    spec:
      containers:
      - image: mysql:5.6
        name: mysql
        env:
        - name: MYSQL_ROOT_PASSWORD
          valueFrom:
            secretKeyRef:
              name: mysql-pass
              key: password
        ports:
        - containerPort: 3306
          name: mysql
        volumeMounts:
        - name: mysql-persistent-storage
          mountPath: /var/lib/mysql
      volumes:
      - name: mysql-persistent-storage
        persistentVolumeClaim:
          claimName: mysql-pv-claim
</code></pre>

Bram Breda
<p>if you really want to run different instance you would really love to create different data directory for them. it's never good idea to use deployment in this scenario. it's better if you use <code>statefulset</code> to manage database. statefulset will automatically generate different pvc for different pods.  you can check that with <code>kubectl get pvc</code>. here, in statefulset <code>volumeClaimTemplates</code> is the template for <code>pvc</code>.</p>
<p>pvc name will be like that <code>&lt;pvc_template_name&gt;-&lt;statefulset_name&gt;-&lt;podnumber&gt;</code>.</p>
<p>eg: <code>mysql-pv-claim-wordpress-mysql-0</code></p>
<pre><code>
apiVersion: v1
kind: Service
metadata:
  name: wordpress-mysql
  labels:
    app: wordpress
spec:
  ports:
    - port: 3306
  selector:
    app: wordpress
    tier: mysql
  clusterIP: None

---
apiVersion: apps/v1
kind: StatefulSet
metadata:
  name: wordpress-mysql
  labels:
    app: wordpress
spec:
  serviceName: wordpress-mysql
  replicas: 1
  selector:
    matchLabels:
      app: wordpress
      tier: mysql

  template:
    metadata:
      labels:
        app: wordpress
        tier: mysql
    spec:
      containers:
      - image: mysql:5.6
        name: mysql
        env:
        - name: MYSQL_ROOT_PASSWORD
          valueFrom:
            secretKeyRef:
              name: mysql-pass
              key: password
        ports:
        - containerPort: 3306
          name: mysql
        volumeMounts:
        - name: mysql-pv-claim
          mountPath: /var/lib/mysql
  volumeClaimTemplates:
  - metadata:
      name: mysql-pv-claim
    spec:
      accessModes: [ &quot;ReadWriteOnce&quot; ]
      storageClassName: standard
      resources:
        requests:
          storage: 20Gi
</code></pre>
