当前位置:网站首页>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 .
边栏推荐
- University of Toronto:Anthony Coache | 深度强化学习的条件可诱导动态风险度量
- 机器学习:numpy版本线性回归预测波士顿房价
- Vulkan performance and refinement
- 1.11 - 总线
- 【日常训练】871. 最低加油次数
- Andorid gets the system title bar height
- An excellent orm in dotnet circle -- FreeSQL
- AEM: Nanlin fan Ben et al. - plant rhizosphere growth promoting bacteria control soybean blight
- Vulkan practice first bullet
- [pulsar document] concepts and architecture
猜你喜欢

1.11 - bus

如何系统学习机器学习

Redis21 classic interview questions, extreme pull interviewer

FAQ | FAQ for building applications for large screen devices

University of Toronto: Anthony coach | the conditions of deep reinforcement learning can induce dynamic risk measurement

logback配置文件

【AutoSAR 九 C/S原理架构】

Teach you JDBC hand in hand -- structure separation

Baidu AI Cloud takes the lead in building a comprehensive and standardized platform for smart cloud

Vulkan-性能及精细化
随机推荐
[pulsar document] concepts and architecture
Arduino开发之按键检测与正弦信号输出
【AutoSAR 五 方法论】
lex && yacc && bison && flex 配置的問題
Web2.0 giants have deployed VC, and tiger Dao VC may become a shortcut to Web3
Array common operation methods sorting (including ES6) and detailed use
Nc17059 queue Q
University of Toronto: Anthony coach | the conditions of deep reinforcement learning can induce dynamic risk measurement
Preview word documents online
How SQLSEVER removes data with duplicate IDS
Shell 实现文件基本操作(切割、排序、去重)
字符设备注册常用的两种方法和步骤
helm 基础学习
JSON conversion tool class
Vulkan practice first bullet
【AutoSAR 二 AppL概述】
NC50965 Largest Rectangle in a Histogram
Multiprocess programming (I): basic concepts
【AutoSAR 三 RTE概述】
1.11 - bus