Kubernetes backup

Overview

The Kubernetes setup for StackState has a built-in backup and restore mechanism that can be configured to store backups to the local clusters, to AWS S3 or to Azure Blob Storage.

Backup scope

The following data can be automatically backed up:
  • Configuration and topology data stored in StackGraph is backed up when the Helm value backup.stackGraph.enabled is set to true.
  • Telemetry data stored in StackState's Elasticsearch instance is backed up when the Helm value backup.elasticsearch.enabled is set to true.
The following data will NOT be backed up:
  • In transit topology and telemetry updates stored in Kafka - these only have temporary value and would be of no use when a backup is restored
  • Master node negotiations state stored in ZooKeeper - this runtime state would be incorrect when restored and will be automatically determined at runtime
  • Kubernetes configuration state and raw persistent volume state - this state can be rebuilt by re-installing StackState and restoring the backups.
  • Kubernetes logs - these are ephemeral.

Storage options

StackGraph and Elasticsearch backups are sent to an instance of MinIO (min.io), which is automatically started by the stackstate Helm chart when automatic backups are enabled. MinIO is an object storage system with the same API as AWS S3. It can store its data locally or act as a gateway to AWS S3 (min.io), Azure BLob Storage (min.io) and other systems.
The built-in MinIO instance can be configured to store the backups in three locations:
  • AWS S3
  • Azure Blob Storage
  • Kubernetes storage

Enable backups

Backup to AWS S3

To enable scheduled backups to AWS S3 buckets, add the following YAML fragment to the Helm values.yaml file used to install StackState:
1
backup:
2
enabled: true
3
stackGraph:
4
bucketName: AWS_STACKGRAPH_BUCKET
5
elasticsearch:
6
bucketName: AWS_ELASTICSEARCH_BUCKET
7
minio:
8
accessKey: YOUR_ACCESS_KEY
9
secretKey: YOUR_SECRET_KEY
10
s3gateway:
11
enabled: true
12
accessKey: AWS_ACCESS_KEY
13
secretKey: AWS_SECRET_KEY
Copied!
Replace the following values:
  • YOUR_ACCESS_KEY and YOUR_SECRET_KEY are the credentials that will be used to secure the MinIO system. The automatic backup jobs and the restore jobs will use them. They are also required to manually access the MinIO storage. YOUR_ACCESS_KEY should contain 5 to 20 alphanumerical characters and YOUR_SECRET_KEY should contain 8 to 40 alphanumerical characters.
  • AWS_ACCESS_KEY and AWS_SECRET_KEY are the AWS credentials for the IAM user that has access to the S3 buckets where the backups will be stored. See below for the permission policy that needs to be attached to that user.
  • AWS_STACKGRAPH_BUCKET and AWS_ELASTICSEARCH_BUCKET are the names of the S3 buckets where the backups should be stored. Note: The names of AWS S3 buckets are global across the whole of AWS, therefore the S3 buckets with the default name (sts-elasticsearch-backup and sts-stackgraph-backup) will probably not be available.
The IAM user identified by AWS_ACCESS_KEY and AWS_SECRET_KEY must be configured with the following permission policy to access the S3 buckets:
1
{
2
"Version": "2012-10-17",
3
"Statement": [
4
{
5
"Sid": "AllowListMinioBackupBuckets",
6
"Effect": "Allow",
7
"Action": [
8
"s3:ListBucket",
9
"s3:GetBucketLocation"
10
],
11
"Resource": [
12
"arn:aws:s3:::AWS_STACKGRAPH_BUCKET",
13
"arn:aws:s3:::AWS_ELASTICSEARCH_BUCKET"
14
]
15
},
16
{
17
"Sid": "AllowWriteMinioBackupBuckets",
18
"Effect": "Allow",
19
"Action": [
20
"s3:PutObject",
21
"s3:GetObject",
22
"s3:DeleteObject"
23
],
24
"Resource": [
25
"arn:aws:s3:::AWS_STACKGRAPH_BUCKET/*",
26
"arn:aws:s3:::AWS_ELASTICSEARCH_BUCKET/*"
27
]
28
}
29
]
30
}
Copied!

Backup to Azure Blob Storage

To enable backups to an Azure Blob Storage account, add the following YAML fragment to the Helm values.yaml file used to install StackState:
1
backup:
2
enabled: true
3
minio:
4
accessKey: AZURE_STORAGE_ACCOUNT_NAME
5
secretKey: AZURE_STORAGE_ACCOUNT_KEY
6
azuregateway:
7
enabled: true
Copied!
Replace AZURE_STORAGE_ACCOUNT_NAME with the Azure storage account name (microsoft.com) and replace AZURE_STORAGE_ACCOUNT_KEY with the Azure storage account key (microsoft.com) where the backups should be stored.
The StackGraph and Elasticsearch backups are stored in BLOB containers called sts-stackgraph-backup and sts-elasticsearch-backup respectively. These names can be changed by setting the Helm values backup.stackGraph.bucketName and backup.elasticsearch.bucketName respectively.

Backup to Kubernetes storage

