<p>I am trying to use the <code>VolumeSnapshot</code> backup <a href="https://kubernetes.io/docs/concepts/storage/volume-snapshots/" rel="nofollow noreferrer">mechanism</a> promoted in <code>kubernetes</code> to <code>beta</code> from <code>1.17</code>.</p>
<p>Here is my scenario:</p>
<p>Create the nginx deployment and the PVC used by it</p>
<pre class="lang-yaml prettyprint-override"><code>apiVersion: apps/v1
kind: Deployment
metadata:
  name: nginx-deployment
spec:
  selector:
    matchLabels:
      app: nginx
  replicas: 1
  template:
    metadata:
      labels:
        app: nginx
    spec:
      containers:
      - name: nginx
        image: nginx:1.14.2
        ports:
        - containerPort: 80
        volumeMounts:
        - name: my-pvc
          mountPath: /root/test
      volumes:
        - name: my-pvc
          persistentVolumeClaim:
            claimName: nginx-pvc
</code></pre>
<pre class="lang-yaml prettyprint-override"><code>apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  finalizers: null
  labels:
    name: nginx-pvc
  name: nginx-pvc
  namespace: default
spec:
  accessModes:
  - ReadWriteOnce
  resources:
    requests:
      storage: 8Gi
  storageClassName: premium-rwo
</code></pre>
<p>Exec into the running <code>nginx</code> container, cd into the PVC mounted path and create some files</p>
<pre class="lang-sh prettyprint-override"><code>▶ k exec -it nginx-deployment-84765795c-7hz5n bash
root@nginx-deployment-84765795c-7hz5n:/# cd /root/test
root@nginx-deployment-84765795c-7hz5n:~/test# touch {1..10}.txt
root@nginx-deployment-84765795c-7hz5n:~/test# ls
1.txt  10.txt  2.txt  3.txt  4.txt  5.txt  6.txt  7.txt  8.txt  9.txt  lost+found
root@nginx-deployment-84765795c-7hz5n:~/test#
</code></pre>
<p>Create the following <code>VolumeSnapshot</code> using as source the <code>nginx-pvc</code></p>
<pre class="lang-yaml prettyprint-override"><code>apiVersion: snapshot.storage.k8s.io/v1beta1
kind: VolumeSnapshot
metadata:
  namespace: default
  name: nginx-volume-snapshot
spec:
  volumeSnapshotClassName: pd-retain-vsc
  source:
    persistentVolumeClaimName: nginx-pvc
</code></pre>
<p>The <code>VolumeSnapshotClass</code> used is the following</p>
<pre class="lang-yaml prettyprint-override"><code>apiVersion: snapshot.storage.k8s.io/v1beta1
deletionPolicy: Retain
driver: pd.csi.storage.gke.io
kind: VolumeSnapshotClass
metadata:
  creationTimestamp: &quot;2020-09-25T09:10:16Z&quot;
  generation: 1
  name: pd-retain-vsc
</code></pre>
<p>and wait until it becomes <code>readyToUse: true</code></p>
<pre class="lang-yaml prettyprint-override"><code>apiVersion: v1
items:
- apiVersion: snapshot.storage.k8s.io/v1beta1
  kind: VolumeSnapshot
  metadata:
    creationTimestamp: &quot;2020-11-04T09:38:00Z&quot;
    finalizers:
    - snapshot.storage.kubernetes.io/volumesnapshot-as-source-protection
    generation: 1
    name: nginx-volume-snapshot
    namespace: default
    resourceVersion: &quot;34170857&quot;
    selfLink: /apis/snapshot.storage.k8s.io/v1beta1/namespaces/default/volumesnapshots/nginx-volume-snapshot
    uid: ce1991f8-a44c-456f-8b2a-2e12f8df28fc
  spec:
    source:
      persistentVolumeClaimName: nginx-pvc
    volumeSnapshotClassName: pd-retain-vsc
  status:
    boundVolumeSnapshotContentName: snapcontent-ce1991f8-a44c-456f-8b2a-2e12f8df28fc
    creationTime: &quot;2020-11-04T09:38:02Z&quot;
    readyToUse: true
    restoreSize: 8Gi
kind: List
metadata:
  resourceVersion: &quot;&quot;
  selfLink: &quot;&quot;
