1 .. This work is licensed under a Creative Commons Attribution 4.0
2 .. International License. http://creativecommons.org/licenses/by/4.0
3 .. Copyright © 2017-2020 Aarna Networks, Inc.
6 .. Github web page to download the latest version of velero open source tool
7 .. _Velero official website: https://velero.io
8 .. Reference link with more details on Instructions for setting up Velero server
9 .. _Setup Velero Server: https://velero.io/docs/v1.5/contributions/minio/#set-up-server
11 Backup and Restore Solution
12 ###########################
14 Problem Statement and Requirement (User Story)
15 ==============================================
17 As an ONAP Operator- We require the ability to backup and restore ONAP state data, We want to have Disaster recovery solution for ONAP deployment done over K8.
19 Basic Use case would be
21 1) Add/Update/Modify the POD Data or DB Data.
22 2) Simulate a Disaster
23 3) Restore using Backup.
24 4) POD Data/DB entries should be recovered.
29 Narrowed down upon a tool which can be used for K8 Backup and Restoration for ONAP deployments named as Velero (formerly Heptio-ARK)
31 Velero is an Opensource tool to back up and restore your Kubernetes cluster resources and persistent volumes. Velero lets you:
33 * Take backups of your cluster and restore in case of loss.
34 * Copy cluster resources across cloud providers. NOTE: Cloud volume migrations are not yet supported.
35 * Replicate your production environment for development and testing environments.
39 * A server that runs on your cluster
40 * A command-line client that runs locally
44 .. figure:: Backup-And-Restore.png
52 - Access to a Kubernetes cluster, version 1.7 or later.
53 - A DNS server on the cluster
55 - Labels should be defined there.
59 Velero is an open source tool to safely backup and restore, perform disaster recovery, and migrate Kubernetes cluster resources and persistent volumes.
61 Go to `Velero official website`_ and Click on DOWNLOAD VELERO BUTTON. It will take you to the github page to download the latest version of velero. Scroll down to the
62 bottom of the page and choose the binary corresponding to the OS where you want to run the Velero on.
64 Install and configure Velero Server and Client
65 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
67 To configure the latest version (1.5.2) of velero on Linux machine, please follow the below steps.
69 Run the below command. It will download the velero to your machine
73 wget https://github.com/vmware-tanzu/velero/releases/download/v1.5.2/velero-v1.5.2-linux-amd64.tar.gz
75 Extract it using below command
79 tar -zxvf velero-v1.5.2-linux-amd64.tar.gz
81 Once extracted, goto the directory "velero-v1.5.2-linux-amd64"
85 cd velero-v1.5.2-linux-amd64
87 Inside this you will find a directory called examples and then minio, just go inside it
93 Inside this you will find a file called 00-minio-deployment.yaml. Open this file using any editor and look for Velero service yaml portion, there you need to change
94 the type from ClusterIP to NodePort
96 Once made the changes then run the below command to deploy velero server
100 kubectl apply -f 00-minio-deployment.yaml
102 This will configure the Velero with Minio. Minio is nothing but local storage with aws s3 capabilities. Velero support many cloud providers as well like Azure,AWS,GCP
103 etc. You can configure any of those.
105 Once the Velero deployment is done, then we need to install and configure the velero server component using velero cli.
107 Create a Velero-specific credentials file (credentials-velero) in your local directory
112 aws_access_key_id=minio
113 aws_secret_access_key=minio123
115 Start the server and the local storage service. In the Velero directory, run
121 --plugins velero/velero-plugin-for-aws:v1.0.0 \
123 --secret-file ./credentials-velero \
124 --use-volume-snapshots=false \
125 --backup-location-config region=minio,s3ForcePathStyle="true",s3Url=http://minio.velero.svc:9000
128 Refer this for more details: `Setup Velero Server`_
132 As Labels need to be defined, because that is a unique identity which we need to have for any backup of our k8 containers,
134 So in OOM code, Where -ever we don't have labels, We need to define that whether its configmap or secret, for eg below:-
138 app: {{ include "common.name" . }}
139 chart: {{ .Chart.Name }}-{{ .Chart.Version | replace "+" "_" }}
140 release: {{ .Release.Name }}
141 heritage: {{ .Release.Service }}
143 Running Velero Example (Backup and Restoration with Logs)
144 ---------------------------------------------------------
146 1) Install SO component
147 ~~~~~~~~~~~~~~~~~~~~~~~
151 This is an optional step, if you have already installed SO or all other components of ONAP then you can skip this step.
153 Below is the example of installing SO component using helm
157 helm install so -n bkup --namespace test3
161 LAST DEPLOYED: Fri Jul 20 06:59:09 2018
171 NAME READY STATUS RESTARTS AGE
173 bkup-so-db-744fccd888-w67zk 0/1 Init:0/1 0 0s
175 bkup-so-7668c746c-vngk8 0/2 Init:0/1 0 0s
181 bkup-so-db Opaque 1 0s
191 so-docker-file-configmap 1 0s
193 so-filebeat-configmap 1 0s
195 so-log-configmap 11 0s
198 ==> v1/PersistentVolume
200 NAME CAPACITY ACCESS MODES RECLAIM POLICY STATUS CLAIM STORAGECLASS REASON AGE
202 bkup-so-db 2Gi RWX Retain Bound test3/bkup-so-db 0s
205 ==> v1/PersistentVolumeClaim
207 NAME STATUS VOLUME CAPACITY ACCESS MODES STORAGECLASS AGE
209 bkup-so-db Bound bkup-so-db 2Gi RWX 0s
214 NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
216 so-db NodePort 10.43.63.96 <none> 3306:30252/TCP 0s
218 so NodePort 10.43.59.93 <none> 8080:30223/TCP,3904:30225/TCP,3905:30224/TCP,9990:30222/TCP,8787:30250/TCP 0s
221 ==> v1beta1/Deployment
223 NAME DESIRED CURRENT UP-TO-DATE AVAILABLE AGE
225 bkup-so-db 1 1 1 0 0s
232 Get the application URL by running these commands
236 export NODE_PORT=$(kubectl get --namespace test3 -o jsonpath="{.spec.ports[0].nodePort}" services so)
238 export NODE_IP=$(kubectl get nodes --namespace test3 -o jsonpath="{.items[0].status.addresses[0].address}")
240 echo http://$NODE_IP:$NODE_PORT
242 2) Checking status of pod
243 ~~~~~~~~~~~~~~~~~~~~~~~~~
247 kubectl get pods --all-namespaces | grep -i so
249 NAMESPACE NAME READY STATUS RESTARTS AGE
251 test3 bkup-so-7668c746c-vngk8 2/2 Running 0 8m
253 test3 bkup-so-db-744fccd888-w67zk 1/1 Running 0 8m
256 3) Creating backup of deployment
257 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
259 Here I am using selector label as release name
263 ./velero backup create so-backup --selector release=bkup
265 Backup request "so-backup" submitted successfully.
267 Run `velero backup describe so-backup` for more details.
270 4) Checking backup logs
271 ~~~~~~~~~~~~~~~~~~~~~~~
275 ./velero backup describe so-backup
304 Label selector: release=bkup
316 Backup Format Version: 1
318 Started: 2018-07-20 07:09:51 +0000 UTC
320 Completed: 2018-07-20 07:09:53 +0000 UTC
322 Expiration: 2018-08-19 07:09:51 +0000 UTC
324 Validation errors: <none>
326 Persistent Volumes: <none included>
328 5) Simulating a disaster
329 ~~~~~~~~~~~~~~~~~~~~~~~~
333 helm delete --purge bkup
335 release "bkup" deleted
337 6)Restoring the kubernetes resources using velero
338 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
342 ./velero restore create --from-backup so-backup
344 Restore request "so-backup-20180720071236" submitted successfully.
346 Run `velero restore describe so-backup-20180720071236` for more details.
349 7) Checking restoration logs
350 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
354 ./velero restore describe so-backup-20180720071236
356 Name: so-backup-20180720071236
378 Excluded: nodes, events, events.events.k8s.io, backups.ark.heptio.com, restores.ark.heptio.com
383 Namespace mappings: <none>
385 Label selector: <none>
392 Validation errors: <none>
402 As we are using Minio which is local storage with aws s3 capabilities. Thus our all the backup files are being stored in locally in Minio Pod. Let's see where the backup files are being genreted.
406 kubectl get pod -n velero
407 NAME READY STATUS RESTARTS AGE
408 minio-d9c56ff5-cg8zp 1/1 Running 0 4d5h
409 minio-setup-ph8pk 0/1 Completed 0 4d5h
410 velero-74cdf64d76-t8wfs 1/1 Running 0 4d5h
414 kubectl exec -it -n velero minio-d9c56ff5-cg8zp ls storage/velero/backups/
418 kubectl exec -it -n velero minio-d9c56ff5-cg8zp ls storage/velero/backups/so-backup
419 so-backup-csi-volumesnapshotcontents.json.gz
420 so-backup-csi-volumesnapshots.json.gz
422 so-backup-podvolumebackups.json.gz
423 so-backup-resource-list.json.gz
424 so-backup-volumesnapshots.json.gz
436 NAME BACKUP STATUS WARNINGS ERRORS CREATED SELECTOR
438 so-backup-20180720071236 so-backup Completed 0 0 2018-07-20 07:12:36 +0000 UTC <none>
441 10) Check the pod status
442 ~~~~~~~~~~~~~~~~~~~~~~~~
446 kubectl get pods --all-namespaces | grep -i so
448 NAMESPACE NAME READY STATUS RESTARTS AGE
450 test3 bkup-so-7668c746c-vngk8 2/2 Running 0 8m
452 test3 bkup-so-db-744fccd888-w67zk 1/1 Running 0 8m
456 Another Example with DB and PV Backup
457 -------------------------------------
459 APPC component backup and restoration
460 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
464 kubectl get pods --all-namespaces | grep -i appc
465 onap bk-appc-0 1/2 Running 0 1m
466 onap bk-appc-cdt-7cd6f6d674-5thwj 1/1 Running 0 1m
467 onap bk-appc-db-0 2/2 Running 0 1m
468 onap bk-appc-dgbuilder-59895d4d69-7rp9q 1/1 Running 0 1m
471 Creating dummy entry in db
472 ~~~~~~~~~~~~~~~~~~~~~~~~~~
476 kubectl exec -it -n default bk-appc-db-0 bash
477 Defaulting container name to appc-db.
478 Use 'kubectl describe pod/bk-appc-db-0 -n onap' to see all of the containers in this pod.
482 root@bk-appc-db-0:/# mysql -u root -p
484 Welcome to the MySQL monitor. Commands end with ; or \g.
485 Your MySQL connection id is 42
486 Server version: 5.7.23-log MySQL Community Server (GPL)
488 Copyright (c) 2000, 2018, Oracle and/or its affiliates. All rights reserved.
490 Oracle is a registered trademark of Oracle Corporation and/or its
491 affiliates. Other names may be trademarks of their respective
494 Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
500 Reading table information for completion of table and column names
501 You can turn off this feature to get a quicker startup with -A
504 Current database: mysql
508 mysql> select * from servers;
512 +-------------+----------+------+-----+---------+-------+
513 | Field | Type | Null | Key | Default | Extra |
514 +-------------+----------+------+-----+---------+-------+
515 | Server_name | char(64) | NO | PRI | | |
516 | Host | char(64) | NO | | | |
517 | Db | char(64) | NO | | | |
518 | Username | char(64) | NO | | | |
519 | Password | char(64) | NO | | | |
520 | Port | int(4) | NO | | 0 | |
521 | Socket | char(64) | NO | | | |
522 | Wrapper | char(64) | NO | | | |
523 | Owner | char(64) | NO | | | |
524 +-------------+----------+------+-----+---------+-------+
525 9 rows in set (0.00 sec)
527 mysql> insert into servers values ("test","ab","sql","user","pwd",1234,"test","wrp","vaib");
528 Query OK, 1 row affected (0.03 sec)
533 mysql> select * from servers;
534 +-------------+------+-----+----------+----------+------+--------+---------+-------+
535 | Server_name | Host | Db | Username | Password | Port | Socket | Wrapper | Owner |
536 +-------------+------+-----+----------+----------+------+--------+---------+-------+
537 | abc | ab | sql | user | pwd | 1234 | test | wrp | vaib |
538 +-------------+------+-----+----------+----------+------+--------+---------+-------+
539 1 row in set (0.00 sec)
547 root@bk-appc-db-0:/# exit
548 command terminated with exit code 127
549 kubectl get pods --all-namespaces | grep -i appc
550 onap bk-appc-0 1/2 Running 0 5m
551 onap bk-appc-cdt-7cd6f6d674-5thwj 1/1 Running 0 5m
552 onap bk-appc-db-0 2/2 Running 0 5m
553 onap bk-appc-dgbuilder-59895d4d69-7rp9q 1/1 Running 0 5m
556 Creating dummy file in APPC PV
557 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
560 kubectl exec -it -n onap bk-appc-0 bash
561 Defaulting container name to appc.
562 Use 'kubectl describe pod/bk-appc-0 -n onap' to see all of the containers in this pod.
566 root@bk-appc-0:/# cd /opt/opendaylight/current/daexim/
567 root@bk-appc-0:/opt/opendaylight/current/daexim# ls
568 root@bk-appc-0:/opt/opendaylight/current/daexim# ls
569 root@bk-appc-0:/opt/opendaylight/current/daexim#
570 root@bk-appc-0:/opt/opendaylight/current/daexim#
571 root@bk-appc-0:/opt/opendaylight/current/daexim# touch abc.txt
572 root@bk-appc-0:/opt/opendaylight/current/daexim# ls
574 root@bk-appc-0:/opt/opendaylight/current/daexim# exit
576 root@rancher:~/oom/kubernetes# kubectl get pods --all-namespaces | grep -i appc
577 onap bk-appc-0 1/2 Running 0 6m
578 onap bk-appc-cdt-7cd6f6d674-5thwj 1/1 Running 0 6m
579 onap bk-appc-db-0 2/2 Running 0 6m
580 onap bk-appc-dgbuilder-59895d4d69-7rp9q 1/1 Running 0 6m
583 Creating backup using velero
584 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
588 ./velero backup create appc-bkup1 --selector release=bk
589 Backup request "appc-bkup1" submitted successfully.
590 Run `velero backup describe appc-bkup1` for more details.
592 ./velero backup describe appc-bkup1
609 Label selector: release=bk
617 Backup Format Version: 1
619 Started: 2018-08-27 05:07:45 +0000 UTC
620 Completed: 2018-08-27 05:07:47 +0000 UTC
622 Expiration: 2018-09-26 05:07:44 +0000 UTC
624 Validation errors: <none>
626 Persistent Volumes: <none included>
629 Simulating disaster by deleting APPC
630 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
634 helm delete --purge bk
638 Restoration using velero
639 ~~~~~~~~~~~~~~~~~~~~~~~~
643 ./velero restore create --from-backup appc-bkup1
644 Restore request "appc-bkup1-20180827052651" submitted successfully.
645 Run `velero restore describe appc-bkup1-20180827052651` for more details.
650 Check the Restoration details immediately after restoration. Restoration process is in InProgress Phase. Please check the Phase.
654 ./velero restore describe appc-bkup1-20180827052651
655 Name: appc-bkup1-20180827052651
668 Excluded: nodes, events, events.events.k8s.io, backups.ark.heptio.com, restores.ark.heptio.com
671 Namespace mappings: <none>
673 Label selector: <none>
679 Validation errors: <none>
683 ./velero restore describe appc-bkup1-20180827052651
684 Name: appc-bkup1-20180827052651
697 Excluded: nodes, events, events.events.k8s.io, backups.ark.heptio.com, restores.ark.heptio.com
700 Namespace mappings: <none>
702 Label selector: <none>
708 Validation errors: <none>
711 Warnings: <error getting warnings: Get "http://minio.velero.svc:9000/velero/restores/dev-appc-1-20201108164330/restore-dev-appc-1-20201108164330-results.gz?X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Credential=minio%2F20201108%2Fminio%2Fs3%2Faws4_request&X-Amz-Date=20201108T183923Z&X-Amz-Expires=600&X-Amz-SignedHeaders=host&X-Amz-Signature=847bdbb0a76718220c40767c4837aa999a4da9ff1344e9b42d3c93f7009e6898": dial tcp: lookup minio.velero.svc on 127.0.0.53:53: no such host>
713 Errors: <error getting errors: Get "http://minio.velero.svc:9000/velero/restores/dev-appc-1-20201108164330/restore-dev-appc-1-20201108164330-results.gz?X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Credential=minio%2F20201108%2Fminio%2Fs3%2Faws4_request&X-Amz-Date=20201108T183923Z&X-Amz-Expires=600&X-Amz-SignedHeaders=host&X-Amz-Signature=847bdbb0a76718220c40767c4837aa999a4da9ff1344e9b42d3c93f7009e6898": dial tcp: lookup minio.velero.svc on 127.0.0.53:53: no such host>
715 This process might take some time to complete. When you check the Restoration details again after some time then the phase will show as Completed as shown below.
719 ./velero restore describe appc-bkup1-20180827052651
720 Name: appc-bkup1-20180827052651
733 Excluded: nodes, events, events.events.k8s.io, backups.ark.heptio.com, restores.ark.heptio.com
736 Namespace mappings: <none>
738 Label selector: <none>
744 Validation errors: <none>
746 Warnings: <error getting warnings: Get "http://minio.velero.svc:9000/velero/restores/dev-appc-1-20201108164330/restore-dev-appc-1-20201108164330-results.gz?X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Credential=minio%2F20201108%2Fminio%2Fs3%2Faws4_request&X-Amz-Date=20201108T183923Z&X-Amz-Expires=600&X-Amz-SignedHeaders=host&X-Amz-Signature=847bdbb0a76718220c40767c4837aa999a4da9ff1344e9b42d3c93f7009e6898": dial tcp: lookup minio.velero.svc on 127.0.0.53:53: no such host>
748 Errors: <error getting errors: Get "http://minio.velero.svc:9000/velero/restores/dev-appc-1-20201108164330/restore-dev-appc-1-20201108164330-results.gz?X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Credential=minio%2F20201108%2Fminio%2Fs3%2Faws4_request&X-Amz-Date=20201108T183923Z&X-Amz-Expires=600&X-Amz-SignedHeaders=host&X-Amz-Signature=847bdbb0a76718220c40767c4837aa999a4da9ff1344e9b42d3c93f7009e6898": dial tcp: lookup minio.velero.svc on 127.0.0.53:53: no such host>
757 NAME BACKUP STATUS WARNINGS ERRORS CREATED SELECTOR
758 appc-bkup-20180827045955 appc-bkup Completed 2 0 2018-08-27 04:59:52 +0000 UTC <none>
759 appc-bkup1-20180827052651 appc-bkup1 Completed 5 0 2018-08-27 05:26:48 +0000 UTC <none>
760 vid-bkp-20180824053001 vid-bkp Completed 149 2 2018-08-24 05:29:59 +0000 UTC <none>
762 Completed status means the Restoration is done successfully.
764 Restoration successful
765 ~~~~~~~~~~~~~~~~~~~~~~
769 kubectl get pods --all-namespaces | grep -i appc
770 onap bk-appc-0 1/2 Running 0 26m
771 onap bk-appc-cdt-7cd6f6d674-5thwj 1/1 Running 0 26m
772 onap bk-appc-db-0 2/2 Running 0 26m
773 onap bk-appc-dgbuilder-59895d4d69-7rp9q 1/1 Running 0 26m
774 kubectl exec -it -n onap bk-appc-db-0 bash
775 Defaulting container name to appc-db.
776 Use 'kubectl describe pod/bk-appc-db-0 -n onap' to see all of the containers in this pod.
782 Restoration of db successful
783 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
787 root@bk-appc-db-0:/# mysql -u root
788 ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)
789 root@bk-appc-db-0:/# mysql -u root -p
791 Welcome to the MySQL monitor. Commands end with ; or \g.
792 Your MySQL connection id is 335
793 Server version: 5.7.23-log MySQL Community Server (GPL)
795 Copyright (c) 2000, 2018, Oracle and/or its affiliates. All rights reserved.
797 Oracle is a registered trademark of Oracle Corporation and/or its
798 affiliates. Other names may be trademarks of their respective
801 Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
804 Reading table information for completion of table and column names
805 You can turn off this feature to get a quicker startup with -A
808 Current database: mysql
810 mysql> select * from servers;
811 +-------------+------+-----+----------+----------+------+--------+---------+-------+
812 | Server_name | Host | Db | Username | Password | Port | Socket | Wrapper | Owner |
813 +-------------+------+-----+----------+----------+------+--------+---------+-------+
814 | abc | ab | sql | user | pwd | 1234 | test | wrp | vaib |
815 +-------------+------+-----+----------+----------+------+--------+---------+-------+
816 1 row in set (0.00 sec)
820 root@bk-appc-db-0:/# exit
824 Restoration of PV successful
825 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
829 kubectl get pods --all-namespaces | grep -i appc
830 onap bk-appc-0 1/2 Running 0 27m
831 onap bk-appc-cdt-7cd6f6d674-5thwj 1/1 Running 0 27m
832 onap bk-appc-db-0 2/2 Running 0 27m
833 onap bk-appc-dgbuilder-59895d4d69-7rp9q 1/1 Running 0 27m
834 kubectl exec -it -n onap bk-appc-0 bash
835 Defaulting container name to appc.
836 Use 'kubectl describe pod/bk-appc-0 -n onap' to see all of the containers in this pod.
841 root@bk-appc-0:/# cd /opt/opendaylight/current/daexim/
842 root@bk-appc-0:/opt/opendaylight/current/daexim# ls
844 root@bk-appc-0:/opt/opendaylight/current/daexim#
845 root@bk-appc-0:/opt/opendaylight/current/daexim#
846 root@bk-appc-0:/opt/opendaylight/current/daexim# exit
856 Using Schedules and Restore-Only Mode
858 If you periodically back up your cluster’s resources, you are able to return to a previous state in case of some unexpected mishap, such as a service outage.
863 Using Backups and Restores
865 Velero can help you port your resources from one cluster to another, as long as you point each Velero Config to the same cloud object storage.
868 https://github.com/vmware-tanzu/velero