使用 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 Protect 凍結設定"。
-
-
如果需要在應用程式建立後套用此註解,可以使用以下命令:
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 運算匹配,每個元素內的欄位(group、kind、version)之間按 AND 運算匹配。
-
resourceMatchers[].group:(可選)要篩選的資源群組。
-
resourceMatchers[].kind:(可選)要篩選的資源類型。
-
resourceMatchers[].version:(可選)要篩選的資源版本。
-
resourceMatchers[].names:(可選)要過濾的資源的 Kubernetes metadata.name 欄位中的名稱。
-
resourceMatchers[].namespaces:(可選)要篩選的資源的 Kubernetes metadata.name 欄位中的命名空間。
-
resourceMatchers[].labelSelectors:(可選)資源在 Kubernetes metadata.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"] -
-
建立與您的環境相符的應用程式 CR 後、套用該 CR。例如:
kubectl apply -f maria-app.yaml
-
使用以下範例之一建立並應用應用程式定義,並將括號中的值替換為您環境中的資訊。您可以使用範例中所示的參數,以逗號分隔的清單在應用程式定義中包含命名空間和資源。
建立應用程式時、您可以選擇使用註解來指定應用程式在快照期間是否可以寫入檔案系統。這僅適用於從虛擬機器定義的應用程式、例如在 KubeVirt 環境中、快照之前會發生檔案系統凍結。如果將註解設為
true、則應用程式會忽略全域設定、並可在快照期間寫入檔案系統。如果將其設為false、則應用程式會忽略全域設定、且檔案系統會在快照期間凍結。如果您使用註解、但應用程式定義中沒有虛擬機器、則會忽略該註解。如果您不使用註解、則應用程式會遵循"全球 Trident Protect 凍結設定"。使用 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"]}]' -