Skip to content

Commit 94e628d

Browse files
committed
Update Blog “how-to-backup-and-restore-stateful-applications-on-kubernetes-using-kasten-k10-in-hpe-greenlake-for-private-cloud-enterprise”
1 parent 7a2f531 commit 94e628d

File tree

1 file changed

+54
-31
lines changed

1 file changed

+54
-31
lines changed

content/blog/how-to-backup-and-restore-stateful-applications-on-kubernetes-using-kasten-k10-in-hpe-greenlake-for-private-cloud-enterprise.md

Lines changed: 54 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
22
title: How to backup and restore stateful applications on Kubernetes using
33
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
55
author: Guoping Jia
66
authorimage: /img/guoping.png
77
disable: false
@@ -13,7 +13,7 @@ tags:
1313
- HPE GreenLake for Private Cloud Enterprise
1414
- hpe-greenlake-for-private-cloud-enterprise
1515
---
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
1717

1818
### Prerequisites
1919

@@ -23,6 +23,7 @@ Before starting, make sure you meet the following requirements:
2323

2424
* A K8s cluster, being provisioned in HPE GreenLake for Private Cloud Enterprise
2525
* 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
2627
* The optional mysql CLI tool, for accessing the deployed sample MySQL database service
2728

2829
### Kasten K10
@@ -99,7 +100,7 @@ gl-sbp-frank-gl1-sstor01 csi.hpe.com Delete 56d
99100

100101
### Install Kasten K10
101102

102-
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:
103104

104105
```shell
105106
$ helm repo add kasten https://charts.kasten.io/
@@ -151,10 +152,10 @@ prometheus-server-689ccf5f57-j9hpz 2/2 Running 0 15m
151152
state-svc-b4b996d9b-jnbrl 3/3 Running 0 15m
152153
```
153154

154-
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.
155156

156157
```markdown
157-
$ kubectl edit svc gateway -n kasten-io
158+
$ kubectl edit svc gateway -n kasten-io
158159
159160
spec:
160161
clusterIP: 10.102.36.25
@@ -203,7 +204,7 @@ In order to show backup and restore process, an MySQL database from [my GitHu
203204
1. Install MySQL database
204205

205206

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:
207208

208209
```markdown
209210
$ cat mysql-app/base/mysql-pvc.yaml
@@ -222,7 +223,7 @@ spec:
222223
storage: 1Gi
223224
```
224225

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/).
226227

227228
```markdown
228229
$ tree mysql-app/base
@@ -233,7 +234,7 @@ mysql-app
233234
└── mysql-pvc.yaml
234235
```
235236

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:
237238

238239
```markdown
239240
$ cat mysql-app/base/kustomization.yaml
@@ -247,9 +248,9 @@ resources:
247248
- mysql-pvc.yaml
248249
```
249250

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*:
251252

252-
```markdown
253+
```shell
253254
$ kubectl apply -k mysql-app/base
254255
namespace/mysql created
255256
secret/mysql-pass-m62cbhd9kf created
@@ -271,7 +272,7 @@ NAME DESIRED CURRENT READY AGE
271272
replicaset.apps/mysql-6974b58d48 1 1 1 24s
272273
```
273274

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:
275276

276277
```markdown
277278
$ kubectl get persistentvolumes
@@ -297,7 +298,7 @@ Handling connection for 42281
297298

298299
The deployed MySQL database service can be accessed by typing the following mysql command:
299300

300-
```markdown
301+
```shell
301302
$ mysql -h 127.0.0.1 -uroot -pCfeDemo@123 -P 42281
302303
Welcome to the MariaDB monitor. Commands end with ; or \g.
303304
Your MySQL connection id is 3
@@ -321,7 +322,7 @@ MySQL [(none)]> show databases;
321322
3. Populate MySQL database
322323

323324

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:
325326

326327
```markdown
327328
$ tree mysql-app/test
@@ -340,9 +341,9 @@ mysql-app/test
340341
└── test_employees_sha.sql
341342
```
342343

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:
344345

345-
```markdown
346+
```shell
346347
$ cd mysql-app/test
347348
$ mysql -h 127.0.0.1 -uroot -pCfeDemo@123 -P 42281 < employees.sql
348349
INFO
@@ -365,9 +366,9 @@ data_load_time_diff
365366
NULL
366367
```
367368

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:
369370

370-
```markdown
371+
```shell
371372
$ mysql -h 127.0.0.1 -uroot -pCfeDemo@123 -P 42281
372373
Welcome to the MariaDB monitor. Commands end with ; or \g.
373374
Your MySQL connection id is 3
@@ -439,31 +440,46 @@ $ mysql -h 127.0.0.1 -uroot -pCfeDemo@123 -P 42281 -t < test_employees_sha.sql
439440

440441
### Back up MySQL database
441442

442-
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.
443444

444445
![](/img/k10-backup-button.png)
445446

446447
Using all the default options from **Snapshot *mysql***, click *Snapshot Application* button:
447448

448449
![](/img/k10-backup.png)
449450

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**:
451452

452453
![](/img/k10-dashboard-backup.png)
453454

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:
455456

456457
![](/img/k10-data-backup.png)
457458

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
465+
k10-csi-snap-ltxzrwxgp6r5pwkp true mysql-pvc 1Gi gl-sbp-frank-gl1-sstor01 snapcontent-f3890356-d47f-4b36-a7e4-eb4c5792ec59 6d12h 6d12h
466+
467+
$ k get volumesnapshotcontents
468+
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+
458474
### Restore MySQL database
459475

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.
461477

462478
#### Delete table
463479

464480
Delete data from the table *departments*:
465481

466-
```markdown
482+
```shell
467483
$ mysql -h 127.0.0.1 -uroot -pCfeDemo@123 -P 42281 -Demployees
468484
Reading table information for completion of table and column names
469485
You can turn off this feature to get a quicker startup with -A
@@ -496,10 +512,10 @@ MySQL [employees]> delete from departments;
496512
Query OK, 9 rows affected (1,523 sec)
497513
```
498514

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:
500516

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
503519
+----------------------+
504520
| INFO |
505521
+----------------------+
@@ -550,25 +566,25 @@ $ mysql -h 127.0.0.1 -uroot -pCfeDemo@123 -P 41797 -t <test_employees_sha.sql
550566

551567
#### Perform MySQL database restore
552568

553-
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:
554570

555571
![](/img/k10-restore-button.png)
556572

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:
558574

559575
![](/img/k10-restore-point.png)
560576

561577
Use all the default options from **Restore Point** and click *Restore* button:
562578

563579
![](/img/k10-restore.png)
564580

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**:
566582

567583
![](/img/k10-dashboard-restore.png)
568584

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*:
570586

571-
```markdown
587+
```shell
572588
$ mysql -h 127.0.0.1 -uroot -pCfeDemo@123 -P 42281 -t < test_employees_sha.sql
573589
+----------------------+
574590
| INFO |
@@ -630,4 +646,11 @@ $ mysql -h 127.0.0.1 -uroot -pCfeDemo@123 -P 42281 -t < test_employees_sha.sql
630646

631647
```
632648

633-
### Summary
649+
650+
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

Comments
 (0)