kubernetes 學習筆記4

來源:互聯網
上載者:User

標籤:lease   data   虛擬機器   產生   resources   回收   soc   cap   can   

kubernetes 儲存問題

Pv:是叢集中的某個網路儲存中對應的一Block Storage,它是一種獨立於計算資源而存在的一種實體資源,通常我們定義一個網路儲存,然後從中划出一個網盤並掛載在虛擬機器上      pv屬於網路儲存,不屬於任何node,但可以在每個node上訪問      Pv不是定義在pod上,而是獨立於pod之外的pvc:某個pod想申請某種條件的pv,需要定義它 volume和claim的生命週期 可以提供的1.靜態一個叢集的管理者會產生很多pv,他們掌控一些儲存的細節並將這些儲存給叢集使用者用,這些pv存在於k8s的api,可以用於消耗2.動態當沒有靜態pv可以用時,管理者需要建立適合使用者的pvc,然後叢集會動態提供一個volume給pvc,這個提供是基於storageclass:這個pvc必須請求一個calss而且管理者必須建立和配置這個class以供使用,如果沒有聲明的話,將不會有動態資源提供 正在綁定的假如一個pvc設定了一定的storage和access modes,並且有對應的pv,那麼就會動態提供資源。一個在master上面的control loop 一直尋在監控pvc,然後找到一個pv進行匹配。假如需要匹配的volume不存在,那麼pvc一直保持unbound狀態,pvc一般會與可利用的匹配的volume綁定。假如叢集提供了一個50g的pv,那麼請求100g的pvc將不匹配,除非叢集添加了一個100g的pv 正在使用pod使用claim作為volume,叢集通過檢查claim來找到綁定的volume,然後提供volume給pod。volumes提供多種multiple access modes,使用者當需要為pod使用volume 時候,需要聲明期望的mode一旦使用者有claim,而且claim被綁定,那麼被綁定的pv就屬於使用者。使用者們通過包含在pod的volume模組中的pvc,調度pods和使用聲明的pv 正在釋放當一個使用者已經用完它們的volume,可以通過api刪除pvc,用以資源的回收。當pvc已被刪除時,這時關聯的volume是released狀態,但是還不能被另外的pvc使用。因為之前pvc產生的資料仍然在volume中,必鬚根據規則進行處理。 重新聲明當volume從它的pvc釋放出來之後,pv的recaim規則會告訴叢集該對volume做什麼。目前來說,volume既可以被保留,也可以被回收利用或者被刪除。deletion會刪除k8s的pv,同樣會刪除關聯的儲存(aws,gce,azure, cinder volume)。動態提供的volume通常會被刪除 目前支援的pv類型
  • GCEPersistentDisk
  • AWSElasticBlockStore
  • AzureFile
  • AzureDisk
  • FC (Fibre Channel)
  • NFS
  • iSCSI
  • RBD (Ceph Block Device)
  • CephFS
  • Cinder (OpenStack block storage)
  • Glusterfs
  • VsphereVolume
  • HostPath (single node testing only – local storage is not supported in any way and WILL NOT WORK in a multi-node cluster)
 pv
apiVersion: v1  kind: PersistentVolume  metadata:    name: pv0003    annotations:      volume.beta.kubernetes.io/storage-class: "slow"  spec:    capacity:      storage: 5Gi    accessModes:      - ReadWriteOnce    persistentVolumeReclaimPolicy: Recycle    nfs:      path: /tmp      server: 172.17.0.2
capacity:儲存屬性access modes:不同的虛擬資源會有不同的儲存能力和不同的access mode

The access modes are:

 

  • ReadWriteOnce – the volume can be mounted as read-write by a single node
  • ReadOnlyMany – the volume can be mounted read-only by many nodes
  • ReadWriteMany – the volume can be mounted as read-write by many nodes

In the CLI, the access modes are abbreviated to:

  • RWO - ReadWriteOnce
  • ROX - ReadOnlyMany
  • RWX - ReadWriteMan
class:pv的annotation 的class volume.beta.kubernetes.io/storage-class會和StorageClass的name關聯起來。pv的class會和pvc的class關聯起來 reclaim policy:
  • Retain – manual reclamation
  • Recycle – basic scrub (“rm -rf /thevolume/*”)
  • Delete – associated storage asset such as AWS EBS, GCE PD, Azure Disk, or OpenStack Cinder volume is deleted

Currently, only NFS and HostPath support recycling. AWS EBS, GCE PD, Azure Disk, and Cinder volumes support deletion.

volume所處的幾個階段:
  • Available – a free resource that is not yet bound to a claim
  • Bound – the volume is bound to a claim
  • Released – the claim has been deleted, but the resource is not yet reclaimed by the cluster
  • Failed – the volume has failed its automatic reclamation

pvc:通常包括 spec和status

 

kind: PersistentVolumeClaimapiVersion: v1metadata:  name: myclaim  annotations:    volume.beta.kubernetes.io/storage-class: "slow"spec:  accessModes:    - ReadWriteOnce  resources:    requests:      storage: 8Gi  selector:    matchLabels:      release: "stable"    matchExpressions:      - {key: environment, operator: In, values: [dev]}
 access modesresources:請求的資源大小seletor :pvc通常包含一個label selector 來挑選合適的volume。當volume的label和label seletor對應起來,才可以用這些volume。 calss volume的claimpod通過claim才可以用volume儲存。claim必須和pod存在於同一個namespace。這個叢集從pod的namespace找到claim,然後和pv關聯起來。然後volume可以掛載在pod上
kind: PodapiVersion: v1metadata:  name: mypodspec:  containers:    - name: myfrontend      image: dockerfile/nginx      volumeMounts:      - mountPath: "/var/www/html"        name: mypd  volumes:    - name: mypd      persistentVolumeClaim:        claimName: myclaim

kubernetes 學習筆記4

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.