K8s workload automatic snapshot mechanism

By introducing ResourceSnapshotRule and Operator controllers in Kubernetes, the automatic creation and execution of timed snapshot policies is realized, which solves the problem of rapid workload snapshots and recovery in Kubernetes, and improves timeliness and data security.

CN119806738APending Publication Date: 2025-04-11CHINA ASEAN INFORMATION PORT CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202411882269.7
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-12-19
Publication Date
2025-04-11

AI Technical Summary

Technical Problem

It is difficult to implement rapid snapshots and recovery of workloads in Kubernetes, especially in application scenarios where timing automatic snapshots and custom snapshot policies are required.

Method used

By introducing ResourceSnapshotRule and Operator controllers in Kubernetes, we can automatically create and execute timed snapshot policies, back up resource configuration and associated resources of k8s workloads, create PVC snapshots, and build a snapshot recovery mechanism to achieve rapid workload recovery.

Benefits of technology

Accurate snapshot volume creation for Kubernetes workloads, improve timeliness, and provide timely automatic snapshots and retry mechanisms to ensure data security and rapid recovery.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119806738A_ABST
    Figure CN119806738A_ABST
Patent Text Reader

Abstract

The invention discloses an automatic snapshot mechanism for k8s workloads, and relates to data processing, in particular to the steps that a snapshot task is automatically created through a timing snapshot strategy, and when the snapshot task is executed, resource backup processing is conducted on the k8s workloads so as to create pvc snapshots; and constructing a snapshot recovery mechanism for performing associated resource analysis on the pvc snapshot to obtain a storage volume snapshot for snapshot recovery. According to the method, the corresponding snapshot creation is carried out at the specified time point according to the snapshot plan, the snapshot volume can be accurately created, the timeliness is improved, outdated snapshot cleaning can be carried out according to the cleaning plan in the snapshot plan, the resource consumption is reduced, and the data security is ensured.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to data processing, and more particularly, to a k8s workload automatic snapshot mechanism. Background Art

[0002] Kubernetes is a portable, extensible, open source platform for managing containerized workloads and services. In Kubernetes, a workload is a way to run an application.

[0003] Kubernetes provides several different workload resources, including Deployment, StatefulSet, DaemonSet, Job, and CronJob. In order to improve the fault tolerance of workloads, it is usually necessary to snapshot the data and be able to quickly restore it. In k8s, the CSI Snapshotter controller is used to implement the storage snapshot function. For workloads in k8s, such as Deployment, StatefulSet, DaemonSet, Job, and CronJob resources, a method is required to implement fast snapshots and restores of k8s resources and storage resources. In some application scenarios, it is necessary to implement the ability to schedule automatic snapshots and create custom snapshot policies and retry mechanisms. Summary of the invention

[0004] The technical problem to be solved by the present invention is to provide a k8s workload automatic snapshot mechanism in view of the deficiencies in the prior art, which can create corresponding snapshots at a specified time point according to the snapshot plan, accurately create snapshot volumes, and improve timeliness.

[0005] The present invention discloses a k8s workload automatic snapshot mechanism, which automatically creates a snapshot task through a timed snapshot strategy, and performs resource backup processing on the k8s workload when the snapshot task is executed to create a pvc snapshot; and constructs a snapshot recovery mechanism that performs associated resource analysis on the pvc snapshot to obtain a storage volume snapshot for snapshot recovery.

[0006] Preferably, the timing snapshot strategy includes:

[0007] Create ResourceSnapshotRule in the container platform k8s;

[0008] Create the ResourceSnapshotRule scheduled snapshot plan;

[0009] The creation of the ResourceSnapshotRule scheduled snapshot plan instance is monitored by the Operator controller, and after the Operator controller monitors the creation of the ResourceSnapshotRule scheduled snapshot plan instance, when the set scheduled snapshot time period is reached, the snapshot task is executed to create a full snapshot of the k8s workload.

[0010] Preferably, the monitoring mode of the Operator controller is:

[0011] The Operator controller checks the ResourceSnapshotRule configuration and if the target resource of the ResourceSnapshotRule scheduled snapshot plan does not exist or

[0012] If the ResourceSnapshotRule configuration is illegal, the ResourceSnapshotRule is marked as abnormal, and the ResourceSnapshotRule timing plan is not executed.

[0013] Preferably, the creation of the full snapshot of the k8s workload is specifically as follows:

