Kubernetes Cluster Snapshot Backups

This chapter describes details about the resource “kubebackups” which represents the snapshot backup definition of a Kubernetes cluster.

Defining a Scheduled Backup

POST /api/v1/kubebackups

{
    "trigger_type": "SCHEDULED"
    "cluster": "5f612ab693eac38c72ff0b74",
    "name": "testbackup",
    "policy": "5f612ab606e136bfb2d6e8ce",
    "source": {
        "all_namespaces": true,
        "snapshotPersistentVolumes": true
    }
}

201 CREATED

{
    "_created": "Tue, 15 Sep 2020 20:57:38 GMT",
    "_etag": "f7067311b310f61ae15eba37e207a44ede2b5d23",
    "_id": "5f612ac2a47691eb08e77904",
    "_links": {
        "related": {
            "cluster": {
                "href": "/v1/kubeclusters/5f612ab693eac38c72ff0b74",
                "title": "Kubecluster"
            },
            "policy": {
                "href": "/v1/policies/5f612ab606e136bfb2d6e8ce",
                "title": "policy"
            }
        },
        "self": {
            "href": "/v1/kubebackups/5f612ac2a47691eb08e77904",
            "title": "Kubebackup"
        }
    },
    "_status": "OK",
    "_updated": "Tue, 15 Sep 2020 20:57:38 GMT",
    "cluster": "5f612ab693eac38c72ff0b74",
    "name": "testbackup",
    "policy": "5f612ab606e136bfb2d6e8ce",
    "source": {
        "all_namespaces": true,
        "snapshotPersistentVolumes": true
    }
}

Schema

trigger_type

Optional. String. Possible values are “ADHOC” and “SCHEDULED”. Default is “SCHEDULED”.

“SCHEDULED” backups are run as per “policy”.

“ADHOC” backups need to be run explicitly as described below.

cluster

ID of the Kubernetes cluster. Required.

policy

ID of the policy. This field is required for “SCHEDULED” type of backups while “ADHOC” backups do not use it.

source

Source of the backup. Required.

pre/post_hooks

Optional. List of pre/post hook’s ID

pause

Boolean. Optional

Response will contain “status” field whose schema is described below. Note that “status” may not appear immediately so client will need to poll until it sees the field.

Source schema

all_namespaces

Boolean. Optional. If set to true, all namespaces will be included in the backup. In this case, values passed in “namespaces” field, if any, will be ignored.

namespaces

Optional. List of namespace names (not IDs).

label_selector

Optional. A map of label key and value pairs.

A map of label key and “,” separated values to support OR set based operation.

When multiple key-value specified then it will be AND-ED together.

snapshotPersistentVolumes

Boolean. Default is true. When set to true, the backup will include snapshotting the persistent volumes of supported types.

Some examples of sources:

Backup everything:

"source": {
    "all_namespaces": true
}

Backup few namespaces:

"source": {
    "namespaces": [
        "appns1",
        "appns2"
    ]
}

Backup with label selectors:

"source": {
    "label_selector": {
        "app": "nginx"
    }
}

"source": {
    "label_selector": {
        "app": "nginx,wordpress"
    }
}

"source": {
    "label_selector": {
        "tier": "frontend",
        "app": "nginx,wordpress"
    }
}

Running a Backup

Some times, users may want to run backups immediately instead of waiting for scheduled time. In case of “ADHOC” backups, there is no schedule so they do need to be run explicitly.:

POST /api/v1/kubebackups/<ID>/action/run

{
    "retention": {
        "retainDays": 15
    }
}

Schema

retention
retainDays

Integer. Required.

Status

The corresponding kubebackup resource will have a “status” field updated as per the following schema:

jobs

List. Contains up to last three completed jobs associated with the backup, in chronological order. Each job in this list contains three fields:

jobid - String. ID of the job.
state - String. State of the job.
message - String. Message from the job resource.
message

String

Get/List

GET /api/v1/kubebackups

GET /api/v1/kubebackups/<ID>

Pause/Resume

Updating pause field in the backup definition will either pause or resume a Kubernetes backup.

Note

These actions do not impact currently running backups. They will take effect on future schedules.

Get backups for a cluster

GET /api/v1/kubebackups?where={"cluster":"5f612ab693eac38c72ff0b74"}

Delete a backup

DELETE /api/v1/kubebackups/<ID>

Note

Delete will fail if there is a running job corresponding to the backup resource.