You are looking at the documentation of a prior release. To read the documentation of the latest release, please visit here.

New to Stash? Please start here.

Supported Workloads

Stash supports the following types of Kubernetes workloads.

Deployments

To backup a Deployment, create a Restic with matching selectors. You can find a full working demo in examples folder.

ReplicaSets

To backup a ReplicaSet, create a Restic with matching selectors. You can find a full working demo in examples folder.

ReplicationControllers

To backup a ReplicationController, create a Restic with matching selectors. You can find a full working demo in examples folder.

DaemonSets

To backup a DaemonSet, create a Restic with matching selectors. You can find a full working demo in examples folder. This example shows how Stash can be used to backup host paths on all nodes of a cluster. First run a DaemonSet without nodeSelectors. This DaemonSet acts as a vector for Restic sidecar and mounts host paths that are to be backed up. In this example, we use a busybox container for this. Now, create a Restic that has a matching selector. This Restic also spec.volumeMounts the said host path and points to the host path in spec.fileGroups.

StatefulSets

Kubernetes does not support updating StatefulSet after they are created. It is recomanded to use initializer for StatefulSets. For details see here. Otherwise you need to add Stash sidecar container to your StatefulSet manually. You can see the relevant portions of a working example below:

apiVersion: apps/v1beta1
kind: StatefulSet
metadata:
  labels:
    app: statefulset-demo
  name: workload
  namespace: default
spec:
  replicas: 1
  serviceName: headless
  template:
    metadata:
      labels:
        app: statefulset-demo
      name: busybox
    spec:
      serviceAccountName: statefulset-demo
      containers:
      - command:
        - sleep
        - "3600"
        image: busybox
        imagePullPolicy: IfNotPresent
        name: busybox
        resources: {}
        terminationMessagePath: /dev/termination-log
        terminationMessagePolicy: File
        volumeMounts:
        - mountPath: /source/data
          name: source-data
      - args:
        - backup
        - --restic-name=statefulset-restic
        - --workload-kind=Statefulset
        - --workload-name=workload
        - --run-via-cron=true
        - --v=3
        env:
        - name: NODE_NAME
          valueFrom:
            fieldRef:
              apiVersion: v1
              fieldPath: spec.nodeName
        - name: POD_NAME
          valueFrom:
            fieldRef:
              apiVersion: v1
              fieldPath: metadata.name
        image: appscode/stash:0.7.0-rc.2
        imagePullPolicy: IfNotPresent
        name: stash
        resources: {}
        terminationMessagePath: /dev/termination-log
        terminationMessagePolicy: File
        volumeMounts:
        - mountPath: /tmp
          name: stash-scratchdir
        - mountPath: /etc/stash
          name: stash-podinfo
        - mountPath: /source/data
          name: source-data
          readOnly: true
        - mountPath: /safe/data
          name: stash-local
      restartPolicy: Always
      volumes:
      volumes:
      - gitRepo:
          repository: https://github.com/appscode/stash-data.git
        name: source-data
      - emptyDir: {}
        name: stash-scratchdir
      - downwardAPI:
          defaultMode: 420
          items:
          - fieldRef:
              apiVersion: v1
              fieldPath: metadata.labels
            path: labels
        name: stash-podinfo
      - hostPath:
          path: /data/stash-test/restic-repo
          type: ""
        name: stash-local

You can find the full working demo in examples folder. The section you should change for your own StatefulSet are:

  • --restic-name flag should be set to the name of the Restic used as configuration.
  • --workload-kind flag specifies the kind of workload (Deployment/Replicaset/RepliationController/DaemonSet/StatefulSet).
  • --workload-name flag specifies the name of workload where sidecar pod is added.

To learn about the meaning of various flags, please visit here.

Next Steps

  • Learn how to use Stash to backup a Kubernetes deployment here.
  • Learn about the details of Restic CRD here.
  • To restore a backup see here.
  • Learn about the details of Recovery CRD here.
  • To run backup in offline mode see here
  • See the list of supported backends and how to configure them here.
  • Thinking about monitoring your backup operations? Stash works out-of-the-box with Prometheus.
  • Learn about how to configure RBAC roles.
  • Wondering what features are coming next? Please visit here.
  • Want to hack on Stash? Check our contribution guidelines.