Skip to content

Commit aadcbc0

Browse files
authored
feat(docs): improve backup and restore documentation (#115)
* feat(docs): improve backup and restore documentation
1 parent e6ded78 commit aadcbc0

10 files changed

Lines changed: 522 additions & 284 deletions

File tree

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,10 @@ A multi-tenant deployment for `etcd` is not common practice. However, `etcd` pro
1111
## Documentation
1212
Refer to the [etcd documentation](https://etcd.io/docs/v3.5/op-guide). Following sections provide additional procedures to help with a specific setup as it is used into project [Kamaji](https://github.com/clastix/kamaji).
1313

14+
- [Inspecting the Cluster](docs/inspect.md)
1415
- [Monitoring](docs/monitoring.md)
15-
- [Taking Snapshots](docs/snapshot.md)
16-
- [Recover from Snapshot](docs/snapshot-recovery.md)
17-
- [Velero](docs/velero.md)
16+
- [Backup](docs/backup.md)
17+
- [Restore](docs/restore.md)
1818
- [Rotate Certificates](docs/rotate-certificates.md)
1919
- [Defragmenting Data](docs/defragmentation.md)
2020
- [Performance and Optimization](docs/performance-and-optimization.md)

docs/backup.md

Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
# Take a backup
2+
3+
The `backup.sh` script is designed to create a job for taking snapshot of `etcd` instance. The script generates Kubernetes Job manifests and applies them to the specified namespace.
4+
5+
## Overview
6+
The script performs the following steps:
7+
8+
1. Creates a Kubernetes Job manifests from one of the `etcd` members.
9+
2. The job takes a snapshot of the `etcd` member and uploads it to a s3-like storage.
10+
11+
## Prerequisites
12+
13+
- Ensure you have `kubectl` installed and configured to interact with the management cluster.
14+
- It is assumed that the snapshot files will be stored on an S3-like storage.
15+
- A kubernetes secret called `backup-storage-secret` containing the parameters and credentials to access the storage must be created in the same namespace where `kamaji-etcd` is running.
16+
17+
### Creating the Secret
18+
19+
To create the secret, use the following command:
20+
21+
```bash
22+
kubectl create secret generic backup-storage-secret \
23+
--from-literal=storage-url=<storage_url> \
24+
--from-literal=storage-access-key=<access_key> \
25+
--from-literal=storage-secret-key=<access_secret> \
26+
--from-literal=storage-bucket-name=<bucket_name> \
27+
--from-literal=storage-bucket-folder=<bucket_folder> \
28+
-n <etcd_namespace>
29+
```
30+
31+
## Usage
32+
To run the script, use the following command:
33+
34+
```bash
35+
./backup.sh [-e etcd_name] [-s etcd_client_service] [-n etcd_namespace]
36+
```
37+
38+
### Parameters
39+
40+
- `-e etcd_name`: Name of the etcd StatefulSet (default: `kamaji-etcd`)
41+
- `-s etcd_client_service`: Name of the etcd client service (default: `kamaji-etcd-client`)
42+
- `-n etcd_namespace`: Namespace of the etcd StatefulSet (default: `kamaji-system`)
43+
44+
### Example
45+
46+
To run the script with custom parameters:
47+
48+
```bash
49+
./backup.sh -e kamaji-etcd -s kamaji-etcd-client -n kamaji-system
50+
```
51+
52+
This will create a Kubernetes Job manifest with the specified parameters and apply it to the cluster. The job will take a snapshot of the `etcd` member and upload it to the specified S3-like storage.
53+
54+
### Notes
55+
56+
- Ensure you have access a s3-like storage and the necessary secret `backup-storage-secret` is configured in Kubernetes.
57+
- The script uses `kubectl` commands, so ensure you have the necessary permissions to perform these operations.
58+
59+
### Debug mode
60+
To run the script in debug mode set the environment variable `DEBUG`:
61+
62+
``` bash
63+
export DEBUG=1
64+
```
65+
66+
## Schedule recurring backups
67+
To schedule recurring backups with CronJobs, use the `schedule.sh` script. The script generates Kubernetes CronJob manifests and applies them to the specified namespace.
68+
69+
### Usage
70+
To run the script, use the following command:
71+
72+
``` bash
73+
./schedule.sh [-e etcd_name] [-s etcd_client_service] [-n etcd_namespace] [-j schedule]
74+
```
75+
76+
### Parameters
77+
78+
- `-e etcd_name`: Name of the etcd StatefulSet (default: `kamaji-etcd`)
79+
- `-s etcd_client_service`: Name of the etcd client service (default: `kamaji-etcd-client`)
80+
- `-n etcd_namespace`: Namespace of the etcd StatefulSet (default: `kamaji-system`)
81+
- `-j schedule`: Cron schedule for the backup job (default: `"0 0 * * *"`, which means daily at midnight)
82+
83+
### Example
84+
To run the script with custom parameters:
85+
86+
```bash
87+
./schedule.sh -e kamaji-etcd -s kamaji-etcd-client -n kamaji-system -j "14 9 * * 1-5"
88+
```
89+
This will create a Kubernetes CronJob manifest with the specified parameters and apply it to the cluster. The CronJob will take a snapshot of the `etcd` member and upload it to the specified S3-like storage according to the defined schedule.
90+
91+
### Debug mode
92+
To run the script in debug mode set the environment variable `DEBUG`:
93+
94+
``` bash
95+
export DEBUG=1
96+
```

docs/inspect.md

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
# Inspecting etcd Cluster
2+
This guide explains how to run a `etcd` client pod to inspect the `kamaji-etcd` cluster and perform various operations.
3+
4+
## Running the etcd Client Pod
5+
6+
The `etcd-client.sh` script in the `scripts` directory can be used to create an etcd client pod with all necessary configurations and certificates mounted. Here's how to use it:
7+
8+
```bash
9+
./etcd-client.sh [-e etcd_name] [-s etcd_client_service] [-n etcd_namespace]
10+
```
11+
12+
### Script Parameters
13+
14+
- `-e`: Name of the etcd cluster (default: "kamaji-etcd")
15+
- `-s`: Service name for etcd client connection (default: "kamaji-etcd-client")
16+
- `-n`: Namespace where etcd is running (default: "kamaji-system")
17+
18+
### Using the Client Pod
19+
20+
1. Run the script to create the client pod:
21+
```bash
22+
./etcd-client.sh -e kamaji-etcd -s kamaji-etcd-client -n kamaji-system
23+
```
24+
25+
2. Once the pod is created, connect to it using:
26+
```bash
27+
kubectl exec -it etcd-client -n kamaji-system -- bash
28+
```
29+
30+
3. Inside the pod, you can run various etcdctl commands:
31+
- List all etcd cluster members:
32+
```bash
33+
etcdctl member list -w table
34+
```
35+
- Check endpoint status:
36+
```bash
37+
etcdctl endpoint status -w table
38+
```
39+
- Check endpoint health:
40+
```bash
41+
etcdctl endpoint health -w table
42+
```
43+
- List all keys in etcd:
44+
```bash
45+
etcdctl get / --prefix --keys-only
46+
```
47+
48+
The client pod is pre-configured with:
49+
50+
- TLS certificates for secure communication
51+
- Correct endpoints configuration
52+
- Required environment variables
53+
54+
### Cleanup
55+
56+
To remove the client pod when finished:
57+
```bash
58+
kubectl delete pod etcd-client -n kamaji-system
59+
```
60+
This allows you to inspect and interact with the `kamaji-etcd` cluster without needing to install etcdctl on your local machine or manage certificates manually.
Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -40,25 +40,27 @@ To run the script, use the following command:
4040
./restore.sh [-e etcd_name] [-s etcd_service] [-n etcd_namespace] [-f snapshot]
4141
```
4242

43-
## Parameters
43+
### Parameters
4444

4545
- `-e etcd_name`: Name of the etcd StatefulSet (default: `kamaji-etcd`)
46-
- `-s etcd_service`: Name of the etcd service (default: `kamaji-etcd`)
46+
- `-s etcd_service`: Name of the etcd headless service (default: `kamaji-etcd`)
4747
- `-n etcd_namespace`: Namespace of the etcd StatefulSet (default: `kamaji-system`)
4848
- `-f snapshot`: Snapshot file to restore from (required)
4949

50-
For example:
50+
### Example:
5151

5252
```bash
53-
./restore.sh -e my-etcd -s my-etcd-service -n my-namespace -f snapshot.db
53+
./restore.sh -e kamaji-etcd -s kamaji-etcd -n kamaji-system -f snapshot.db
5454
```
5555

56-
## Notes
56+
> 🚨 Make sure to use the **headless service** name for the `-s` parameter, which is typically the same as the StatefulSet name.
5757
58-
- Ensure that the snapshot file is accessible and the necessary secret for accessing the storage is configured in the same namespace.
58+
### Notes
59+
60+
- Ensure that the snapshot file is accessible and the necessary secret `backup-storage-secret` for accessing the storage is configured in the same namespace.
5961
- The script uses `kubectl` commands, so ensure you have the necessary permissions to perform these operations.
6062

61-
## Debug mode
63+
### Debug mode
6264
To run the script in debug mode set the environment variable `DEBUG`:
6365

6466
``` bash

docs/snapshot.md

Lines changed: 0 additions & 64 deletions
This file was deleted.

docs/velero.md

Lines changed: 0 additions & 102 deletions
This file was deleted.

0 commit comments

Comments
 (0)