使用Trident Protect 定義管理應用程式
您可以透過建立應用程式 CR 和關聯的 AppVault CR 來定義要使用Trident Protect 管理的應用程式。
建立 AppVault CR
您需要建立一個 AppVault CR,該 CR 將在對應用程式執行資料保護操作時使用,並且 AppVault CR 需要位於安裝了Trident Protect 的叢集上。 AppVault CR 是針對您的特定環境的;有關 AppVault CR 的範例,請參閱:"AppVault 自訂資源。"
定義應用程式
您需要定義要使用Trident Protect 管理的每個應用程式。您可以透過手動建立應用程式 CR 或使用Trident Protect CLI 來定義要管理的應用程式。
-
建立目標應用程式 CR 檔案:
-
建立自訂資源 (CR) 檔案並將其命名為(例如,
maria-app.yaml)。 -
配置以下屬性:
-
metadata.name: (必填) 應用程式自訂資源的名稱。請注意您選擇的名稱,因為保護操作所需的其他 CR 檔案會引用此值。
-
spec.includedNamespaces: (必要) 使用命名空間和標籤選擇器來指定應用程式使用的命名空間和資源。應用程式命名空間必須包含在此清單中。標籤選擇器是可選的,可用來篩選每個指定命名空間內的資源。
-
spec.includedClusterScopedResources: (可選) 使用此屬性指定要包含在應用程式定義中的叢集範圍資源。此屬性可讓您根據資源的群組、版本、種類和標籤來選擇這些資源。
-
groupVersionKind: (必要) 指定叢集範圍資源的 API 群組、版本和類型。
-
labelSelector: (可選) 依照標籤篩選叢集範圍的資源。
-
-
metadata.annotations.protect.trident.netapp.io/skip-vm-freeze: (可選) 此註解僅適用於從虛擬機定義的應用程序,例如 KubeVirt 環境,其中檔案系統凍結發生在快照之前。指定此應用程式在快照期間是否可以寫入檔案系統。如果設定為 true,應用程式將忽略全域設置,並且可以在快照期間寫入檔案系統。如果設定為 false,應用程式將忽略全域設置,並且在快照期間檔案系統將被凍結。如果指定了註解,但應用程式定義中沒有虛擬機,則忽略該註解。如未特別說明,則申請流程如下:"全球Trident保護凍結設置" 。
-
-
如果需要在應用程式建立後套用此註解,可以使用以下命令:
kubectl annotate application -n <application CR namespace> <application CR name> protect.trident.netapp.io/skip-vm-freeze="true"
+
YAML 範例:
+
apiVersion: protect.trident.netapp.io/v1
kind: Application
metadata:
annotations:
protect.trident.netapp.io/skip-vm-freeze: "false"
name: my-app-name
namespace: my-app-namespace
spec:
includedNamespaces:
- namespace: namespace-1
labelSelector:
matchLabels:
app: example-app
- namespace: namespace-2
labelSelector:
matchLabels:
app: another-example-app
includedClusterScopedResources:
- groupVersionKind:
group: rbac.authorization.k8s.io
kind: ClusterRole
version: v1
labelSelector:
matchLabels:
mylabel: test
-
(可選)新增篩選條件,包含或排除帶有特定標籤的資源:
-
resourceFilter.resourceSelectionCriteria:(篩選時必備)使用 `Include`或者 `Exclude`包含或排除 resourceMatchers 中定義的資源。新增以下 resourceMatchers 參數以定義要包含或排除的資源:
-
resourceFilter.resourceMatchers:resourceMatcher 物件陣列。如果在該數組中定義多個元素,則它們之間按 OR 運算匹配,每個元素內的字段(組、種類、版本)之間按 AND 運算匹配。
-
resourceMatchers[].group: (可選) 要篩選的資源群組。
-
resourceMatchers[].kind: (可選) 要篩選的資源類型。
-
resourceMatchers[].version: (可選) 要篩選的資源版本。
-
resourceMatchers[].names: (可選) 要過濾的資源的 Kubernetes 元資料.name 欄位中的名稱。
-
resourceMatchers[].namespaces: (可選) 要篩選的資源的 Kubernetes 元資料.name 欄位中的命名空間。
-
resourceMatchers[].labelSelectors: (可選) 資源的 Kubernetes 元資料.name 欄位中的標籤選擇器字串,如在下列位置定義: "Kubernetes 文檔" 。例如:
"trident.netapp.io/os=linux"。當兩者 `resourceFilter`和 `labelSelector`被使用, `resourceFilter`先運行,然後 `labelSelector`應用於生成的資源。
-
例如:
-
spec: resourceFilter: resourceSelectionCriteria: "Include" resourceMatchers: - group: my-resource-group-1 kind: my-resource-kind-1 version: my-resource-version-1 names: ["my-resource-names"] namespaces: ["my-resource-namespaces"] labelSelectors: ["trident.netapp.io/os=linux"] - group: my-resource-group-2 kind: my-resource-kind-2 version: my-resource-version-2 names: ["my-resource-names"] namespaces: ["my-resource-namespaces"] labelSelectors: ["trident.netapp.io/os=linux"] -
-
建立與您的環境相符的應用程式變更要求後,請套用該變更要求。例如:
kubectl apply -f maria-app.yaml
-
使用以下範例之一建立並應用應用程式定義,將括號中的值替換為您環境中的資訊。您可以使用逗號分隔的列表,並在範例中顯示參數,將命名空間和資源包含在應用程式定義中。
建立應用程式時,您可以選擇使用註解來指定應用程式在快照期間是否可以寫入檔案系統。這僅適用於從虛擬機定義的應用程序,例如 KubeVirt 環境,其中檔案系統凍結發生在快照之前。如果您將註釋設定為 `true`該應用程式忽略全域設置,可以在快照期間寫入檔案系統。如果你把它設定為 `false`該應用程式忽略全域設置,導致檔案系統在快照期間凍結。如果使用了註解,但應用程式定義中沒有虛擬機,則該註解將被忽略。如果您不使用註解,應用程式將遵循以下規則:"全球Trident保護凍結設置" 。
在使用 CLI 建立應用程式時,若要指定註解,可以使用以下方法: `--annotation`旗幟。
-
建立應用程式並使用檔案系統凍結行為的全域設定:
tridentctl-protect create application <my_new_app_cr_name> --namespaces <namespaces_to_include> --csr <cluster_scoped_resources_to_include> --namespace <my-app-namespace> -
建立應用程式並配置本機應用程式設定以控製檔案系統凍結行為:
tridentctl-protect create application <my_new_app_cr_name> --namespaces <namespaces_to_include> --csr <cluster_scoped_resources_to_include> --namespace <my-app-namespace> --annotation protect.trident.netapp.io/skip-vm-freeze=<"true"|"false">您可以使用 `--resource-filter-include`和 `--resource-filter-exclude`用於根據以下條件包含或排除資源的標誌 `resourceSelectionCriteria`例如群組、類型、版本、標籤、名稱和命名空間,如下例所示:
tridentctl-protect create application <my_new_app_cr_name> --namespaces <namespaces_to_include> --csr <cluster_scoped_resources_to_include> --namespace <my-app-namespace> --resource-filter-include '[{"Group":"apps","Kind":"Deployment","Version":"v1","Names":["my-deployment"],"Namespaces":["my-namespace"],"LabelSelectors":["app=my-app"]}]' -