Kubernetes對卷快照Alpha支援的現況

  • 2019 年 12 月 5 日
  • 筆記

作者:Jing Xu(Google)、Xing Yang(華為)、Saad Ali(Google)

Kubernetes v1.12引入了卷快照(volume snapshot)支援作為alpha功能。在Kubernetes v1.13,它仍然是alpha功能,但增加了一些強化和一些重大更改。這篇文章總結了這些變化。

重大更改

CSI spec v1.0對卷快照功能進行了一些重大更改。CSI驅動程式維護者在升級其驅動程式以支援v1.0時,應該了解這些更改。

https://github.com/container-storage-interface/spec/releases/tag/v1.0.0

SnapshotStatus替換為Boolean ReadyToUse

在CSI v0.3.0,CreateSnapshotResponse中定義了SnapshotStatus枚舉(enum),表示快照是READY,UPLOADING,還是ERROR_UPLOADING。在CSI v1.0,SnapshotStatus已從CreateSnapshotResponse中刪除,並替換為布爾值(boolean)ReadyToUse。ReadyToUse值為true,表示完成後快照處理(post snapshot processing),例如上載,並且快照已準備好用作創建卷的源。

需要進行後快照處理的存儲系統(例如在快照完成後上傳),應該在快照完成後返回成功的CreateSnapshotResponse,並將ReadyToUse欄位設置為false。這表示容器箱編排系統(Container Orchestration System,CO),可以恢復因為進行快照而停頓的任何工作負載。然後,CO可以重複調用CreateSnapshot,直到ReadyToUse欄位設置為true,或該調用返回一個錯誤,指示處理中出現問題。CSI ListSnapshot調用可以與snapshot_id過濾一起使用,以確定快照是否可以使用,但不推薦使用這個方式,因為它無法在處理過程中檢測錯誤(ReadyToUse欄位只是無限期地保持為false)。

CSI外部快照邊車容器(external-snapshotter sidecar container)的v1.x.x版本,已通過調用CreateSnapshot,而不是ListSnapshots來處理此更改,以檢查快照是否可以使用。當升級驅動程式到CSI 1.0時,驅動程式維護者應使用相應的1.0兼容邊車(sidecar)容器。

https://github.com/kubernetes-csi/external-snapshotter/releases/tag/v1.0.1

為了與CSI規範的更改保持一致,VolumeSnapshot API對象中的Ready欄位已重命名為ReadyToUse。當執行kubectl describe volumesnapshot以查看快照的詳細資訊時,用戶可以看到此更改。

時間戳數據類型

快照的創建時間作為VolumeSnapshotContent API對象的一部分可供Kubernetes管理員使用。該欄位使用CSI CreateSnapshotResponse中的creation_time欄位填充。在CSI v1.0中,此creation_time欄位類型已更改為.google.protobuf.Timestamp,而不是int64。將驅動程式升級到CSI 1.0時,驅動程式維護者必須相應地進行更改。CSI外部快照程式邊車容器的v1.x.x版本已更新以處理此更改。

https://github.com/kubernetes-csi/external-snapshotter/releases/tag/v1.0.1

棄用

以下VolumeSnapshotClass參數已被棄用(deprecated),將在以後的版本中刪除。它們將替換為下面Replacement「替換」部分中列出的參數。

棄用csiSnapshotterSecretName,替換csi.storage.k8s.io/snapshotter-secret-name

棄用csiSnapshotterSecretNameSpace,替換csi.storage.k8s.io/snapshotter-secret-namespace

新功能

SnapshotContent刪除/保留(Deletion/Retain)政策

如在宣布快照alpha的初始部落格文章中所述,Kubernetes快照API類似於PV/PVC API:就像卷(volume),由綁定的PVC和PV對表示一樣,快照由綁定的VolumeSnapshot和VolumeSnapshotContent對表示。

https://kubernetes.io/blog/2018/10/09/introducing-volume-snapshot-alpha-for-kubernetes/

對於PV/PVC對,當用戶完成使用卷時,他們可以刪除PVC。PV上的回收政策決定PV之後的處理(是刪除,還是保留)。

