一、概述
Docker使用數(shù)據(jù)卷和數(shù)據(jù)卷容器來(lái)進(jìn)行數(shù)據(jù)的持久化。
Pod是Kubernetes的基本單位,包含一個(gè)或多個(gè)容器。
Pod內(nèi)部的容器存在共享數(shù)據(jù)存儲(chǔ)的需求,Kubernetes給出了類似容器Volum(卷)的概念,與Pod具有相同的生命周期。
使用Volum,就需要知道存儲(chǔ)方案的技術(shù)細(xì)節(jié),通常由運(yùn)維人員來(lái)維護(hù)。而對(duì)開(kāi)發(fā)人員來(lái)說(shuō),只想知道我需要多大的存儲(chǔ)空間、I/O是否能滿足要求等等這些細(xì)節(jié)。
為此,Kubernetes在Volum的基礎(chǔ)上做了進(jìn)一步抽象,提出了PV(PersistentVolume,持久化卷)、PVC(PersistentVolumeClaim,持久化卷聲明)。
PV相當(dāng)于一塊硬盤(pán),由運(yùn)維人員提供。
PVC是對(duì)存儲(chǔ)需求的聲明,由開(kāi)發(fā)人員提供。
PVC可類比POD來(lái)理解,POD申請(qǐng)的是CPU和內(nèi)存資源,而PVC則是申請(qǐng)存儲(chǔ)資源。
PV一般是預(yù)先手動(dòng)創(chuàng)建的,開(kāi)發(fā)人員每次都申請(qǐng),則比較麻煩。是否可以根據(jù)PVC的要求,自動(dòng)創(chuàng)建呢?
Kubernetes提出了 Sotrage Class ,實(shí)現(xiàn)PV的動(dòng)態(tài)供給。
**二、實(shí)踐
**
(一)配置NFS服務(wù)器
NFS(Network File System)是一種分布式文件系統(tǒng)協(xié)議,可以通過(guò)網(wǎng)絡(luò),讓不同的客戶端,可以彼此訪問(wèn)共同的文件系統(tǒng) ,來(lái)實(shí)現(xiàn)文件的共享。NFS服務(wù)器提供可以掛載的目錄,客戶端直接掛載在本地端的目錄。
- 安裝NFS服務(wù)器
apt-get install nfs-kernel-server
- 配置NFS服務(wù)器
/etc/exports為NFS服務(wù)器的配置文件。
root@linux:/tmp# vi /etc/exports
# /etc/exports: the access control list for filesystems which may be exported
#to NFS clients. See exports(5).
# 訪問(wèn)控制列表,以便NFS客戶端配置
# Example for NFSv2 and NFSv3:
# /srv/homes hostname1(rw,sync,no_subtree_check) hostname2(ro,sync,no_subtree_check)
#
# Example for NFSv4:
# /srv/nfs4 gss/krb5i(rw,sync,fsid=0,crossmnt,no_subtree_check)
# /srv/nfs4/homes gss/krb5i(rw,sync,no_subtree_check)
#
/tmp *(rw,no_root_squash,sync)
參數(shù)說(shuō)明:
rw:設(shè)置目錄可讀寫(xiě);
no_root_squash:客戶端連接服務(wù)端時(shí),如果是root用戶,那么,將擁有服務(wù)端目錄的root權(quán)限;
sync:將數(shù)據(jù)同步寫(xiě)入內(nèi)存緩沖區(qū)與磁盤(pán)中,效率低,但可以保證數(shù)據(jù)的一致性;
- NFS服務(wù)器的啟動(dòng)
root@linux:/# service nfs-kernel-server start
- NFS客戶端配置
(1)安裝nfs-common
root@linux:/# apt install nfs-common
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following package was automatically installed and is no longer required:
grub-pc-bin
Use 'apt autoremove' to remove it.
The following additional packages will be installed:
keyutils libnfsidmap2 libtirpc1 rpcbind
Suggested packages:
watchdog
The following NEW packages will be installed:
keyutils libnfsidmap2 libtirpc1 nfs-common rpcbind
0 upgraded, 5 newly installed, 0 to remove and 345 not upgraded.
Need to get 399 kB of archives.
...
(2)將本地/mnt/nfs目錄掛載在NFS服務(wù)器上/tmp
root@linux:/# mount -t nfs 30.0.1.90:/tmp /mnt/nfs
root@linux:/#
(5)新建測(cè)試文件:
root@linux:/# cd /mnt/nfs/
root@linux:/mnt/nfs# touch 1.txt
root@linux:/mnt/nfs# echo this is nfs test > 1.txt
root@linux:/mnt/nfs# ls
1.txt
(6)登錄NFS服務(wù)器,便可查到文件:
root@linux:/tmp# ll
total 72
-rw-r--r-- 1 root root 1.txt
root@linux:/tmp# cat 1.txt
this is nfs test
root@linux:/tmp#
(二)Kubernetes掛載NFS
編寫(xiě)一個(gè)yaml文件,需要記住server地址和可供掛載的目錄
apiVersion: v1
kind: Pod
metadata:
name: mountnfstest
namespace: kubetest #
spec:
containers:
- name: nginx
image: nginx:1.21.0
ports:
- containerPort: 80
volumeMounts:
- name: logs-volume
mountPath: /var/log/nginx
volumes:
- name: logs-volume
nfs:
server: 30.0.1.90 # NFS服務(wù)器地址
path: /tmp/ #可供掛載的目錄
-
容器
+關(guān)注
關(guān)注
0文章
509瀏覽量
22415 -
Docker
+關(guān)注
關(guān)注
0文章
515瀏覽量
12877
發(fā)布評(píng)論請(qǐng)先 登錄
Kubernetes存儲(chǔ)體系解析 淺談Volume概念的由來(lái)



PVC電纜料的配方是什么?
從零開(kāi)始入門(mén) K8s | 應(yīng)用存儲(chǔ)和持久化數(shù)據(jù)卷:核心知識(shí)
從零開(kāi)始入門(mén) K8s | 應(yīng)用存儲(chǔ)和持久化數(shù)據(jù)卷:存儲(chǔ)快照與拓?fù)湔{(diào)度
從零開(kāi)始入門(mén) K8s | 應(yīng)用存儲(chǔ)和持久化數(shù)據(jù)卷:核心知識(shí)
電纜材料PVC和PUR有什么區(qū)別
pvc軟板有什么特性_pvc老化時(shí)間是多久

光伏測(cè)試儀PV150/PV200/PV210數(shù)據(jù)導(dǎo)出手冊(cè)

評(píng)論