Examples of Velero backup and restoration tests

Prev Next

Available in VPC

This is an example where you test if the backup and restoration features work properly, based on what was explained in Velero plugin.

nginx deployment example

Deploy nginx first so you can execute the backup and restoration test example.

The following is the example for deploying nginx.

  1. Save the code shown below in the nginx-example.yaml file.
    # nginx-example.yaml
    ---
    apiVersion: v1
    kind: Namespace
    metadata:
      name: nginx-example
      labels:
        app: nginx
    ---
    
    kind: PersistentVolumeClaim
    apiVersion: v1
    metadata:
      name: nginx-log-pvc
      namespace: nginx-example
      labels:
        app: nginx
    spec:
      storageClassName: nks-block-storage
      accessModes:
        - ReadWriteOnce
      resources:
        requests:
          storage: 10Gi
    
    ---
    apiVersion: apps/v1
    kind: Deployment
    metadata:
      name: nginx-deploy
      namespace: nginx-example
      labels:
        app: nginx
    spec:
      replicas: 1
      selector:
        matchLabels:
          app: nginx
      template:
        metadata:
          labels:
            app: nginx
        spec:
          volumes:
            - name: nginx-logs
              persistentVolumeClaim:
               claimName: nginx-log-pvc
          containers:
          - image: nks.kr.ncr.ntruss.com/nginx:1.9
            name: nginx
            ports:
            - containerPort: 80
            volumeMounts:
            - mountPath: "/var/log/nginx"
              name: nginx-logs
              readOnly: false
    
  2. Run the following command to deploy nginx to the cluster.
    $ kubectl --kubeconfig $KUBE_CONFIG apply -f nginx-example.yaml
    
  3. Run the commands below in order to check the pod and forward the port in order to be able to access nginx.
    $ kubectl --kubeconfig $KUBE_CONFIG get pods --namespace nginx-example
    
    $ kubectl --kubeconfig $KUBE_CONFIG --namespace nginx-example port-forward pod/nginx-deploy-749cb5ff64-x8j4w 9191:80
    
  4. Enter the forwarded port in a browser or use the curl command to access nginx, and check if the page is displayed correctly.

Example of backup through Velero

The following is an example where you perform a backup through Velero.

  1. Run the following commands in order to check the logs in the NGINX container, and exit the container.
    $ kubectl --kubeconfig $KUBE_CONFIG exec -it nginx-deploy-749cb5ff64-x8j4w --namespace nginx-example -- /bin/bash
    
    nginx-deploy-749cb5ff64-x8j4w:/# cat /var/log/nginx/access.log
    
    $ exit
    
  2. Run the following command to create a backup of the current cluster status.
    $ velero --kubeconfig $KUBE_CONFIG backup create nginx-backup --selector app=nginx
    
    • Save nginx's Kubernetes object in Object Storage, and create a snapshot of the PersistentVolume that you created when deploying nginx.
    • The --selector app=nginx option designates the Velero server to only back up Kubernetes objects that have the app=nginx label set through the Label Selector.

Example of restoration through Velero

The following is an example where you perform a restoration using the data backed up by Velero.

  1. Run the following commands in order to delete the nginx-example namespace, and check if it's deleted properly.
    $ kubectl --kubeconfig $KUBE_CONFIG delete namespace nginx-example
    
    $ kubectl --kubeconfig $KUBE_CONFIG get deployments --namespace=nginx-example
    
  2. Run the command shown below to perform restoration.
velero --kubeconfig $KUBE_CONFIG restore create --from-backup nginx-backup
  1. Run the following commands individually to check if the restoration was performed properly.
    • Check the status of the restored deployment
    $ kubectl --kubeconfig $KUBE_CONFIG get deployments --namespace=nginx-example
    
    • Check if PersistentVolume is created
    $ kubectl --kubeconfig $KUBE_CONFIG get pvc --namespace=nginx-example
    
    • Run the following commands in order to check if the log displayed is the same as before restoration.
    $ kubectl --kubeconfig $KUBE_CONFIG get pods --namespace nginx-example
    
    $ kubectl --kubeconfig $KUBE_CONFIG exec -it nginx-deploy-749cb5ff64-x8j4w --namespace nginx-example -- /bin/bash
    
    $ nginx-deploy-749cb5ff64-x8j4w:/# cat /var/log/nginx/access.log