1. 程式人生 > >kubernetes in action - Volumes

kubernetes in action - Volumes

Volume解決Kubernetes的儲存的問題

對於Pod使用的儲存,抽象為volume,volume伴隨著Pod的建立而建立,消失而同時消失,不能單獨的建立

這樣的好處,是儲存的塑膠不會因為某個container重啟而丟失,因為volume是pod級別的

還有好處是,volume是pod資源,所以所有Pod中的container都可以共享訪問這個volume,這樣非常的方便

但是需要在contain中去mount這個volume,可以mount到任意目錄,比如下面這個例子,

ContentAgent會產生內容html到/var/html,這個目錄對應於Volume publicHtml,
WebServer會通過/var/htdocs讀取Volume publicHtml中的資料,並把日誌通過/var/logs/寫到Volume logVol中
最後LogRotator會從Volume logVol消費logs

 

volume有很多種型別,

- emptyDir—A simple empty directory used for storing transient data.
- hostPath—Used for mounting directories from the worker node’s filesystem into the pod.
- gitRepo—A volume initialized by checking out the contents of a Git repository.
- nfs—An NFS share mounted into the pod.
- gcePersistentDisk (Google Compute Engine Persistent Disk), awsElastic-
- BlockStore (Amazon Web Services Elastic Block Store Volume), azureDisk (Microsoft Azure Disk Volume)—Used for mounting cloud provider-specific storage.
- cinder, cephfs, iscsi, flocker, glusterfs, quobyte, rbd, flexVolume, vsphere-Volume, photonPersistentDisk, scaleIO—Used for mounting other types of network storage.
- configMap, secret, downwardAPI—Special types of volumes used to expose certain Kubernetes resources and cluster information to the pod.
- persistentVolumeClaim

—A way to use a pre- or dynamically provisioned persistent storage. (We’ll talk about them in the last section of this chapter.)

其中,

emptyDir最常用,特點是pod刪除後資料會丟失,使用者container間互動資料或者純計算的中間結果

 

hostPath,mount到node的目錄,這樣資料就不會因為pod刪除而丟失

 

當然,如果要跨節點的恢復資料,就需要用到分散式的volume,比如,gcePersistentDisk

 

PersistentVolumeClaims,提供一種抽象來封裝底層各種具體的儲存 

 

 

這樣的好處,user不需要了解和配置具體的儲存,可以直接使用,那些事情交給Admin去做

 

Dynamic provisioning of PersistentVolumes

提前配置好,Persistent Volume Provisioner和Storage Class,僅僅在需要的時候才會自動產生Persistent Volume