Impostazione delle istantanee per File Storage for VPC

Cloud virtuale privato

File Storage for VPC Le istantanee dei volumi offrono un metodo standardizzato per copiare il contenuto di un volume in un determinato momento senza creare un volume completamente nuovo. Gli snapshot sono supportati sia per le classi di archiviazione basate su zone ( dp2 ) che su regioni (rfs). Per ulteriori informazioni sugli snapshot, consulta Come funzionano gli snapshot.

Per ulteriori informazioni su File Storage for VPC, vedi Informazioni suFile Storage for VPC.

Il supporto delle istantanee per File Storage for VPC l'add-on è attualmente in versione beta.

Se il PVC (condivisione file) viene eliminato, vengono eliminate tutte le istantanee corrispondenti di proprietà della condivisione file. In questo caso, gli snapshot del volume CSI rimangono, ma gli snapshot backend in VPC non esistono. Pertanto, è necessario eliminare i volumi utilizzando oc delete vs <snapshot-name>.

Prerequisiti

  • Assicurarsi che il componente aggiuntivo File Storage for VPC sia installato nel cluster.
  • Assicuratevi di avere Operatore di istantanea delle azioni autorizzazioni in IAM.

Creazione di un'applicazione

Crea un esempio di Persistent Volume Claim (PVC) e distribuisci un pod che fa riferimento a tale claim.

  1. Accedi al tuo account. Se applicabile, specifica il gruppo di risorse appropriato. Imposta il contesto per il tuo cluster.

  2. Verificare che lo stato dell'add-on sia normal e che lo stato sia Ready.

    ibmcloud oc cluster addon ls --cluster CLUSTER-ID
    
    Name                    Version                     Health State   Health Status   
    vpc-file-csi-driver     2.0                         normal         Addon Ready. For more info: http://ibm.biz/addon-state (H1500)
    
  3. Verificare che i pod del driver siano distribuiti e che lo stato sia Running.

    oc get pods -n kube-system | grep vpc-file-csi
    

    Output di esempio

    ibm-vpc-file-csi-controller-s34sw                    7/7     Running   0          77s
    ibm-vpc-file-csi-controller-7hdhd                    7/7     Running   0          77s
    ibm-vpc-file-csi-node-56c85                          4/4     Running   0          77s
    ibm-vpc-file-csi-node-87j2t                          4/4     Running   0          77s
    ibm-vpc-file-csi-node-cmh2h                          4/4     Running   0          77s
    
  4. Creare un PVC.

    apiVersion: v1
    kind: PersistentVolumeClaim
    metadata:
      name: csi-file-pvc
    spec:
      accessModes:
      - ReadWriteMany
      resources:
        requests:
          storage: 10Gi
      storageClassName: ibmc-vpc-file-min-iops
    
    oc create -f pvc.yaml
    
  5. Verificare che il PVC sia stato creato e sia in uno Bound stato.

    oc get pvc
    
    NAME           STATUS   VOLUME                                     CAPACITY   ACCESS MODES   STORAGECLASS             VOLUMEATTRIBUTESCLASS   AGE
    csi-file-pvc   Bound    pvc-9873bd7e-41a8-4234-a9bf-271b8ca7e4f9   10Gi       RWM          ibmc-vpc-file-min-iops   <unset>                 5
    
  6. Creare un file di configurazione YAML per una distribuzione che monti il PVC creato.

    apiVersion: apps/v1
    kind: Deployment
    metadata:
    name: my-deployment
    labels:
        app: my-deployment
    spec:
    replicas: 1
    selector:
        matchLabels:
        app: my-deployment
    template:
        metadata:
        labels:
            app: my-deployment
        spec:
        containers:
        - image: nginx # Your containerized app image
            name: container-name
            volumeMounts:
            - mountPath: /myvolumepath  # Mount path for PVC
            name: my-vol # Volume mount name
        volumes:
        - name: my-vol  # Volume resource name
            persistentVolumeClaim:
            claimName: csi-file-pvc  # The name of the PVC you created earlier
    
    
    oc create -f pod.yaml
    
  7. Verificare che il pod sia in esecuzione nel cluster.

    oc get pods
    
    NAME                          READY   STATUS    RESTARTS   AGE
    my-deployment-58dd7c89b6-8zdcl   1/1     Running   0          4m50s
    
  8. Ora che hai creato il pod, accedi al pod e crea un file di testo da utilizzare per lo snapshot.

    oc exec -it POD_NAME -- /bin/bash
    

    Esempi di comandi per creare un nuovo file di testo.

    root@my-deployment-58dd7c89b6-8zdcl:/# cd myvolumepath/
    root@my-deployment-58dd7c89b6-8zdcl:/myvolumepath# echo "hi" > new.txt
    root@my-deployment-58dd7c89b6-8zdcl:/myvolumepath# exit
    

Creazione di un'istantanea del volume