[0014] At the beginning of a time period of the timing snapshot, creating a ResourceSnapshot in the container platform k8s;

[0015] Back up the original resource configuration of the k8s workload to the status.source field in ResourceSnapshot;

[0016] Query the associated resource list of the k8s workload to obtain whether the associated resource list has mounted configmap, secret, and pvc storage configurations. If so, update the backup-associated configmap specification to status.configmapBackups, the backup-associated secret specification to status.secretBackups, and the backup-associated pvc specification to status.volumeBackups;

[0017] Get the CSI driver information of all mounted pvcs to create the pvc snapshot.

[0018] Preferably, if the mounted pvc storage configuration does not support CSI snapshot, exit directly.

[0019] Preferably, if the pvc snapshot creation fails, it is recreated according to the retry times in the ResourceSnapshotRule until the retry times are exceeded.

[0020] Preferably, the snapshot recovery mechanism is specifically as follows:

[0021] Create ResourceRestore in the container platform k8s, and specify the target resource object name and resource type, namespace, and pvc snapshot name for the ResourceRestore;

[0022] Check whether the associated resources in the associated resource list have been deleted. If they have been deleted, create a new resource object based on configmapBackups / secretBackups; if they have not been deleted, roll back the resource object based on configmapBackups / secretBackups;

[0023] Create and generate a new pvc volume through the pvc snapshot and volumeBackups;

[0024] The target resource configuration is updated through the source configuration in ResourceSnapshot, and the pvc volume name of the target resource configuration is replaced with the new pvc volume name.

[0025] Preferably, after the ResourceRestore is created, the snapshot status is checked by the Operator controller according to the specified pvc snapshot name, and it is available when status.readyToUse of the snapshot status is True, otherwise the snapshot recovery fails.

[0026] Preferably, when the Operator controller detects that ResourceSnapshotRule is deleted, all ResourceSnapshot, ResourceRestore and pvc snapshot resources are deleted in association.

[0027] When the Operator controller detects the deletion of ResourceSnapshot, it deletes the ResourceRestore and pvc snapshot resources it created.

[0028] Preferably, during the execution of the pvc snapshot creation and snapshot restoration, the execution results are recorded in the custom fields of the custom resource objects ResourceSnapshot and ResourceRestore.

[0029] Beneficial Effects

[0030] The advantages of the present invention are: ResourceSnapshotRule is a data protection solution for k8s workloads. ResourceSnapshotRule can perform complete snapshots on all configurations and data volumes in k8s workloads, create corresponding snapshots at specified time points according to the snapshot plan, accurately create snapshot volumes, improve timeliness, and clean up outdated snapshots according to the cleanup plan in the snapshot plan, reduce resource consumption, and ensure data security. In addition, a storage volume snapshot is created for the pvc snapshot, and when restoring the snapshot, the k8s workload can be restored to the snapshot time point with one click. BRIEF DESCRIPTION OF THE DRAWINGS

[0031] Figure 1 A schematic diagram of a process flow for creating a snapshot of the present invention;

[0032] Figure 2 It is a schematic diagram of the snapshot recovery process of the present invention;

[0033] Figure 3 This is a schematic diagram of the k8s workload automatic snapshot mechanism architecture of the present invention;

[0034] Figure 4 It is a schematic diagram of the modular structure of the Operator controller of the present invention. DETAILED DESCRIPTION

[0035] The present invention will be further described below in conjunction with the embodiments, but it does not constitute any limitation to the present invention. Any limited number of modifications made by anyone within the scope of the claims of the present invention are still within the scope of the claims of the present invention.

[0036] See also Figure 1-Figure 4 The present invention provides an automatic snapshot mechanism for k8s workloads. It formulates a scheduled snapshot plan for k8s workloads, such as Deployment, StatefulSet, DaemonSet, Job, CronJob and other resources, and automatically creates snapshots according to the scheduled snapshot strategy to achieve snapshot retention time, snapshot retention number and failure retry capabilities. When creating a snapshot, the k8s workload includes the original resource configuration and associated resource configuration, such as configmap, secret, and pvc. A storage volume snapshot, i.e., a pvc volume, is created for the pvc snapshot (in this article, the pvc snapshot is referred to as a snapshot). Based on the pvc volume, when restoring the snapshot, the k8s workload can be restored to the snapshot time point with one click. Specifically, the following steps are included:

