当前位置:网站首页>Kubernetes resource object introduction and common commands (V) - (NFS & PV & PVC)
Kubernetes resource object introduction and common commands (V) - (NFS & PV & PVC)
2022-07-03 00:45:00 【Jiang Xiaonan】
Storage abstraction (NFS&PV&PVC)

kubernetes adopt NFS Network file system , Synchronize the attached data of each node , Then it's guaranteed pod Failover, etc , The stored data can still be read .

install NFS
All nodes execute
yum install -y nfs-utils
nfs Master node execution
echo "/nfs/data/ *(insecure,rw,sync,no_root_squash)" > /etc/exports # Exposed the directory /nfs/data/,`*` It means that all nodes can access .
mkdir -p /nfs/data
systemctl enable rpcbind --now
systemctl enable nfs-server --now
# Configuration takes effect
exportfs -r
# Check and verify
[[email protected] ~]# exportfs
/nfs/data <world>
[[email protected] ~]#
Execute... From node
# Exhibition 172.31.0.2 Which directories can be mounted
showmount -e 172.31.0.2 # ip Change to your own master node ip
mkdir -p /nfs/data
# Mount the local directory and remote directory
mount -t nfs 172.31.0.2:/nfs/data /nfs/data
# Write a test file
echo "hello nfs server" > /nfs/data/test.txt

Actual test
Native data mount
apiVersion: apps/v1
kind: Deployment
metadata:
labels:
app: nginx-pv-demo
name: nginx-pv-demo
spec:
replicas: 2
selector:
matchLabels:
app: nginx-pv-demo
template:
metadata:
labels:
app: nginx-pv-demo
spec:
containers:
- image: nginx
name: nginx
volumeMounts:
- name: html
mountPath: /usr/share/nginx/html
volumes:
- name: html
nfs:
server: 172.31.0.2
path: /nfs/data/nginx-pv
[[email protected] ~]# kubectl apply -f nfsdata.yml
deployment.apps/nginx-pv-demo created
[[email protected] ~]#
explain : Create a directory in the node before deployment mkdir -p /nfs/data/nginx-pv
. Use the above method , It realizes the /usr/share/nginx/html
The directory is mounted to nfs File system /nfs/data/nginx-pv
Catalog , Later revision is very convenient .

PV&PVC
PV: Persistent volume (Persistent Volume), Save the data that the application needs to persist to the specified location .
PVC: Persistent volume declaration (Persistent Volume Claim), State the persistent volume specifications to be used .
establish PV pool
Static supply
# nfs Master node execution
[[email protected] data]# mkdir -p /nfs/data/01
[[email protected] data]# mkdir -p /nfs/data/02
[[email protected] data]# mkdir -p /nfs/data/03
[[email protected] data]# ls
01 02 03 nginx-pv test.txt
[[email protected] data]# pwd
/nfs/data
[[email protected] data]#
establish PV,pv.yml
apiVersion: v1
kind: PersistentVolume
metadata:
name: pv01-10m
spec:
capacity:
storage: 10M
accessModes:
- ReadWriteMany
storageClassName: nfs
nfs:
path: /nfs/data/01
server: 172.31.0.2
---
apiVersion: v1
kind: PersistentVolume
metadata:
name: pv02-1gi
spec:
capacity:
storage: 1Gi
accessModes:
- ReadWriteMany
storageClassName: nfs
nfs:
path: /nfs/data/02
server: 172.31.0.2
---
apiVersion: v1
kind: PersistentVolume
metadata:
name: pv03-3gi
spec:
capacity:
storage: 3Gi
accessModes:
- ReadWriteMany
storageClassName: nfs
nfs:
path: /nfs/data/03
server: 172.31.0.2
explain : take ip Change to yourself nfs The primary node of ip. Here will be our top 3 Folders are created as 3 individual PV, And set the size storage
. To form a PV pool . Be careful name No capital letters .
[[email protected] ~]# kubectl apply -f pv.yml
persistentvolume/pv01-10m created
persistentvolume/pv02-1gi created
persistentvolume/pv03-3gi created
[[email protected] ~]# kubectl get persistentvolume
NAME CAPACITY ACCESS MODES RECLAIM POLICY STATUS CLAIM STORAGECLASS REASON AGE
pv01-10m 10M RWX Retain Available nfs 45s
pv02-1gi 1Gi RWX Retain Available nfs 45s
pv03-3gi 3Gi RWX Retain Available nfs 45s
[[email protected] ~]#
establish PVC And PV binding ,pvc.yml
kind: PersistentVolumeClaim
apiVersion: v1
metadata:
name: nginx-pvc
spec:
accessModes:
- ReadWriteMany
resources:
requests:
storage: 200Mi
storageClassName: nfs
Created pvc, The size used is 200Mi. Note here storageClassName Need and pv Keep consistent , It is equivalent to using the same label to find .
[[email protected] ~]# kubectl apply -f pvc.yml
persistentvolumeclaim/nginx-pvc created
[[email protected] ~]# kubectl get pvc,pv
NAME STATUS VOLUME CAPACITY ACCESS MODES STORAGECLASS AGE
persistentvolumeclaim/nginx-pvc Bound pv02-1gi 1Gi RWX nfs 14m
NAME CAPACITY ACCESS MODES RECLAIM POLICY STATUS CLAIM STORAGECLASS REASON AGE
persistentvolume/pv01-10m 10M RWX Retain Available nfs 17m
persistentvolume/pv02-1gi 1Gi RWX Retain Bound default/nginx-pvc nfs 17m
persistentvolume/pv03-3gi 3Gi RWX Retain Available nfs 17m
[[email protected] ~]#
Can be found using 200Mi Of PVC, Will be in PV The best binding in the pool 1Gi The size of pv02-1gi
Of PV To use the , Maximize resource utilization . See at the same time pv In the pool pv02-1gi
Of PV Already in use , Status as Bound.
establish Pod binding PVC,podpvc.yml
apiVersion: apps/v1
kind: Deployment
metadata:
labels:
app: nginx-deploy-pvc
name: nginx-deploy-pvc
spec:
replicas: 2
selector:
matchLabels:
app: nginx-deploy-pvc
template:
metadata:
labels:
app: nginx-deploy-pvc
spec:
containers:
- image: nginx
name: nginx
volumeMounts:
- name: html
mountPath: /usr/share/nginx/html
volumes:
- name: html
persistentVolumeClaim:
claimName: nginx-pvc
Train of thought :Pod-->PVC-->PV
[[email protected] ~]# kubectl apply -f podpvc.yml
deployment.apps/nginx-deploy-pvc created
[[email protected] ~]#
At this time, we can also modify the file with pod Synchronization within .