To enable backups to cluster-local storage, enable MinIO by adding the following YAML fragment to the Helm values.yaml file used to install StackState:
1
backup:
2
enabled: true
3
minio:
4
accessKey: YOUR_ACCESS_KEY
5
secretKey: YOUR_SECRET_KEY
6
persistence:
7
enabled: true
Copied!
Replace YOUR_ACCESS_KEY and YOUR_SECRET_KEY with the credentials that will be used to secure the MinIO system. The automatic backup jobs and the restore jobs will use them. They are also required to manually access the MinIO storage. YOUR_ACCESS_KEY should contain 5 to 20 alphanumerical characters and YOUR_SECRET_KEY should contain 8 to 40 alphanumerical characters.

Configuration and topology data (StackGraph)

Configuration and topology data (StackGraph) backups are full backups, stored in a single file with the extension .graph. Each file contains a full backup and can be moved, copied or deleted as required.

Disable scheduled backups

When backup.enabled is set to true, scheduled StackGraph backups are enabled by default. To disable scheduled StackGraph backups only, set the Helm value backup.stackGraph.scheduled.enabled to false.

Disable restores

When backup.enabled is set to true, StackGraph restores are enabled by default. To disable StackGraph restore functionality only, set the Helm value backup.stackGraph.restore.enabled to false.

Backup schedule

By default, the StackGraph backups are created daily at 03:00 AM server time.
The backup schedule can be configured using the Helm value backup.stackGraph.scheduled.schedule, specified in Kubernetes cron schedule syntax (kubernetes.io).

Backup retention

By default, the StackGraph backups are kept for 30 days. As StackGraph backups are full backups, this can require a lot of storage.
The backup retention delta can be configured using the Helm value backup.stackGraph.scheduled.backupRetentionTimeDelta, specified in Python timedelta format (python.org).

Telemetry data (Elasticsearch)

The telemetry data (Elasticsearch) snapshots are incremental and stored in files with the extension .dat. The files in the Elasticsearch backup storage location should be treated as a single whole and can only be moved, copied or deleted as a whole.
The configuration snippets provided in the section enable backups will enable daily Elasticsearch snapshots.

Disable scheduled snapshots

When backup.enabled is set to true, scheduled Elasticsearch snapshots are enabled by default. To disable scheduled Elasticsearch snapshots only, set the Helm value backup.elasticsearch.scheduled.enabled to false.

Disable restores

When backup.enabled is set to true, Elasticsearch restores are enabled by default. To disable Elasticsearch restore functionality only, set the Helm value backup.elasticsearch.restore.enabled to false.

Snapshot schedule

By default, Elasticsearch snapshots are created daily at 03:00 AM server time.
The backup schedule can be configured using the Helm value backup.elasticsearch.scheduled.schedule, specified in Elasticsearch cron schedule syntax (elastic.co).

Snapshot retention

By default, Elasticsearch snapshots are kept for 30 days, with a minimum of 5 snapshots and a maximum of 30 snapshots.
The retention time and number of snapshots kept can be configured using the following Helm values:
  • backup.elasticsearch.scheduled.snapshotRetentionExpireAfter, specified in Elasticsearch time units (elastic.co).
  • backup.elasticsearch.scheduled.snapshotRetentionMinCount
  • backup.elasticsearch.scheduled.snapshotRetentionMaxCount
By default, the retention task itself runs daily at 1:30 AM UTC (elastic.co). If you set snapshots to expire faster than within a day, for example for testing purposes, you will need to change the schedule for the retention task.

Snapshot indices

By default, a snapshot is created for all Elasticsearch indices.
This indices for which a snapshot is created can be configured using the Helm value backup.elasticsearch.scheduled.indices, specified in JSON array format (w3schools.com).

Restore backups and snapshots

Scripts to list and restore backups and snapshots can be found in the restore directory of the StackState Helm chart repository (github.com). To use the scripts, download them from the GitHub site or check out the repository.
Before you use the scripts, ensure that:
  1. 1.
    The kubectl binary has been installed.
  2. 2.
    The kubectl binary is configured to connect to the Kubernetes cluster and the namespace within that cluster that runs StackState.
  3. 3.
    The Helm value backup.enabled is set to true.
  4. 4.
    The Helm value backup.stackGraph.restore.enabled is not set to false (to access StackGraph backups).
  5. 5.
    The Helm value backup.elasticsearch.restore.enabled is not set to false (to access Elasticsearch snapshots).

List StackGraph backups

To list the StackGraph backups, execute the following command:
1
./restore/list-stackgraph-backups.sh
Copied!
The output should look like this:
1
job.batch/stackgraph-list-backups-20210222t111942 created
2
Waiting for job to start...
3
=== Listing StackGraph backups in bucket "sts-stackgraph-backup"...
4
sts-backup-20210215-0300.graph
5
sts-backup-20210216-0300.graph
6
sts-backup-20210217-0300.graph
7
sts-backup-20210218-0300.graph
8
sts-backup-20210219-0300.graph
9
sts-backup-20210220-0300.graph
10
sts-backup-20210221-0300.graph
11
sts-backup-20210222-0300.graph
12
===
13
job.batch "stackgraph-list-backups-20210222t111942" deleted
Copied!
The timestamp when the backup was taken is part of the backup name.
Lines in the output that start with Error from server (BadRequest): are expected. They appear when the script is waiting for the pod to start.