</code></pre>
<p>Delete the <code>nginx</code> deployment and the initial PVC</p>
<pre class="lang-sh prettyprint-override"><code>▶ k delete pvc,deploy --all
persistentvolumeclaim &quot;nginx-pvc&quot; deleted
deployment.apps &quot;nginx-deployment&quot; deleted
</code></pre>
<p>Create a new PVC, using the previously created <code>VolumeSnapshot</code> as its <code>dataSource</code></p>
<pre class="lang-yaml prettyprint-override"><code>apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  finalizers: null
  labels:
    name: nginx-pvc-restored
  name: nginx-pvc-restored
  namespace: default
spec:
  accessModes:
  - ReadWriteOnce
  resources:
    requests:
      storage: 8Gi
  dataSource:
    name: nginx-volume-snapshot
    kind: VolumeSnapshot
    apiGroup: snapshot.storage.k8s.io
</code></pre>
<pre><code>▶ k create -f nginx-pvc-restored.yaml
persistentvolumeclaim/nginx-pvc-restored created

▶ k get pvc
NAME                 STATUS   VOLUME                                     CAPACITY   ACCESS MODES   STORAGECLASS   AGE
nginx-pvc-restored   Bound    pvc-56d0a898-9f65-464f-8abf-90fa0a58a048   8Gi        RWO            standard       39s
</code></pre>
<p>Set the name of the new (restored) PVC to the nginx deployment</p>
<pre class="lang-yaml prettyprint-override"><code>apiVersion: apps/v1
kind: Deployment
metadata:
  name: nginx-deployment
spec:
  selector:
    matchLabels:
      app: nginx
  replicas: 1
  template:
    metadata:
      labels:
        app: nginx
    spec:
      containers:
      - name: nginx
        image: nginx:1.14.2
        ports:
        - containerPort: 80
        volumeMounts:
        - name: my-pvc
          mountPath: /root/test
      volumes:
        - name: my-pvc
          persistentVolumeClaim:
            claimName: nginx-pvc-restored
</code></pre>
<p>and create the <code>Deployment</code> again</p>
<pre class="lang-sh prettyprint-override"><code>▶ k create -f nginx-deployment-restored.yaml
deployment.apps/nginx-deployment created
</code></pre>
<p><code>cd</code> into the PVC mounted directory. It should contain the previously created files but its empty</p>
<pre class="lang-sh prettyprint-override"><code>▶ k exec -it nginx-deployment-67c7584d4b-l7qrq bash
root@nginx-deployment-67c7584d4b-l7qrq:/# cd /root/test
root@nginx-deployment-67c7584d4b-l7qrq:~/test# ls
lost+found
root@nginx-deployment-67c7584d4b-l7qrq:~/test#
</code></pre>
<pre><code>▶ k version
Client Version: version.Info{Major:&quot;1&quot;, Minor:&quot;17&quot;, GitVersion:&quot;v1.17.12&quot;, GitCommit:&quot;5ec472285121eb6c451e515bc0a7201413872fa3&quot;, GitTreeState:&quot;clean&quot;, BuildDate:&quot;2020-09-16T13:39:51Z&quot;, GoVersion:&quot;go1.13.15&quot;, Compiler:&quot;gc&quot;, Platform:&quot;darwin/amd64&quot;}
Server Version: version.Info{Major:&quot;1&quot;, Minor:&quot;17+&quot;, GitVersion:&quot;v1.17.12-gke.1504&quot;, GitCommit:&quot;17061f5bd4ee34f72c9281d49f94b4f3ac31ac25&quot;, GitTreeState:&quot;clean&quot;, BuildDate:&quot;2020-10-19T17:00:22Z&quot;, GoVersion:&quot;go1.13.15b4&quot;, Compiler:&quot;gc&quot;, Platform:&quot;linux/amd64&quot;}
</code></pre>

pkaramol
<p>This is a community wiki answer posted for more clarity of the current problem. Feel free to expand on it.</p>
<p>As mentioned by @pkaramol, this is an on-going issue registered under the following thread:</p>
<p><a href="https://github.com/kubernetes/kubernetes/issues/96225" rel="nofollow noreferrer">Creating an intree PVC with datasource should fail #96225</a></p>
<blockquote>
<p><strong>What happened:</strong> In clusters that have intree drivers as the default
storageclass, if you try to create a PVC with snapshot data source and
forget to put the csi storageclass in it, then an empty PVC will be
provisioned using the default storageclass.</p>
<p><strong>What you expected to happen:</strong> PVC creation should not proceed and
instead have an event with an incompatible error, similar to how we
check proper csi driver in the csi provisioner.</p>
</blockquote>
<p>This issue has not yet been resolved at the moment of writing this answer.</p>