[0037] The first step is to install ResourceSnapshotRule, ResourceSnapshot, ResourceRestore and Operator controllers in the container platform k8s to monitor the creation, deletion and update status of CRD instances, and perform corresponding snapshot task management according to the configuration information of ResourceSnapshotRule instances, and perform corresponding snapshot recovery management according to the creation of ResourceRestore instances.

[0038] Among them, ResourceSnapshotRule: a custom resource (CRD) object used to define the k8s workload snapshot backup plan;

[0039] ResourceSnapshot: A custom resource (CRD) object used to define a k8s workload snapshot;

[0040] ResourceRestore: A custom resource (CRD) object used to define k8s workload snapshot recovery tasks;

[0041] The Operator controller runs in Deployment mode. The Operator controller includes: snapshot scheduling module, snapshot management module, snapshot cleanup module, and snapshot recovery module.

[0042] Step 2: Create a ResourceSnapshotRule scheduled snapshot plan, specify the target resource type and resource name, scheduled task cycle expression, number of failed retries, and snapshot cleanup strategy. The snapshot cleanup strategy includes the snapshot expiration time and the number of snapshots to be retained.

[0043] Step 3: After the Operator controller monitors the creation of the ResourceSnapshotRule scheduled snapshot plan instance, it creates a full snapshot of the k8s workload when the scheduled snapshot time period is reached.

[0044] Step 4: The Operator controller checks the ResourceSnapshotRule configuration. If the target resource does not exist or the configuration is illegal, the ResourceSnapshotRule is marked as abnormal and the scheduled plan is no longer executed.

[0045] Step 5: The scheduled snapshot creation task includes the scheduled creation of a ResourceSnapshot instance, which specifies the snapshot name, namespace, target resource name, and resource type. Initialize the ResourceSnapshot instance's status.readyToUse to False.

[0046] Step 6. The Operator controller queries the target resource status, backs up the original resource configuration of the k8s workload and updates it to the status.source field in ResourceSnapshot; then queries the list of associated resources of the k8s workload, such as whether storage configurations such as configmap, secret, and pvc storage are mounted, and updates the backup-associated configmap specification to status.configmapBackups, the backup-associated secret specification to status.secretBackups, and the backup-associated pvc specification to status.volumeBackups.

[0047] Step 7. Get the CSI driver information of all mounted pvcs and create a pvc snapshot. If the mounted pvc storage configuration does not support CSI snapshots, exit directly. If the snapshot creation fails, recreate it according to the retry count in ResourceSnapshotRule until the retry count is exceeded. When the snapshot is completed, the status status.readyToUse of the ResourceSnapshot instance is updated to True.

[0048] Step 8: Operator controller regularly cleans up outdated snapshots according to all

[0049] The expiration time in ResourceSnapshotRule cleans up ResourceSnapshot instances and associated pvc snapshots that have exceeded the expiration time. However, it is necessary to ensure that the specified number of snapshots are retained. When the number of snapshots is less than or equal to the number of retained snapshots, expired snapshots are no longer cleaned up.

[0050] Step 9: Snapshot recovery is achieved by creating ResourceRestore. Specifically, by creating a ResourceRestore instance, you specify: the target resource object name and resource type, namespace, and snapshot name.

[0051] Step 10. The Operator controller checks the snapshot status according to the specified snapshot name. It is available when status.readyToUse is True. Otherwise, the snapshot recovery fails and needs to be recreated.

[0052] Step 11: Check whether the associated resource has been deleted. If it has been deleted, create a new resource object based on configmapBackups / secretBackups; if it has not been deleted, roll back the resource object based on configmapBackups / secretBackups. For pvc resources, you need to create a new pvc volume through pvc snapshots and volumeBackups.

[0053] Step 12: Update the target resource configuration through the source configuration in ResourceSnapshot, and replace the pvc volume name of the target resource configuration with the new pvc volume name.

[0054] Step 13: When the Operator controller detects that a ResourceSnapshotRule instance is deleted, it deletes all associated ResourceSnapshot, ResourceRestore, and pvc snapshot resources.

[0055] Step 14: When the Operator controller detects that a ResourceSnapshot instance is deleted, it deletes the associated ResourceRestore and pvc snapshot resources that it created.

