k8up icon indicating copy to clipboard operation
k8up copied to clipboard

K8up User CLI

Open tobru opened this issue 3 years ago • 3 comments

Summary

As a K8up user I want to be able to easily work with K8up with a specialized CLI So that I can get my job faster and easier done.

Context

NOTE: In this text, K8up (with uppercase K) refers to the backup operator, while k8up refers to the proposed command line tool.

K8up users must at the moment create and edit YAML files to describe the operations to be performed on the Kubernetes cluster where the operator is installed. This requires sometimes deleting the previous instance of an operation in order to apply the new one, tasks that must be performed through the kubectl command.

These manual operations are cumbersome and prone to errors at several levels: YAML syntax errors, naming, ID mismatches, etc.

To simplify the use of the K8up operator, the k8up command-line tool would "wrap" kubectl taking some command parameters

This tool would include a subcommand per type of YAML file that K8up can consume:

  • k8up configure would configure the required AWS S3 or Minio parameters for backup operations.
  • k8up backup would trigger a one-time backup.
  • k8up restore --snapshot [ID] --target pvc --location /var/lib/mysql would trigger the restore of the contents of a snapshot to a particular PVC at the specified location.
  • k8up schedule --pattern '*/5 * * * *' would schedule regular backups every 5 minutes
  • k8up archive would trigger an archive job
  • k8up check would trigger a check job
  • k8up prune would trigger a prune job

Each of the aforementioned commands would do the following steps:

  1. Delete any previous pod for the same command, if existing
  2. Create the YAML corresponding to the task
  3. Post that YAML to the Kubernetes cluster using the kubectl command.

Additionally, the k8up tool would offer online help (through a standard k8up help command) to support users. Other suggested commands could be:

  • k8up status to see the status of the last command pods
  • k8up logs to see the logs of the command pods

The k8up tool should be cross-platform, and its only requirement would be to have the kubectl command installed locally.

See also https://github.com/vshn/k8up/discussions/232 for some more context.

Out of Scope

Further links

  • https://kubernetes.io/docs/tasks/extend-kubectl/kubectl-plugins/

Acceptance criteria

Implementation Ideas

  • As a kubectl plugin
  • As a subcommand of the K8up operator

tobru avatar Jan 22 '21 08:01 tobru

In a future version we can use k8s native cronjobs.

Example how this could look:

  • a user creates a schedule ns/schedule
  • the operator simply creates a cronjob that triggers k8up backup --from=ns/schedule (or something in that manner)
  • the k8up tool (not the operator!) will then ** start the prebackup pods and wait for them to get ready ** collect the PVCs to be backed up ** start a job that runs the actual restic job(s)
  • the restic job writes some snapshot cr to the cluster containing the ID and metrics about the job (percentage, etc.)
  • the operator watches for the snapshot CRs and exposes the metrics via its own prometheus endpoint (killing the need for the pushgw)
  • the native k8s cronjob will do the cleanup of finished and failed jobs

This would remove quite a bit of complexity and issues we currently face from the operator. For example #137 would be fixed with that approach. Also we could remove the push gateway as all metrics are solely exposed by the operator.

Kidswiss avatar Feb 15 '21 15:02 Kidswiss

Yes, I was having the same vision in my head. In essence, the K8up operator with native cronjobs becomes like a glorified "cronjob manager with extra sausage", but K8up's core features lies in its CLI with CRDs as database resp. backup config.

ccremer avatar Feb 15 '21 15:02 ccremer

I've opened #643 to break this down into smaller stories.

Kidswiss avatar Apr 20 '22 13:04 Kidswiss