当前位置:网站首页>How does kubernetes store business data persistently? (10)
How does kubernetes store business data persistently? (10)
2022-06-29 02:46:00 【wzlinux】
Through the previous explanation , We know how to Pod Use in Volume To save the data .Volume Follow Pod The life cycle of is bound , When Pod After being deleted ,Volume The data in may be deleted together , See the corresponding volume plugin Requirements for use of , You can see the comparison table in the previous section .
Storage requirements
Here we also need to consider the following issues .
- share Volume. at present Pod Internal Volume In fact, with Pod There is a static one-to-one binding relationship , Life cycle binding . This makes a difference Pod Can't share between Volume.
- Reuse Volume Data in . When Pod To fail for some reason , After being deleted and recreated by the workload controller , We need to be able to reuse Volume Old data in .
- Volume Some of its own strong relevance demands . For stateful workloads StatefulSet Come on , When it manages Pod There are some hardware or software problems in the host computer , For example, the disk is damaged 、kernel Abnormal etc. ,Pod again “ Long ” To other nodes , How to guarantee Volume and Pod A strong correlation between ?
- Volume Function and semantic extension , Such as capacity 、 Tag information 、 Expand or shrink capacity, etc .
For this we are Kubernetes A special object is introduced in Persistent Volume( abbreviation PV), Separate computing from storage , Different controllers can be used to manage .
At the same time through PV, We can also work with Pod Decouple the life cycle of itself . One PV Can be several Pod Use at the same time , Even if Pod After being deleted ,PV This object still exists , Other new Pod It can still be reused . To better describe this association binding relationship , Easy to use , And shield more detailed parameters that users do not care about ( such as PV By whom 、 Where to create zone/region、 How to access , wait ), We use an abstract object Persistent Volume Claim(PVC) To use PV.
We can PV It can be understood as a description of the actual physical storage resources ,PVC Is an easy to use abstraction API. stay Kubernetes in , We are all in Pod Pass through PVC How to use PV Of , See the picture below .

stay Kubernetes in , establish PV(PV Provision) There are two ways , Static and dynamic , As shown in the figure below .

static state PV

Let's start with static PV(Static PV), The administrator manually creates the corresponding... On the back-end storage platform Volume, And then through PV Define the Kubernetes In the middle . Developers through PVC To use . Let's take a look at HostPath Type of PV Example :
here , We have defined a system called task-pv-volume Of PV,PV It is the resource of the cluster , It doesn't belong to one namespace. among storageClassName This field is some StorageClass The name of the object . We will be in the next section PV In the interpretation of the StorageClass The role of .
For each of these PV, We all need to set the storage capacity for it , Currently, only storage space settings are supported , For example, we have set up 10G Space size of . Other configurations will be added to the community in the future , Such as IOPS(Input/Output Operations Per Second, Input / output times per second )、 Throughput, etc .
Here's the head accessMode You can specify the PV Several ways to access and mount :
- ReadWriteOnce(RWO) Indicates that the volume can only be mounted to one by reading and writing Pod Inside ;
- ReadOnlyMany( ROX) Indicates that the volume can be mounted to multiple nodes , And by multiple Pod Mount... As read-only ;
- ReadWriteMany(RWX) Indicates that a volume can be mounted by multiple nodes in a read-write manner for multiple Pod Use at the same time .
Pay attention to one. PV There can only be one access mount mode . Different volume plugin Supported by accessMode Is not the same , In use , You can refer to the official This form Make a selection .
Let's look at this after we create it PV:
You can see , This PV The status of is Available( You can use ).
Here we also see the above kubectl get There is a in the output of ReclaimPolicy Field , This field indicates that PV Recycling strategy for , The default is Retain, namely PV Data retention after use , The administrator needs to clean up the data manually . except Retain Outside , The following strategies are also supported :
- Recycle, I.e. recycling , This time will clear PV Data in ;
- Delete, Delete immediately , This strategy is often used in the storage services of cloud service providers , such as AWS EBS.
Let's create another PVC:
When it's created ,Kubernetes Would be PVC Match the PV. We are PVC Specify the inside storageClassName by manua, At this time, I will only match storageClassName For the same manual Of PV. Once you find the right one PV after , You can bind to the PV On .
PVC yes namespace Level of resources , Let's create and see :
We can see This PVC Already with our top PV Bound up . Let's check it out task-pv-volume This PV object , You can see that its state also changes from Available Turned into Bound.
PV There are generally the following five states :
- Pending It means that at present PV It has not been created in the back-end storage system ;
- Available That is, idle and available status , At this time, it has not been bound to any PVC On ;
- Bound As in the above example , At this time, it has been bound to a PVC Yes ;
- Released Indicates the bound PVC It has been deleted , But the resources have not been recycled ;
- Failed Indicates that recycling failed .
Again , about PVC Come on , There are also three states :
- Pending Indicates that no... Has been bound PV;
- Bound It means that you have been with a PV bound ;
- Lost Relating to PV Out of contact .
Let's take a look at , How to be in Pod Use static... In PV. Look at the following example :
Once I've created it :
You can see ,PV Has been properly mounted to Pod Inside .
static state PV The biggest problem is that it is not convenient to use , The administrator creates a batch of specified specifications in advance PV, Cannot create on demand . In use , It is often encountered that the resource size does not match , Unequal specifications , cause PVC Can't bind PV The situation of . At the same time, it will cause a waste of resources , For example, one only needs 1G Spatial Pod, The binding 10G Of PV.
These problems , Can be dynamically PV To solve .
dynamic PV
To dynamically create PV, We need some parameters to help us create PV. Here we use StorageClass This object describes , You can Kubernetes There are many definitions in StorageClass, Here is a Storage Examples of definitions :
You can use notes storageclass.kubernetes.io/is-default-class To specify the default StorageClass. So the newly created PVC Medium storageClassName Fields will automatically use the default StorageClass.
Here is a provisioner Field is required , Mainly used to specify which volume plugin To create PV. you 're right , This is exactly what we talked about last time CSI driver Name .
Now let's talk about the dynamic PV Process of work :

