事件
3月31日 下午11時 - 4月2日 下午11時
最大的網狀架構、Power BI 和 SQL 學習事件。 3 月 31 日 - 4 月 2 日。 使用程式代碼 FABINSIDER 來節省 $400 美元。
立即註冊Azure 容器儲存體是雲端式磁碟區管理、部署和協調流程服務,專為容器原生建置。 本文說明如何擷取永續性磁碟區的時間點快照集,並使用新的永續性磁碟區宣告將其還原。
首先,您需要建立磁碟區快照集類別,以便在 YAML 資訊清單檔中定義磁碟區快照集的屬性,從而指定其屬性。 請遵循下列步驟來建立 Azure 磁碟的磁碟區快照集類別。
使用您慣用的文字編輯器來建立 YAML 資訊清單檔,例如 code acstor-volumesnapshotclass.yaml
。
貼入下列程式碼。 磁碟區快照集類別的 name 值可以是任意值。
apiVersion: snapshot.storage.k8s.io/v1
kind: VolumeSnapshotClass
metadata:
name: csi-acstor-vsc
driver: containerstorage.csi.azure.com
deletionPolicy: Delete
parameters:
incremental: "true" # available values: "true", "false" ("true" by default for Azure Public Cloud, and "false" by default for Azure Stack Cloud)
套用 YAML 資訊清單檔來建立磁碟區快照集類別。
kubectl apply -f acstor-volumesnapshotclass.yaml
建立完成時,您會看到如下訊息:
volumesnapshotclass.snapshot.storage.k8s.io/csi-acstor-vsc created
您也可以執行 kubectl get volumesnapshotclass
來檢查磁碟區快照集類別是否已建立。 您應該會看到類似如下輸出:
NAME DRIVER DELETIONPOLICY AGE
csi-acstor-vsc containerstorage.csi.azure.com Delete 11s
接下來,您將建立現有永續性磁碟區宣告的快照集,並套用在上一個步驟中建立的磁碟區快照集類別。
使用您慣用的文字編輯器來建立 YAML 資訊清單檔,例如 code acstor-volumesnapshot.yaml
。
貼入下列程式碼。 volumeSnapshotClassName
應為您在上一個步驟中建立的磁碟區快照集類別名稱。 針對 persistentVolumeClaimName
,請使用要建立快照集的永續性磁碟區宣告名稱。 磁碟區快照集的 name 值可以是任意值。
apiVersion: snapshot.storage.k8s.io/v1
kind: VolumeSnapshot
metadata:
name: azuredisk-volume-snapshot
spec:
volumeSnapshotClassName: csi-acstor-vsc
source:
persistentVolumeClaimName: azurediskpvc
套用 YAML 資訊清單檔以建立磁碟區快照集。
kubectl apply -f acstor-volumesnapshot.yaml
建立完成時,您會看到如下訊息:
volumesnapshot.snapshot.storage.k8s.io/azuredisk-volume-snapshot created
您也可以執行 kubectl get volumesnapshot
來檢查磁碟區快照集是否已建立。 如果 READYTOUSE
指出 true,則可以繼續下一個步驟。
現在,您可以建立新的永續性磁碟區宣告,以使用磁碟區快照集作為資料來源。
使用您慣用的文字編輯器來建立 YAML 資訊清單檔,例如 code acstor-pvc-restored.yaml
。
貼入下列程式碼。 storageClassName
必須符合您在建立原始永續性磁碟區時所使用的儲存類別。 例如,如果您使用暫時性磁碟 (本機 NVMe),而非用於後端記憶體的 Azure 磁碟,請將 storageClassName
變更為 acstor-ephemeraldisk
。 針對資料來源的 name 值,請使用您在上一個步驟中建立的磁碟區快照集名稱。 永續性磁碟區宣告的中繼資料 name 值可以是任意值。
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: pvc-azuredisk-snapshot-restored
spec:
accessModes:
- ReadWriteOnce
storageClassName: acstor-azuredisk
resources:
requests:
storage: 100Gi
dataSource:
name: azuredisk-volume-snapshot
kind: VolumeSnapshot
apiGroup: snapshot.storage.k8s.io
套用 YAML 資訊清單檔以建立 PVC。
kubectl apply -f acstor-pvc-restored.yaml
建立完成時,您會看到如下訊息:
persistentvolumeclaim/pvc-azuredisk-snapshot-restored created
您也可以執行 kubectl describe pvc pvc-azuredisk-snapshot-restored
來檢查永續性磁碟區是否已建立。 您應看到狀態為 [擱置],以及訊息「waiting for first consumer to be created before binding」。
提示
如果您已建立還原的永續性磁碟區宣告,並想要再次套用 yaml 檔案以更正錯誤或進行變更,您必須先刪除舊的永續性磁碟區宣告,接著再次套用 yaml 檔案:kubectl delete pvc <pvc-name>
。
在建立新的 Pod 之前,您可能想要刪除用於建立快照集的原始 Pod。
kubectl get pods
以列出 Pod。 請確定您要刪除的 Pod 正確無誤。kubectl delete pod <pod-name>
。接下來,使用還原的永續性磁碟區宣告建立新的 Pod。 使用 Fio (彈性 I/O 測試器) 建立 Pod,以進行基準測試和工作負載模擬,並指定永續性磁碟區的掛接路徑。
使用您慣用的文字編輯器來建立 YAML 資訊清單檔,例如 code acstor-pod2.yaml
。
貼入下列程式碼。 永續性磁碟區宣告 claimName
應為您所建立還原快照集永續性磁碟區宣告的名稱。 Pod 的中繼資料 name 值可以是任意值。
kind: Pod
apiVersion: v1
metadata:
name: fiopod2
spec:
nodeSelector:
acstor.azure.com/io-engine: acstor
volumes:
- name: diskpv
persistentVolumeClaim:
claimName: pvc-azuredisk-snapshot-restored
containers:
- name: fio
image: nixery.dev/shell/fio
args:
- sleep
- "1000000"
volumeMounts:
- mountPath: "/volume"
name: diskpv
套用 YAML 資訊清單檔以部署 Pod。
kubectl apply -f acstor-pod2.yaml
您應該會看到如下輸出:
pod/fiopod2 created
檢查 Pod 是否正在執行,且永續性磁碟區宣告已成功繫結至 Pod:
kubectl describe pod fiopod2
kubectl describe pvc pvc-azuredisk-snapshot-restored
檢查 Fio 測試以查看其目前狀態:
kubectl exec -it fiopod2 -- fio --name=benchtest --size=800m --filename=/volume/test --direct=1 --rw=randrw --ioengine=libaio --bs=4k --iodepth=16 --numjobs=8 --time_based --runtime=60
您現在已從還原的永續性磁碟區宣告部署新的 Pod,並可在 Kubernetes 工作負載上使用。
事件
3月31日 下午11時 - 4月2日 下午11時
最大的網狀架構、Power BI 和 SQL 學習事件。 3 月 31 日 - 4 月 2 日。 使用程式代碼 FABINSIDER 來節省 $400 美元。
立即註冊訓練
模組
Learn storage concepts that help you solve real problems with Windows containers running on Azure Kubernetes Service (AKS) and AKS Hybrid.
認證
Microsoft Certified: Azure for SAP Workloads Specialty - Certifications
Demonstrate planning, migration, and operation of an SAP solution on Microsoft Azure while you leverage Azure resources.