Dopo aver creato una distribuzione e un PVC, è possibile creare le istantanee del volume.

  1. Assicuratevi di avere Operatore di istantanea delle azioni autorizzazioni in IAM.

  2. Crea un'istantanea del volume nel tuo cluster utilizzando la classe ibmc-vpcfile-snapshot-delete snapshot distribuita quando hai abilitato il componente aggiuntivo. Salvate la seguente configurazione di VolumeSnapshot in un file chiamato snapvol.yaml.

    apiVersion: snapshot.storage.k8s.io/v1
    kind: VolumeSnapshot
    metadata:
      name: snapshot-csi-file-pvc
    spec:
      volumeSnapshotClassName: ibmc-vpcfile-snapshot-delete
      source:
        persistentVolumeClaimName: csi-file-pvc
    
    oc create -f snapvol.yaml
    
  3. Verificare che lo snapshot sia pronto per l'uso.

    oc get volumesnapshots
    

    Esempio di output dove READYTOUSE è true.

    NAME                            READYTOUSE   SOURCEPVC              SOURCESNAPSHOTCONTENT   RESTORESIZE   SNAPSHOTCLASS SNAPSHOTCONTENT                                    CREATIONTIME   AGE
    ibmc-vpcfile-snapshot-delete   true         csi-file-pvc                           10Gi           ibmc-vpcfile-snapshot-delete   snapcontent-9c374fbf-43a6-48d6-afc5-e76e1ab7c12b   18h            18h
    

Ripristino da un'istantanea del volume

Dopo aver distribuito l'istantanea del volume, è possibile ripristinare i dati su un nuovo volume utilizzando l'istantanea. La creazione di un PVC provvede in modo dinamico a un nuovo volume con dati snapshot.

  1. Crea un secondo PVC che faccia riferimento alla tua snapshot del volume.

    apiVersion: v1
    kind: PersistentVolumeClaim
    metadata:
      name: restore-pvc
    spec:
      storageClassName: ibmc-vpc-file-min-iops
      dataSource:
        name: snapshot-csi-file-pvc
        kind: VolumeSnapshot
        apiGroup: snapshot.storage.k8s.io
      accessModes:
        - ReadWriteMany
      resources:
        requests:
          storage: 10Gi
    
  2. Verificare che il PVC sia stato creato e sia in uno Bound stato.

    oc get pvc
    
    NAME           STATUS   VOLUME                                     CAPACITY   ACCESS MODES   STORAGECLASS             VOLUMEATTRIBUTESCLASS   AGE
    csi-file-pvc   Bound    pvc-9873bd7e-41a8-4234-a9bf-271b8ca7e4f9   10Gi       RWM            ibmc-vpc-file-min-iops   <unset>                 9m16s
    restore-pvc    Bound    pvc-04dc8d6c-ac75-48b1-989d-ed67deb35911   10Gi       RWM            ibmc-vpc-file-min-iops   <unset>                 116s
    
  3. Creare un secondo file di configurazione YAML per una distribuzione che monti il PVC creato.

    apiVersion: apps/v1
    kind: Deployment
    metadata:
      name: restore-pod
      labels:
        app: restore-pod
    spec:
      replicas: 1
      selector:
        matchLabels:
          app: restore-pod
      template:
        metadata:
          labels:
            app: restore-pod
        spec:
          containers:
          - image: nginx # Your containerized app image
            name: container-name
            volumeMounts:
            - mountPath: /myvolumepath  # Mount path for pvc from container
              name: my-vol # Volume mount name
          volumes:
          - name: my-vol  # Volume resource name
            persistentVolumeClaim:
            claimName: restore-pvc   # The name of the PVC that you created earlier
    
    oc create -f restore-pod.yaml
    
  4. Verifica che il pod sia stato creato.

    oc get pods
    
    NAME                          READY   STATUS    RESTARTS   AGE
    restore-pod-1                      1/1     Running   0          30m
    pod-2                     1/1     Running   0          46h
    
  5. Accedi al pod appena creato e verifica che il file di testo di esempio creato in precedenza sia stato salvato nel nuovo pod.

    oc exec -it POD_NAME -- /bin/bash
    root@POD_NAME :/# cd myvolumepath/
    root@POD_NAME :/myvolumepath# ls
    lost+found  new.txt
    root@POD_NAME :/myvolumepath# cat new.txt
    

    Output di esempio

    hi
    

Ripristino di istantanee statiche