First we defined one StorageClass. When the user has created Pod in the future , It specifies PVC, This is the time Kubernetes Will be based on StorageClass As defined in Provisioner To call the corresponding plugin To create PV.PV Once created , Follow PVC Binding , Mount to Pod Use in .
StatefulSet How to use PV and PVC?
Remember when we said StatefulSet Problems left over from ? about StatefulSet Managed Pod, Every Pod The use of Volume The data in are all different , And the relationship between them needs strong binding . Not at this time StatefulSet Of spec.template To point directly to PV and PVC 了 . So we were StatefulSet Used in volumeClaimTemplate, With this template We can do it for everyone Pod Generate a single PVC, And bind PV 了 , So as to realize stateful service Pod All have their own storage . What's generated here PVC Name and StatefulSet Of Pod Name the same , Are with a specific serial number .
You can see here StatefulSet Example :
Last
In this chapter, we talked about PV、PVC as well as StorageClass, Their direct relationship and design ideas . Maybe when you first came into contact with these concepts , A little confused , But the problem to be solved by analyzing each object , It can help you master them better .
https://kubernetes.io/docs/concepts/storage/persistent-volumes/
Welcome to scan the code to pay attention to , For more information

边栏推荐
猜你喜欢

正则表达式(?:pattern)

层次分析法(AHP)

Leetcode counts the logarithm of points that cannot reach each other in an undirected graph

“内窥镜第一股”二闯IPO,去年亏损5个亿,核心产品商业化仍存疑 | IPO速递

今日直播|Apache Pulsar x KubeSphere 在线 Meetup 火热来袭

1110: 最近共同祖先(函数专题)

LabVIEW jump to web page

Day10 enumeration class and annotation

LabVIEW generate application (exe) and installer
![[sans titre]](/img/36/2f9319e05157ab6a8dd5aa3bef4505.png)
[sans titre]
随机推荐
Mipi d-phy -- contents of HS and LP agreements
深入解析 Apache BookKeeper 系列:第三篇——读取原理
Informatics Olympiad all in one 1361: production | Luogu P1037 [noip2002 popularization group] production
99 multiplication table
计算矩形面积
目标检测——ADAS实战
ArrayList basic operation and add element source code
Centos7 installation php7.2
Only in the past four years, Microsoft finally gave it up!
sql训练01
Introduction to openresty
对补wasm环境的一些测试
Pvcreate ASM disk causes abnormal recovery of ASM disk group - sparing separation
Double click events and click events
PWN攻防世界Level2
PHP system function
高并发的理解与设计方案
STM32L4系列单片机ADC通过内部参考电压精确计算输入电压
[sans titre]
Troubleshooting of pyinstaller failed to pack pikepdf