Summary
What we said above PV The pool is a static supply . That is, in advance nfs The corresponding file directory is created in , And set the size and so on , for PVC Bind using . There is also a dynamic supply , There is no need to create in advance PV, But according to PVC Requirements for dynamic creation PV, In this way, the utilization of resources is more reasonable and effective .
边栏推荐
- The most painful programming problem in 2021, adventure of code 2021 Day24
- JSON conversion tool class
- 微信小程序获取某个元素的信息(高、宽等),并将px转换为rpx。
- 程序分析与优化 - 9 附录 XLA的缓冲区指派
- 2022中国3D视觉企业(引导定位、分拣场景)厂商名单
- Detailed explanation of pod life cycle
- Free we media essential tools sharing
- lex && yacc && bison && flex 配置的問題
- lex && yacc && bison && flex 配置的问题
- 线程的启动与优先级
猜你喜欢
University of Toronto: Anthony coach | the conditions of deep reinforcement learning can induce dynamic risk measurement
【AutoSAR 五 方法论】
Solution to the problem of abnormal display of PDF exported Chinese documents of confluence
Use Jenkins II job
ftrace工具的介绍及使用
Web2.0 giants have deployed VC, and tiger Dao VC may become a shortcut to Web3
Web2.0的巨头纷纷布局VC,Tiger DAO VC或成抵达Web3捷径
logback配置文件
世平信息首席科学家吕喆:构建以数据和人员为中心的安全能力
Logback configuration file
随机推荐
Vulkan并非“灵药“
【AutoSAR 三 RTE概述】
NC24840 [USACO 2009 Mar S]Look Up
Explain in detail the significance of the contour topology matrix obtained by using the contour detection function findcontours() of OpenCV, and how to draw the contour topology map with the contour t
1.11 - 总线
线程的启动与优先级
Preview word documents online
DotNet圈里一个优秀的ORM——FreeSql
The "2022 China Digital Office Market Research Report" can be downloaded to explain the 176.8 billion yuan market in detail
指针初阶(基础)
【AutoSAR 八 OS】
Introduction and use of ftrace tool
Hundreds of continuous innovation to create free low code office tools
lex && yacc && bison && flex 配置的問題
Win10 多种方式解决无法安装.Net3.5的问题
Solution to the problem of abnormal display of PDF exported Chinese documents of confluence
Redis21 classic interview questions, extreme pull interviewer
机器学习:numpy版本线性回归预测波士顿房价
可下载《2022年中国数字化办公市场研究报告》详解1768亿元市场
Graduation summary