在最初的alpha版本中,快照不支援指定回收政策的功能。當刪除快照對象時,它總是導致快照被刪除。在Kubernetes v1.13中,添加了快照內容DeletionPolicy。它使管理員,能夠配置VolumeSnapshotContent在綁定的VolumeSnapshot對象被刪除後的處理方式。卷快照的DeletionPolicy可以是Retain(刪除)或Delete(保留)。如果未指定該值,則預設值取決於SnapshotContent對象,是通過靜態綁定,還是動態配置創建的。

Retain(保留)

Retain(保留)政策允許手動回收資源。如果是靜態創建並綁定VolumeSnapshotContent,則默認的DeletionPolicy為Retain。刪除VolumeSnapshot時,VolumeSnapshotContent繼續存在,VolumeSnapshotContent被視為「已釋放」(「released」)。但它不能用於綁定到其他VolumeSnapshot對象,因為它包含數據。由管理員決定如何處理剩餘的API對象和資源清理。

Delete(刪除)

Delete(刪除)政策允許從Kubernetes自動刪除綁定的VolumeSnapshotContent對象,以及外部基礎結構中的關聯存儲資產(例如AWS EBS快照,或GCE PD快照等)。動態配置的快照會繼承其VolumeSnapshotClass的刪除政策,該政策默認為Delete。

管理員應使用所需的保留政策配置VolumeSnapshotClass。創建政策後,通過修補(patching)對象,可以更改單個VolumeSnapshotContent的政策。

以下示例演示如何檢查動態調配的VolumeSnapshotContent的刪除政策。

$ kubectl create -f ./examples/kubernetes/demo-defaultsnapshotclass.yaml  $ kubectl create -f ./examples/kubernetes/demo-snapshot.yaml  $ kubectl get volumesnapshots demo-snapshot-podpvc -o yaml  apiVersion: snapshot.storage.k8s.io/v1alpha1  kind: VolumeSnapshot  metadata:    creationTimestamp: "2018-11-27T23:57:09Z"  ...  spec:    snapshotClassName: default-snapshot-class    snapshotContentName: snapcontent-26cd0db3-f2a0-11e8-8be6-42010a800002    source:      apiGroup: null      kind: PersistentVolumeClaim      name: podpvc  status:  …  $ kubectl get volumesnapshotcontent snapcontent-26cd0db3-f2a0-11e8-8be6-42010a800002 -o yaml  apiVersion: snapshot.storage.k8s.io/v1alpha1  kind: VolumeSnapshotContent  …  spec:    csiVolumeSnapshotSource:      creationTime: 1546469777852000000      driver: pd.csi.storage.gke.io      restoreSize: 6442450944      snapshotHandle: projects/jing-k8s-dev/global/snapshots/snapshot-26cd0db3-f2a0-11e8-8be6-42010a800002    deletionPolicy: Delete    persistentVolumeRef:      apiVersion: v1      kind: PersistentVolume      name: pvc-853622a4-f28b-11e8-8be6-42010a800002      resourceVersion: "21117"      uid: ae400e9f-f28b-11e8-8be6-42010a800002    snapshotClassName: default-snapshot-class    volumeSnapshotRef:      apiVersion: snapshot.storage.k8s.io/v1alpha1      kind: VolumeSnapshot      name: demo-snapshot-podpvc      namespace: default      resourceVersion: "6948065"      uid: 26cd0db3-f2a0-11e8-8be6-42010a800002  

用戶可以使用修補程式(patch)更改刪除政策:

$ kubectl patch volumesnapshotcontent snapcontent-26cd0db3-f2a0-11e8-8be6-42010a800002 -p '{"spec":{"deletionPolicy":"Retain"}}' --type=merge    $ kubectl get volumesnapshotcontent snapcontent-26cd0db3-f2a0-11e8-8be6-42010a800002 -o yaml  apiVersion: snapshot.storage.k8s.io/v1alpha1  kind: VolumeSnapshotContent  ...  spec:    csiVolumeSnapshotSource:  ...    deletionPolicy: Retain    persistentVolumeRef:      apiVersion: v1      kind: PersistentVolume      name: pvc-853622a4-f28b-11e8-8be6-42010a800002  ...  

