Command-Line Interface
Learn about using Trilio for Kubernetes from the command-line interface
Overview
In order to get started with Trilio for Kubernetes in your environment, the following steps will be performed:
Operating the Product
Install a compatible CSI Driver
Create a T4K Target - Location where backups will be stored.
Create a retention policy (Optional) - To specify how long to keep the backups for.
Run Example
Label Example
Helm Example
Operator Example
Namespace Example
Step 1: Install Test CSI Driver
Skip this step if your environment already has a CSI driver installed with snapshot capability.
Trilio for Kubernetes requires a compatible Container Storage Interface (CSI) driver that provides the Snapshot feature.
You should check the Kubernetes CSI Developer Documentation to select a driver appropriate for your backend storage solution. See the selected CSI driver's documentation for details on the installation of the driver in your cluster.
Step 2: Create a Target
Create a secret containing the credentials for data stores to store backups. An example is provided below.
Please use one of the Target examples provided in the Custom Resource Definition section as a template for creating an NFS, Amazon S3, or any S3-compatible storage target.
Supported values for S3 vendors include:
An Amazon S3 target example is provided below:
Note: With the above configuration, the target would get created in the current user namespace unless specified. Also, additional information on Bucket permissions can be found in the Appendix Section: AWS S3 Target Permissions****
Step 3: Create a Retention Policy (Optional)
While the example backup custom resources created by following this Getting Started page can be deleted manually via kubectl
commands, Trilio also provides backup retention capability - to automatically delete the backups based on defined time boundaries.
More information on the Retention Policy spec can be found in the application CRD reference section. A retention policy is referenced in the backupPlan CR .
Note: With the above configuration, policy would get created in default namespace unless specified.
Step 4: Run Example
This section covers backup and restores examples based on Labels, Helm charts, Operators, and Namespaces
More details about CRDs and their usage/explanation can be found in the Custom Resource Definition Section.
Note:
Backup and BackupPlan should be in the same namespace.
For the restore operation, the resources will get restored in the namespace where restore CR is created.
Specifying backupPlan information in the restore manifest will automatically select the latest successful backup for that backupPlan.
Step 4.1: Label Example
The following sections will create a sample application (tag it with labels), backup the application via labels, and then restore the application.
The following steps will be performed.
Create a sample MySQL application
Create a BackupPlan CR that specifies the MySQL application to protect via labels
Create a Backup CR with reference to the BackupPlan CR
Create a Restore CR with reference to the Backup CR.
Create a Sample Application
Create the following file as mysql.yaml. Note the labels used to tag the different components of the application.
Run below command to access the mysql DB using a mysql client from the host. This command works for "default" namespace. Please change the namespace context or use "-n <namespace>" if the demo app is installed in some other namespace.
Create a BackupPlan
Create a BackupPlan CR that references the application created in the previous step via matching labels in the same namespace where the application resides.
Create a Backup
Create a Backup CR to protect the BackupPlan. Type
of the backup can be either full or incremental.
Note: The first backup into a target location will always be a Full backup.
Restore the Backup/Application
Finally, create the Restore CR to restore the Backup in the same namespace where the Backup CR is created. In the example provided below, mysql-label-backup is being restored into the "default" namespace.
Note: If restoring into the same namespace, ensure that the original application components have been removed.
Note: If restoring to another cluster (migration scenario), ensure that Trilio for Kubernetes is running in the remote namespace/cluster as well. To restore into a new cluster (where the Backup CR does not exist), source.type
must be set to location. Please refer to the Custom Resource Definition Restore Section to view a restore by location example.
Note: If restoring into another namespace in the same cluster, ensure that the resources which cannot be shared, like ports, should be freed, or transformation should be used to avoid conflict. More information about transformation can be found at Restore Transformation.
Step 4.2: Helm Example
The following sections will create a sample application via Helm, back up the application via Helm selector fields, and then restore the application.
The following steps will be performed.
Create a cockroachdb instance using Helm
Create a BackupPlan CR that specifies the cockroachdb application to protect.
Create a Backup CR with a reference to the BackupPlan CR
Create a Restore CR with a reference to the Backup CR.
Create a sample application via Helm
In this example, we will use Helm Tooling to create a "cockroachdb" application.
Run the following commands against a Kubernetes cluster. Use the attached cockroachdb_-values.yaml_ file for the installation by copying it to your local directory.
After running helm install, confirm the installation was successful by running helm ls
Create a BackupPlan
Use the following to create a BackupPlan. Ensure the name of the release you specify matches the output from the helm ls command in the previous step.
Create a Backup
Use the following content to create a backup CR.
Restore Backup/Application
After the backup has completed successfully, create a Restore CR to restore the application in the same namespace where BackupPlan and Backup CRs are created.
Before restoring the app, we need to clean the existing app. This is required cluster level resources of the app can create conflict during restore operation.
Similar to the Label example above:
Note: If restoring into the same namespace, ensure that the original application components have been removed. Especially the PVC of application are deleted.
Note: If restoring to another cluster (migration scenario), ensure that Trilio for Kubernetes is running in the remote namespace/cluster as well. To restore into a new cluster (where the Backup CR does not exist), source.type
must be set to location. Please refer to the Custom Resource Definition Restore Section to view a restore by location example.
Step 4.3: Operator Example
The following steps will be performed.
Install a sample etcd Operator
Create a etcd cluster
Create a BackupPlan CR that specifies the etcd application to protect.
Create a Backup CR with a reference to the BackupPlan CR
Create a Restore CR with a reference to the Backup CR.
We are demonstrating standard 'etcd-operator' here. First we need to deploy the operator using it's helm chart. Then we need to deploy etcd cluster. Following are the commands for it.
Install etcd-operator
Create an etcd cluster using following yaml definition
Create a BackupPlan
Create 'BackupPlan' resource to protect 'etcd-operator' and it's clusters. Use the following yaml definition.
'operatorResourceName': This field holds the name of the operator whose backup we are going to take. In this case our operator name is "demo-etcd-cluster"
'operatorResourceSelector': This field selects the operator resources (whose backup we are going to take) using labels. In this case, operator is 'etcd-operator' and all it's resources like pods, services, deployments have a unique label - "release: trilio-demo-etcd-operator"
'applicationResourceSelector': This field selects the resources of the application launched using the operator. In this case, etcd-cluster is the application launched using etcd-operator. All the resources of this application have a unique label - "app: etcd"
Create a Backup
Take a backup of above 'BackupPlan'. Use following YAML definition to create a 'Backup' resource.
Restore the Backup/Application
After the backup completes successfully, you can perform the Restore of it.
To restore the etcd-operator and it's clusters from the above backup, use the following YAML definition.
Note: If restoring into the same namespace, ensure that the original application components have been removed.
Note: If restoring to another cluster (migration scenario), ensure that Trilio for Kubernetes is running in the remote namespace/cluster as well. To restore into a new cluster (where the Backup CR does not exist), source.type
must be set to location. Please refer to the Custom Resource Definition Restore Section to view a restore by location example.
Step 4.4: Namespace Example
Create a namespace called 'wordpress'
Use helm to deploy a wordpress application into the namespace.
Perform a backup of the namespace
Delete the namespace/application
Create a new namespace 'wordpress-restore'
Perform a Restore of the namespace
Create a namespace and application
Create the namespace called 'wordpress'
Install the wordpress Helm Chart
You can launch the wordpress app via a browser and make changes to the sample page to ensure changes are captured when you restore.
Create a BackupPlan
Create a backupPlan to backup the namespace
Backup the Namespace
Use the following YAML to build the Backup CR
Restore the Backup/Namespace
Perform restore of the namespace backup
Validate the pods are up and running after restore completes.
Validate Restore
Validate Application Pods
Finally, confirm the changes on the WordPress launch pages that were made earlier.
Last updated