Skip to main content
Version: 3.2

Snapshot single PVCs in OpenShift with FlashArray

Summary and Key concepts

Summary:

This article provides instructions on how to create snapshots of PVCs backed by Portworx volumes in Kubernetes. It explains how to create snapshots within a single namespace and across multiple namespaces using Kubernetes manifests. The guide covers checking snapshot status with oc and storkctl commands, and includes an example of taking snapshots in one namespace and restoring them in another. The article also outlines using annotations to manage cross-namespace snapshot restoration and provides YAML examples for creating PVCs from snapshots.

Kubernetes Concepts:

  • PersistentVolumeClaim (PVC): Used to request storage in Kubernetes, and can be snapshotted and restored.
  • Annotations: Attach metadata to Kubernetes objects, like defining which namespaces can restore snapshots.
  • Namespace: Used to isolate resources and manage PVC snapshots across different namespaces.

Portworx Concepts:

  • Stork: A Kubernetes extension used for managing storage operations such as snapshots.

  • VolumeSnapshot: Represents a snapshot of a Portworx volume for backup and restoration purposes.

This document will show you how to create a snapshot of a PVC backed by a Portworx volume.

Creating snapshot within a single namespace

  1. If you have a PVC called jenkins-home-jenkins-master-0, in the jenkins namespace, you can create a snapshot for that PVC by using the following spec:

    apiVersion: volumesnapshot.external-storage.k8s.io/v1
    kind: VolumeSnapshot
    metadata:
    name: jenkins-home-jenkins-master-0
    namespace: jenkins
    spec:
    persistentVolumeClaimName: jenkins-home-jenkins-master-0
  2. Once you apply the above object you can check the status of the snapshots using oc:

    oc get -n jenkins volumesnapshot
    NAME                                                      AGE
    jenkins-jobs-jenkins-master-0-snapshot-2019-03-20-snap1 6m
    oc get -n jenkins volumesnapshotdatas
    NAME                                                       AGE
    k8s-volume-snapshot-xxxxxxxx-xxxx-xxxx-xxxx-0242ac110002 8m
  3. The creation of the volumesnapshotdatas object indicates that the snapshot has been created. If you describe the volumesnapshotdatas object you can see the Portworx Volume Snapshot ID and the PVC for which the snapshot was created:

    oc describe volumesnapshotdatas
Name:         k8s-volume-snapshot-xxxxxxxx-xxxx-xxxx-xxxx-0242ac110002
Namespace:
Labels: <none>
Annotations: <none>
API Version: volumesnapshot.external-storage.k8s.io/v1
Kind: VolumeSnapshotData
Metadata:
Creation Timestamp: 2019-03-20T22:22:37Z
Generation: 1
Resource Version: 56596513
Self Link: /apis/volumesnapshot.external-storage.k8s.io/v1/volumesnapshotdatas/k8s-volume-snapshot-xxxxxxxx-xxxx-xxxx-xxxx-0242ac110002
UID: xxxxxxxx-xxxx-xxxx-xxxx-0cc47ab5f9a2
Spec:
Persistent Volume Ref:
Kind: PersistentVolume
Name: pvc-xxxxxxxx-xxxx-xxxx-xxxx-0cc47ab5f9a2
Portworx Volume:
Snapshot Id: 411710013297550893
Snapshot Type: local
Volume Snapshot Ref:
Kind: VolumeSnapshot
Name: jenkins/jenkins-jobs-jenkins-master-0-snapshot-2019-03-20-snap1-xxxxxxxx-xxxx-xxxx-xxxx-0cc47ab5f9a2
Status:
Conditions:
Last Transition Time: 2019-03-20T22:22:37Z
Message: Snapshot created successfully and it is ready
Reason:
Status: True
Type: Ready
Creation Timestamp: <nil>
Events: <none>
  1. You can use the storkctl command to verify that the snapshot was created successfully:

    storkctl -n jenkins get snap
    NAME                                                      PVC                             STATUS    CREATED               COMPLETED             TYPE
    jenkins-jobs-jenkins-master-0-snapshot-2019-03-20-snap1 jenkins-jobs-jenkins-master-0 Ready 20 Mar 19 15:22 PDT 20 Mar 19 15:22 PDT local

Creating snapshots across namespaces

When creating snapshots, you can provide comma separated regexes with stork.libopenstorage.org/snapshot-restore-namespaces annotation to specify which namespaces the snapshot can be restored to. When creating PVC from snapshots, if a snapshot exists in another namespace, the snapshot namespace should be specified with stork.libopenstorage.org/snapshot-source-namespace annotation.

Let's take an example where we have 2 namespaces dev and prod. We will create a PVC and snapshot in the dev namespace and then create a PVC in the prod namespace from the snapshot.

  1. Create the namespaces

    apiVersion: v1
    kind: Namespace
    metadata:
    name: dev
    labels:
    name: dev
    ---
    apiVersion: v1
    kind: Namespace
    metadata:
    name: prod
    labels:
    name: prod
  2. Create the PVC

    kind: PersistentVolumeClaim
    apiVersion: v1
    metadata:
    name: mysql-data
    namespace: dev
    annotations:
    volume.beta.kubernetes.io/storage-class: px-mysql-sc
    spec:
    accessModes:
    - ReadWriteOnce
    resources:
    requests:
    storage: 2Gi
    ---
    kind: StorageClass
    apiVersion: storage.k8s.io/v1
    metadata:
    name: px-mysql-sc
    provisioner: pxd.portworx.com
    parameters:
    repl: "2"
  3. Create the snapshot

    apiVersion: volumesnapshot.external-storage.k8s.io/v1
    kind: VolumeSnapshot
    metadata:
    name: mysql-snapshot
    namespace: dev
    annotations:
    stork.libopenstorage.org/snapshot-restore-namespaces: "prod"
    spec:
    persistentVolumeClaimName: mysql-data

  4. Create a PVC in a different namespace from the snapshot

    apiVersion: v1
    kind: PersistentVolumeClaim
    metadata:
    name: mysql-clone
    namespace: prod
    annotations:
    snapshot.alpha.kubernetes.io/snapshot: mysql-snapshot
    stork.libopenstorage.org/snapshot-source-namespace: dev
    spec:
    accessModes:
    - ReadWriteOnce
    storageClassName: stork-snapshot-sc
    resources:
    requests:
    storage: 2Gi