Per ripristinare un'istantanea statica, completare i seguenti passaggi.

  1. Accedi al tuo account. Se applicabile, specifica il gruppo di risorse appropriato. Imposta il contesto per il tuo cluster.

  2. Ottieni l'istantanea CRN utilizzando

    ibmcloud is share-snapshot <share-id> <share-snapshot-id> | grep CRN
    

    Output di esempio

    CRN  crn:v1:staging:public:is:us-south-3:a/77f2bceddaeb577dcaddb4073fe82c1c::share-snapshot:r134-1b3af00c-7a07-4ba7-b005-f6723c5b5e98/r134-164521b1-f5c1-4968-9605-a7aaa7e6cd2f
    
  3. Creare una risorsa VolumeSnapshotContent. Salva la seguente configurazione in un file denominato volsnapcontent.yaml.

    apiVersion: snapshot.storage.k8s.io/v1
    kind: VolumeSnapshotContent
    metadata:
      name: static-file-snapshot-cnt
    spec:
      volumeSnapshotClassName: ibmc-vpcfile-snapshot-retain
      deletionPolicy: Retain
      driver: vpc.file.csi.ibm.io
      source:
        snapshotHandle: crn:v1:staging:public:is:us-south-3:a/77f2bceddaeb577dcaddb4073fe82c1c::share-snapshot:r134-1b3af00c-7a07-4ba7-b005-f6723c5b5e98/r134-164521b1-f5c1-4968-9605-a7aaa7e6cd2f  # Enter the CRN of the snapshot you created earlier. For example crn:v1:public:is:us-south:a/8ee729d7f903db130b00257d91b6977f::snapshot:r134-64c3ad8e-786e-4f54-9b63-388615811ba6
      volumeSnapshotRef:
        name: static-file-snapshot
        namespace: default
    
    oc apply -f volsnapcontent.yaml
    

    Output di esempio

    volumesnapshot.snapshot.storage.k8s.io/crossaccount-snapshot created
    
  4. Crea un VolumeSnapshot. Salva la seguente configurazione in un file denominato volsnap.yaml.

    apiVersion: snapshot.storage.k8s.io/v1
    kind: VolumeSnapshot
    metadata:
      name: static-file-snapshot
      namespace: default
    spec:
      volumeSnapshotClassName: ibmc-vpcfile-snapshot-retain
      source:
        volumeSnapshotContentName: static-file-snapshot-cnt # Enter the name of the VolumeSnapshotContent that you created in the previous step.
    
    oc apply -f volsnap.yaml
    
  5. Creare un PVC. Salva la seguente configurazione in un file denominato pvc2.yaml.

    apiVersion: v1
    kind: PersistentVolumeClaim
    metadata:
      name: restore-static-pvc
    spec:
      storageClassName: ibmc-vpc-file-min-iops
      dataSource:
        name: static-file-snapshot
        kind: VolumeSnapshot
        apiGroup: snapshot.storage.k8s.io
      accessModes:
        - ReadWriteMany
      resources:
        requests:
          storage: 10Gi
    
    oc apply -f pvc2.yaml
    

    Ridistribuisci la tua app.

    apiVersion: apps/v1
    kind: Deployment
    metadata:
      name: my-deployment
      labels:
        app: my-deployment
    spec:
      replicas: 1
      selector:
        matchLabels:
          app: my-deployment
      template:
        metadata:
          labels:
            app: my-deployment
        spec:
          containers:
          - image: nginx # Your containerized app image
            name: container-name
            volumeMounts:
            - mountPath: /myvolumepath  # Mount path for PVC
              name: my-vol # Volume mount name
          volumes:
          - name: my-vol  # Volume resource name
            persistentVolumeClaim:
              claimName: restore-static-pvc  # The name of the PVC you created earlier
    
    oc create -f dep2.yaml
    
  6. Verificare che il pod sia in esecuzione nel cluster.

    oc get pods
    
    NAME                          READY   STATUS    RESTARTS   AGE
    my-deployment-58dd7c89b6-8zdcl   1/1     Running   0          4m50s
    
  7. Accedi al pod appena creato e verifica che il file di testo di esempio creato in precedenza sia stato salvato nel nuovo pod.

    root@my-deployment-static-768f64ffcf-h6qft:/# cd myvolumepath/
    root@my-deployment-static-768f64ffcf-h6qft:/myvolumepath# ls
    new.txt
    root@my-deployment-static-768f64ffcf-h6qft:/myvolumepath# cat new.txt
    hi
    

Disattivazione delle istantanee

Per impostazione predefinita, la funzionalità snapshot è abilitata quando si utilizza il File Storage for VPC. Questa funzionalità può essere disattivata nella configmap addon-vpc-file-csi-driver-configmap nel kube-system namespace modificando il IsSnapshotEnabled in false. Si noti che con questa modifica nella configmap, qualsiasi snapshot creato fallisce con il messaggio: CreateSnapshot functionality is disabled.

  1. Salva la configmap corrente dal tuo cluster sul tuo computer locale.

    oc get cm -n kube-system addon-vpc-file-csi-driver-configmap -o yaml >> snapshotconfigmap.yaml
    
  2. Modificare il parametro IS_SNAPSHOT_ENABLED in false.

    IS_SNAPSHOT_ENABLED:false
    
  3. Salvare il file e applicare le modifiche.

    oc apply -f snapshotconfigmap.yaml