[0056] Step 15. During the execution of snapshot creation and snapshot recovery, the relevant execution results are recorded in the custom fields of the custom resource objects ResourceSnapshot and ResourceRestore, such as status.conditions, to record the process execution results, execution failure information, returned response information, and also record the start time, execution completion time and other information.

[0057] The above is only a preferred embodiment of the present invention. It should be pointed out that for those skilled in the art, several modifications and improvements can be made without departing from the structure of the present invention, which will not affect the effect of the implementation of the present invention and the practicality of the patent.

Claims

1. A k8s workload automatic snapshot mechanism, characterized in that: A snapshot task is automatically created through a scheduled snapshot strategy, and when the snapshot task is executed, resource backup processing is performed on the k8s workload to create a pvc snapshot; a snapshot recovery mechanism is constructed by analyzing the associated resources of the pvc snapshot to obtain a storage volume snapshot for snapshot recovery.

2. According to claim 1, a k8s workload automatic snapshot mechanism is characterized in that: The timing snapshot strategy includes: Create ResourceSnapshotRule in the container platform k8s; Create the ResourceSnapshotRule scheduled snapshot plan; The creation of the ResourceSnapshotRule scheduled snapshot plan instance is monitored by the Operator controller, and after the Operator controller monitors the creation of the ResourceSnapshotRule scheduled snapshot plan instance, when the set scheduled snapshot time period is reached, the snapshot task is executed to create a full snapshot of the k8s workload.

3. According to claim 2, a k8s workload automatic snapshot mechanism is characterized in that: The monitoring mode of the Operator controller is: The Operator controller checks the ResourceSnapshotRule configuration, and if the target resource of the ResourceSnapshotRule timing snapshot plan does not exist or the ResourceSnapshotRule configuration is illegal, the ResourceSnapshotRule is marked as abnormal, and the ResourceSnapshotRule timing plan is not executed.

4. According to claim 2, a k8s workload automatic snapshot mechanism is characterized in that: The creation of the full snapshot of the k8s workload is as follows: At the beginning of a time period of the timing snapshot, creating a ResourceSnapshot in the container platform k8s; Back up the original resource configuration of the k8s workload to the status.source field in ResourceSnapshot; Query the associated resource list of the k8s workload to check whether the associated resource list has mounted the configmap, secret, and pvc storage configurations. If so, update the backup-associated configmap specification to status.configmapBackups, the backup-associated secret specification to status.secretBackups, and the backup-associated pvc specification to status.volumeBackups; Get the CSI driver information of all mounted pvcs to create the pvc snapshot.

5. According to claim 4, a k8s workload automatic snapshot mechanism is characterized in that: If the mounted PVC storage configuration does not support CSI snapshots, exit directly.

6. A k8s workload automatic snapshot mechanism according to claim 4, characterized in that: If the pvc snapshot creation fails, it is recreated according to the retry times in the ResourceSnapshotRule until the retry times are exceeded.

7. A k8s workload automatic snapshot mechanism according to claim 4, characterized in that: The snapshot recovery mechanism is specifically as follows: Create ResourceRestore in the container platform k8s, and specify the target resource object name and resource type, namespace, and pvc snapshot name for the ResourceRestore; Check whether the associated resources in the associated resource list have been deleted. If they have been deleted, create a new resource object according to configmapBackups / secretBackups; if they have not been deleted, roll back the resource object according to configmapBackups / secretBackups; Create and generate a new pvc volume through the pvc snapshot and volumeBackups; The target resource configuration is updated through the source configuration in ResourceSnapshot, and the pvc volume name of the target resource configuration is replaced with the new pvc volume name.

8. A k8s workload automatic snapshot mechanism according to claim 7, characterized in that: After the ResourceRestore is created, the snapshot status is checked through the Operator controller according to the specified pvc snapshot name. When the status.readyToUse of the snapshot status is True, it is available, otherwise the snapshot recovery fails.

9. A k8s workload automatic snapshot mechanism according to claim 7, characterized in that: When the Operator controller detects the deletion of ResourceSnapshotRule, it deletes all ResourceSnapshot, ResourceRestore and pvc snapshot resources; When the Operator controller detects the deletion of ResourceSnapshot, it deletes the ResourceRestore and pvc snapshot resources it created.

10. A k8s workload automatic snapshot mechanism according to claim 7, characterized in that: During the execution of the pvc snapshot creation and snapshot restoration, the execution results are recorded in the custom fields of the custom resource objects ResourceSnapshot and ResourceRestore.