当前位置:网站首页>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 17:11:00 【Silly [email protected]】
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 .
This paper is written by mdnice Multi platform Publishing
版权声明
本文为[Silly [email protected][email protected]]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/184/202207031706233888.html
边栏推荐
猜你喜欢
Why is WPA3 security of enterprise business so important?
【RT-Thread】nxp rt10xx 设备驱动框架之--hwtimer搭建和使用
The largest matrix (H) in a brush 143 monotone stack 84 histogram
Pools de Threads: les composants les plus courants et les plus sujets aux erreurs du Code d'affaires
大变局!全国房价,跌破万元大关
手把手带你入门 API 开发
Static program analysis (I) -- Outline mind map and content introduction
Recommendation of good books on learning QT programming
Cross border e-commerce: advantages of foreign trade enterprises in overseas social media marketing
Mysql database -dql
随机推荐
基于主机的入侵系统IDS
Great changes! National housing prices fell below the 10000 yuan mark
【RT-Thread】nxp rt10xx 设备驱动框架之--Pin搭建和使用
Unity notes unityxr simple to use
UCORE overview
【JokerのZYNQ7020】DDS_ Compiler。
One brush 147-force deduction hot question-4 find the median of two positive arrays (H)
免费数据 | 新库上线 | CnOpenData中国保险中介机构网点全集数据
New library online | cnopendata China bird watching record data
关于学习Qt编程的好书精品推荐
Take you to API development by hand
One brush 142 monotone stack next larger element II (m)
kubernetes资源对象介绍及常用命令(三)
Free data | new library online | cnopendata complete data of China's insurance intermediary outlets
Meituan side: why does thread crash not cause JVM crash
[combinatorial mathematics] recursive equation (example of recursive equation 2 Hanoi Tower | example of recursive equation 3 insertion sequencing)
Open vsftpd port under iptables firewall
On Lagrange interpolation and its application
Assembly instance analysis -- screen display in real mode
One brush 148 force deduction hot question-5 longest palindrome substring (m)