Restore a StackGraph backup

When a backup is restored, the existing data in the StackGraph database will be overwritten.
Only execute the restore command when you are sure that you want to restore the backup.
To restore a StackGraph backup, select a backup name and pass it as the first parameter in the following command:
1
./restore/restore-stackgraph-backup.sh sts-backup-20210216-0300.graph
Copied!
The output should look like this:
1
job.batch/stackgraph-restore-20210222t112142 created
2
Waiting for job to start...
3
=== Downloading StackGraph backup "sts-backup-20210216-0300.graph" from bucket "sts-stackgraph-backup"...
4
download: s3://sts-stackgraph-backup/sts-backup-20210216-1252.graph to ../../tmp/sts-backup-20210216-0300.graph
5
=== Importing StackGraph data from "sts-backup-20210216-0300.graph"...
6
WARNING: An illegal reflective access operation has occurred
7
WARNING: Illegal reflective access by org.codehaus.groovy.vmplugin.v7.Java7$1 (file:/opt/docker/lib/org.codehaus.groovy.groovy-2.5.4.jar) to constructor java.lang.invoke.MethodHandles$Lookup(java.lang.Class,int)
8
WARNING: Please consider reporting this to the maintainers of org.codehaus.groovy.vmplugin.v7.Java7$1
9
WARNING: Use --illegal-access=warn to enable warnings of further illegal reflective access operations
10
WARNING: All illegal access operations will be denied in a future release
11
===
12
job.batch "stackgraph-restore-20210222t112142" deleted
Copied!
Lines that starts with WARNING: are expected. They are generated by Groovy running in JDK 11 and can be ignored.

List Elasticsearch snapshots

To list the Elasticsearch snapshots, execute the following command:
1
./restore/list-elasticsearch-snapshos.sh
Copied!
The output should look like this:
1
job.batch/elasticsearch-list-snapshots-20210224t133115 created
2
Waiting for job to start...
3
Waiting for job to start...
4
=== Listing Elasticsearch snapshots in snapshot repository "sts-backup" in bucket "sts-elasticsearch-backup"...
5
sts-backup-20210219-0300-mref7yrvrswxa02aqq213w
6
sts-backup-20210220-0300-yrn6qexkrdgh3pummsrj7e
7
sts-backup-20210221-0300-p481sih8s5jhre9zy4yw2o
8
sts-backup-20210222-0300-611kxendsvh4hhkoosr4b7
9
sts-backup-20210223-0300-ppss8nx40ykppss8nx40yk
10
===
11
job.batch "elasticsearch-list-snapshots-20210224t133115" deleted
Copied!
The timestamp when the backup was taken is part of the backup name.

Restore an Elasticsearch snapshot

When a snapshot is restored, existing indices will NOT be overwritten. Use Elasticsearch's Delete index API (elastic.co) to remove them first. See delete Elasticsearch indices, below.
To restore an Elasticsearch snapshot, select a snapshot name and pass it as the first parameter in the following command line:
1
./restore/restore-elasticsearch-snapshot.sh sts-backup-20210223-0300-ppss8nx40ykppss8nx40yk
Copied!
The output should look like this:
1
job.batch/elasticsearch-restore-20210229t152530 created
2
Waiting for job to start...
3
Waiting for job to start...
4
=== Restoring Elasticsearch snapshot "sts-backup-20210223-0300-ppss8nx40ykppss8nx40yk" from snapshot repository "sts-backup" in bucket "sts-elasticsearch-backup"...
5
{
6
"snapshot" : {
7
"snapshot" : "sts-backup-20210223-0300-ppss8nx40ykppss8nx40yk",
8
"indices" : [
9
".slm-history-1-000001",
10
"ilm-history-1-000001",
11
"sts_internal_events-2021.02.19"
12
],
13
"shards" : {
14
"total" : 3,
15
"failed" : 0,
16
"successful" : 3
17
}
18
}
19
}
20
===
21
job.batch "elasticsearch-restore-20210229t152530" deleted
Copied!
The indices restored are listed in the output, as well as the number of failed and successful restore actions.

Delete Elasticsearch indices

To delete existing Elasticsearch indices so that a snapshot can be restored, follow these steps.
  1. 1.
    Open a port-forward to the Elasticsearch master:
    1
    kubectl port-forward service/stackstate-elasticsearch-master 9200:9200
    Copied!
  2. 2.
    Delete an index with a following command:
    1
    curl -X DELETE "http://localhost:9200/INDEX_NAME?pretty"
    Copied!
    Replace INDEX_NAME with the name of the index to delete, for example
    1
    curl -X DELETE "http://localhost:9200/sts_internal_events-2021.02.19?pretty"
    Copied!
  3. 3.
    The output should be:
    1
    {
    2
    "acknowledged" : true
    3
    }
    Copied!
Last modified 2mo ago