You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: content/blog/how-to-backup-and-restore-stateful-applications-on-kubernetes-using-kasten-k10-in-hpe-greenlake-for-private-cloud-enterprise.md
+54-31Lines changed: 54 additions & 31 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,7 +1,7 @@
1
1
---
2
2
title: How to backup and restore stateful applications on Kubernetes using
3
3
Kasten K10 in HPE GreenLake for Private Cloud Enterprise
4
-
date: 2024-01-18T07:33:24.381Z
4
+
date: 2024-01-26T10:07:05.982Z
5
5
author: Guoping Jia
6
6
authorimage: /img/guoping.png
7
7
disable: false
@@ -13,7 +13,7 @@ tags:
13
13
- HPE GreenLake for Private Cloud Enterprise
14
14
- hpe-greenlake-for-private-cloud-enterprise
15
15
---
16
-
This blog post describes how to backup and restore using Kasten K10 the stateful applications running in a Kubernetes (K8s) cluster in HPE GreenLake for Private Cloud Enterprise. Using pre-installed HPE CSI driver for K8s in the cluster, Kasten K10 works seamlessly for
16
+
This blog post describes how to backup and restore the stateful applications running in a Kubernetes (K8s) cluster using Kasten K10 in HPE GreenLake for Private Cloud Enterprise. Using pre-installed HPE CSI driver for K8s in the cluster, Kasten K10 works seamlessly for
17
17
18
18
### Prerequisites
19
19
@@ -23,6 +23,7 @@ Before starting, make sure you meet the following requirements:
23
23
24
24
* A K8s cluster, being provisioned in HPE GreenLake for Private Cloud Enterprise
25
25
* The kubectl CLI tool, together with the kubeconfig file for accessing the K8s cluster
26
+
* The [Helm](https://helm.sh/docs/intro/install/) CLI tool, version 3.12.1 or later
26
27
* The optional mysql CLI tool, for accessing the deployed sample MySQL database service
Following the [Kasten K10 installation page](https://docs.kasten.io/latest/index.html), the Kasten K10 can be installed to the K8s cluster using the following commands using helm:
103
+
Following the [Kasten K10 installation page](https://docs.kasten.io/latest/index.html), the Kasten K10 can be installed to the cluster with the following commands using helm:
After all the Pods are in running states, edit the service *gateway* to change its service type from *ClusterIP* to *NodePort*. This will generate a service port and expose the service via the configured gatway host name plus the generated the port.
155
+
After all the Pods are in running states, edit the service *gateway* to change its service type from *ClusterIP* to *NodePort*. This will generate a service port and expose the service via the configured gatway host name plus the generated port.
155
156
156
157
```markdown
157
-
$ kubectl edit svc gateway -n kasten-io
158
+
$ kubectl edit svc gateway -n kasten-io
158
159
…
159
160
spec:
160
161
clusterIP: 10.102.36.25
@@ -203,7 +204,7 @@ In order to show backup and restore process, an MySQL database from [my GitHu
203
204
1. Install MySQL database
204
205
205
206
206
-
MySQL database requires a persistent volume to store data. Here is the PVC YAML manifest file:
207
+
MySQL database requires a persistent volume to store data. Here is the PVC YAML manifest file*mysql-pvc.yaml* in the repo's *base* folder:
207
208
208
209
```markdown
209
210
$ cat mysql-app/base/mysql-pvc.yaml
@@ -222,7 +223,7 @@ spec:
222
223
storage: 1Gi
223
224
```
224
225
225
-
The YAML manifest files in the folder *base* will be used to install the MySQL application using [Kustomize](https://kustomize.io/).
226
+
This PVC file, together with other YAML manifest files in the folder *base*, will be used to install the MySQL database using [Kustomize](https://kustomize.io/).
226
227
227
228
```markdown
228
229
$ tree mysql-app/base
@@ -233,7 +234,7 @@ mysql-app
233
234
└── mysql-pvc.yaml
234
235
```
235
236
236
-
The file kustomization.yaml lists all YAML files in its resources section, together with the secret generator for MySQL password:
237
+
The file *kustomization.yaml* lists all YAML files in its resources section, together with the secret generator for MySQL password:
237
238
238
239
```markdown
239
240
$ cat mysql-app/base/kustomization.yaml
@@ -247,9 +248,9 @@ resources:
247
248
- mysql-pvc.yaml
248
249
```
249
250
250
-
Typing below command to install the MySQL application to the namespace *mysql*:
251
+
Typing below command to install the MySQL database to the namespace *mysql*:
251
252
252
-
```markdown
253
+
```shell
253
254
$ kubectl apply -k mysql-app/base
254
255
namespace/mysql created
255
256
secret/mysql-pass-m62cbhd9kf created
@@ -271,7 +272,7 @@ NAME DESIRED CURRENT READY AGE
271
272
replicaset.apps/mysql-6974b58d48 1 1 1 24s
272
273
```
273
274
274
-
You can check the PV and the PVC created as part of application deployment:
275
+
You can check the PV and the PVC created as part of database deployment:
275
276
276
277
```markdown
277
278
$ kubectl get persistentvolumes
@@ -297,7 +298,7 @@ Handling connection for 42281
297
298
298
299
The deployed MySQL database service can be accessed by typing the following mysql command:
299
300
300
-
```markdown
301
+
```shell
301
302
$ mysql -h 127.0.0.1 -uroot -pCfeDemo@123 -P 42281
302
303
Welcome to the MariaDB monitor. Commands end with ; or \g.
303
304
Your MySQL connection id is 3
@@ -321,7 +322,7 @@ MySQL [(none)]> show databases;
321
322
3. Populate MySQL database
322
323
323
324
324
-
The MySQL database repo has the test folder that contains a list of scripts for populating data records and testing the contents:
325
+
The MySQL application repo has the *test* folder that contains a list of scripts for populating data records and testing the contents:
325
326
326
327
```markdown
327
328
$ tree mysql-app/test
@@ -340,9 +341,9 @@ mysql-app/test
340
341
└── test_employees_sha.sql
341
342
```
342
343
343
-
Typing the following command to populate a sample *employees* data to the database:
344
+
Typing the following command to populate a sample *employees* data to the MySQL database:
344
345
345
-
```markdown
346
+
```shell
346
347
$ cd mysql-app/test
347
348
$ mysql -h 127.0.0.1 -uroot -pCfeDemo@123 -P 42281 < employees.sql
348
349
INFO
@@ -365,9 +366,9 @@ data_load_time_diff
365
366
NULL
366
367
```
367
368
368
-
The added sample data records *employees* can be checked and verified by below commands:
369
+
The added sample data records *employees* can be checked and verified by running below commands:
369
370
370
-
```markdown
371
+
```shell
371
372
$ mysql -h 127.0.0.1 -uroot -pCfeDemo@123 -P 42281
372
373
Welcome to the MariaDB monitor. Commands end with ; or \g.
In order to back up the MySQL database, go to the Kasten K10 Dashboard and click the Applications. Find the deployed MySQL application *mysql* from the application list and expand its menu. Then click *Snapshot* button.
443
+
In order to back up the MySQL database, go to the Kasten K10 Dashboard and click the Applications. Find the deployed MySQL database *'mysql'* from the application list and expand its menu. Then click *Snapshot* button.
443
444
444
445

445
446
446
447
Using all the default options from **Snapshot *mysql***, click *Snapshot Application* button:
447
448
448
449

449
450
450
-
The snapshot of the MySQL database will be started that takes a few seconds. Go back to the Dashboard, you should see the completed *Backup* entry under **Actions**:
451
+
The snapshot of the MySQL database will be started that takes a few seconds. Go back to the K10 Dashboard, you should see the completed *Backup* entry under **Actions**:
451
452
452
453

453
454
454
-
You can also check the **Data Usage* page to see the data used by application backups:
455
+
You can also check the **Data Usage** page to see the data used by database backups:
455
456
456
457

457
458
459
+
In the cluster, after snapshot of the MySQL database, you can check there is a *VolumeSnapshot*_k10-csi-snap-ltxzrwxgp6r5pwkp_ created from the PVC *mysql-pvc* in the namespace *mysql*, together with a *VolumeSnapshotContent* object created at cluster level:
460
+
461
+
```shell
462
+
463
+
$ k get volumesnapshot -n mysql
464
+
NAME READYTOUSE SOURCEPVC SOURCESNAPSHOTCONTENT RESTORESIZE SNAPSHOTCLASS SNAPSHOTCONTENT CREATIONTIME AGE
NAME READYTOUSE RESTORESIZE DELETIONPOLICY DRIVER VOLUMESNAPSHOTCLASS VOLUMESNAPSHOT VOLUMESNAPSHOTNAMESPACE AGE
469
+
snapcontent-f3890356-d47f-4b36-a7e4-eb4c5792ec59 true 1073741824 Delete csi.hpe.com gl-sbp-frank-gl1-sstor01 k10-csi-snap-ltxzrwxgp6r5pwkp mysql 6d12h
470
+
```
471
+
472
+
This volume snapshot can be used for MySQL database restore.
473
+
458
474
### Restore MySQL database
459
475
460
-
I will first delete some table from MySQL database to simulate a loss of data. Then, I will perform the database recovery from the application backup.
476
+
Before showing the database restore, I will first delete some table from MySQL database to simulate a loss of data. Then, I will perform the database recovery using the Kasten K10.
461
477
462
478
#### Delete table
463
479
464
480
Delete data from the table *departments*:
465
481
466
-
```markdown
482
+
```shell
467
483
$ mysql -h 127.0.0.1 -uroot -pCfeDemo@123 -P 42281 -Demployees
468
484
Reading table information for completion of table and column names
469
485
You can turn off this feature to get a quicker startup with -A
@@ -496,10 +512,10 @@ MySQL [employees]> delete from departments;
496
512
Query OK, 9 rows affected (1,523 sec)
497
513
```
498
514
499
-
Then re-run the script *test_employees_sha.sql*. It will show the failures of *CRC* and *count* which indicate the loss of data in the database:
515
+
If re-run the testing script *test_employees_sha.sql*, it will show the failures of *CRC* and *count* which indicate the loss of data in the MySQL database:
500
516
501
-
```markdown
502
-
$ mysql -h 127.0.0.1 -uroot -pCfeDemo@123 -P 41797 -t <test_employees_sha.sql
517
+
```shell
518
+
$ mysql -h 127.0.0.1 -uroot -pCfeDemo@123 -P 42281 -t <test_employees_sha.sql
In order to restore the MySQL database, go to application list of the Kasten K10 Dashboard and expand the menu of *mysql* application. Then click *Restore* button.
569
+
In order to restore the MySQL database, go to again the Kasten K10 Dashboard, locate the MySQL database *'mysql'* from the application list, expand the menu of *mysql*, then click *Restore* button:
554
570
555
571

556
572
557
-
Select a restore point from the list and click it. The *Restore Point* page will show up:
573
+
Select a restore point from the list and click it. The **Restore Point** page will show up:
558
574
559
575

560
576
561
577
Use all the default options from **Restore Point** and click *Restore* button:
562
578
563
579

564
580
565
-
The restore of the MySQL database will be started from the selected restore point. It will take a few seconds. Go back to the Dashboard, you should see the completed *Restore* entry under **Actions**:
581
+
The restore of the MySQL database will be started from the selected restore point. It will take a few seconds. Go back to the Kasten K10 Dashboard, you should see the completed *Restore* entry under **Actions**:
566
582
567
583

568
584
569
-
Re-run the script *test_employees_sha.sql*. You should see the test ends without showing any issue. It indicates the MySQL database gets recovered from its backup:
585
+
Connect to the MySQL database service and re-run the testing script *test_employees_sha.sql*. You should see the testing script now reports everything is *OK*:
This indicates the MySQL database gets recovered from its backup and MySQL database data is back !
651
+
652
+
### Summary
653
+
654
+
In this blog post, I described persistent volumes, volume snapshots, and the CSI driver in K8s. Using HPE CSI driver for K8s, I demonstrated how to create a volume snapshot of a MySQL database and how to restore database using the created volume snapshot in the cluster. The volume snapshot capability can be easily integrated with third-party tools like Kasten K10 by Veeam as an automatic backup and recovery solution. It can significantly simplify the process and enhance the robustness of data management in a K8s cluster.
655
+
656
+
You can keep coming back to the [HPE Developer blog](https://developer.hpe.com/blog/) to learn more about HPE GreenLake for Private Cloud Enterprise.
0 commit comments