当前位置:网站首页>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
边栏推荐
- How do large consumer enterprises make digital transformation?
- [combinatorics] recursive equation (definition of general solution | structure theorem of general solution of recursive equation without multiple roots)
- Rsync远程同步
- Host based intrusion system IDS
- 远程办公之如何推进跨部门项目协作 | 社区征文
- Squid 服务启动脚本
- Mysql database DDL and DML
- RedHat 6.2 配置 Zabbix
- 简单配置PostFix服务器
- How to allow remote connection to MySQL server on Linux system?
猜你喜欢
网络安全web渗透技术
【RT-Thread】nxp rt10xx 设备驱动框架之--rtc搭建和使用
Redis: operation commands for list type data
新库上线 | CnOpenData中国保险机构网点全集数据
MySQL Basics
人生还在迷茫?也许这些订阅号里有你需要的答案!
Pools de Threads: les composants les plus courants et les plus sujets aux erreurs du Code d'affaires
Web crawler knowledge day03
免费数据 | 新库上线 | CnOpenData中国保险中介机构网点全集数据
图之深度优先搜索
随机推荐
汇编实例解析--实模式下屏幕显示
New library online | cnopendata China bird watching record data
远程办公之如何推进跨部门项目协作 | 社区征文
Examination questions for the assignment of selected readings of British and American Literature in the course examination of Fujian Normal University in February 2022
The most complete postman interface test tutorial in the whole network, API interface test
RF analyze demo build step by step
Javescript variable declaration -- VaR, let, const
匯編實例解析--實模式下屏幕顯示
One brush 145 force deduction hot question-2 sum of two numbers (m)
[combinatorics] recursive equation (constant coefficient linear homogeneous recursive equation | constant coefficient, linear, homogeneous concept description | constant coefficient linear homogeneous
Open vsftpd port under iptables firewall
美团一面:为什么线程崩溃崩溃不会导致 JVM 崩溃
Necessary ability of data analysis
免费数据 | 新库上线 | CnOpenData中国保险中介机构网点全集数据
C语言按行修改文件
Online assignment 3 of mobile Internet technology in the 20th autumn of electronic technology [standard answer]
27. Input 3 integers and output them in descending order. Pointer method is required.
Design e-commerce spike
[combinatorial mathematics] recursive equation (example of recursive equation 2 Hanoi Tower | example of recursive equation 3 insertion sequencing)
Life is still confused? Maybe these subscription numbers have the answers you need!