保護使用中的快照對象

「保護使用中的快照對象」(Snapshot Object in Use Protection)功能的目的,是確保不會從系統中刪除正在使用的快照API對象(因為這可能會導致數據丟失)。有兩種情況需要「使用中」(「in-use」)保護:

  • 如果卷快照正在被PVC作為創建卷的源。
  • 如果VolumeSnapshotContent API對象綁定到VolumeSnapshot API對象,會認為該內容對象正在使用中。

如果用戶刪除PVC正在使用的VolumeSnapshot API對象,VolumeSnapshot對象不會被立即刪除。刪除VolumeSnapshot對象被推遲,直到任何PVC不再使用VolumeSnapshot。同樣,如果管理員刪除了綁定到VolumeSnapshot的VolumeSnapshotContent,VolumeSnapshotContent不會被立即刪除。刪除VolumeSnapshotContent被推遲,直到VolumeSnapshotContent沒有綁定到VolumeSnapshot對象。

哪些卷插件支援Kubernetes快照?

快照僅在CSI驅動程式支援(不適用於樹內「in-tree」或Flexvolume)。要使用Kubernetes快照功能,請確保在群集上部署實現快照的CSI驅動程式。

截至本博文發布時,以下CSI驅動程式支援快照:

  • GCE Persistent Disk CSI Driver
  • OpenSDS CSI Driver
  • Ceph RBD CSI Driver
  • Portworx CSI Driver
  • GlusterFS CSI Driver
  • Digital Ocean CSI Driver
  • Ember CSI Driver
  • Cinder CSI Driver
  • Datera CSI Driver
  • NexentaStor CSI Driver

其他驅動程式的快照支援正在等待階段,應該很快就可以使用。閱讀「Kubernetes的容器存儲介面(CSI)GA了」部落格文章,了解有關CSI以及如何部署CSI驅動程式的更多資訊。

https://kubernetes-csi.github.io/docs/Drivers.html

下一步?

根據回饋和採用情況,Kubernetes團隊計劃將CSI Snapshot實施在1.15或1.16版本推向beta。我們感興趣的一些功能包括一致性組(consistency group)、應用程式一致性快照、工作負載停頓、就地恢復等。

怎樣才能了解更多?

快照API和控制器的程式碼存儲庫位於:https://github.com/kubernetes-csi/external-snapshotter

在此處查看有關快照功能的其他文檔:http://k8s.io/docs/concepts/storage/volume-snapshots和https://kubernetes-csi.github.io/docs/

怎樣參與?

像所有Kubernetes一樣,這個項目是許多來自不同背景的貢獻者共同努力的結果。

特別感謝所有幫助增加CSI v1.0支援,並改進此版本快照功能的貢獻者,包括Saad Ali(saadali)、Michelle Au(msau42)、Deep Debroy(ddebroy)、James DeFelice(jdef)、John Griffith (j-griffith)、Julian Hjortshoj(julian-hj)、Tim Hockin(thockin)、Patrick Ohly(pohly)、Luis Pabon(lpabon)、Cheng Xing(verult)、Jing Xu(jingxu97)、Shiwei Xu(wackxu)、Xing Yang(xing-yang)、Jie Yu(jieyu)、David Zhu(davidz627)。

有興趣參與CSI或Kubernetes存儲系統任何部分的設計和開發的人士,請加入Kubernetes存儲特別興趣小組(SIG)。我們正在快速成長,一直歡迎新的貢獻者。

https://github.com/kubernetes/community/tree/master/sig-storage

我們還定期召開SIG-Storage Snapshot工作組會議。歡迎新的參與者加入設計和開發的討論。

https://docs.google.com/document/d/1qdfvAj5O-tTAZzqJyz3B-yczLLxOiQd-XKpJmTEMazs/edit?usp=sharing