'Volume not persistent in Google Cloud

I'm trying to build a mysql pod on Google Cloud. However, when I create a database and then restart the pod, the database that I created is not persisted.

I follow this official tutorial : https://github.com/kubernetes/kubernetes/tree/master/examples/mysql-wordpress-pd

mysql-deployment.yaml :

---
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  name: mysql-pv-claim
  labels:
    app: myApp
    env: production
spec:
  accessModes:
    - ReadWriteOnce
  resources:
    requests:
      storage: 20Gi
---
kind: Deployment
apiVersion: extensions/v1beta1
metadata:
  name: myapp-backend-production-mysql
spec:
  replicas:
  template:
    metadata:
      labels:
        app: myapp
        role: backend
        env: production
        type: mysql
    spec:
      containers:
      - name: backend-mysql
        image: mysql:5.6
        env:
        - name: MYSQL_ROOT_PASSWORD
          valueFrom:
            secretKeyRef:
              name: mysql-pass
              key: password.txt
        ports:
        - name: backend
          containerPort: 3306
        volumeMounts:
        - name: mysql-persistent-storage
          mountPath: /var/lib/mysql
      volumes:
        - name: mysql-persistent-storage
          persistentVolumeClaim:
            claimName: mysql-pv-claim

And the volume.yaml :

# Not applied for all build
kind: PersistentVolume
apiVersion: v1
metadata:
  name: mysql-production-pv-1
  labels:
    app: myapp
    env: production
spec:
  capacity:
    storage: 20Gi
  accessModes:
    - ReadWriteOnce
  gcePersistentDisk:
    pdName: mysql-production-1
    fsType: ext4
---
kind: PersistentVolume
apiVersion: v1
metadata:
  name: mysql-production-pv-2
  labels:
    app: myapp
    env: production
spec:
  capacity:
    storage: 20Gi
  accessModes:
    - ReadWriteOnce
  gcePersistentDisk:
    pdName: mysql-production-2
    fsType: ext4


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source