当前位置:网站首页>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 .
边栏推荐
- 【AutoSAR 十一 通信相关机制】
- 2022上半年值得被看见的10条文案,每一句都能带给你力量!
- Teach you JDBC hand in hand -- structure separation
- 【小程序项目开发-- 京东商城】uni-app之自定义搜索组件(中)-- 搜索建议
- Hundreds of continuous innovation to create free low code office tools
- 【AutoSAR 四 BSW概述】
- 简单聊聊运维监控的其他用途
- Graduation summary
- Shell implements basic file operations (SED edit, awk match)
- Vulkan performance and refinement
猜你喜欢

1.11 - bus

Arduino开发之按键检测与正弦信号输出

Web2.0 giants have deployed VC, and tiger Dao VC may become a shortcut to Web3

Unity learns from spaceshooter to record the difference between fixedupdate and update in unity for the second time

Rust ownership (very important)

Shell implements basic file operations (SED edit, awk match)

Shell implements basic file operations (cutting, sorting, and de duplication)

University of Oslo: Li Meng | deep reinforcement learning based on swing transformer

世平信息首席科学家吕喆:构建以数据和人员为中心的安全能力

Rust所有权(非常重要)
随机推荐
机器学习:numpy版本线性回归预测波士顿房价
使用jenkins之二Job
Set up nacos2 X cluster steps and problems encountered
How to find out the currently running version of Solr- How do I find out version of currently running Solr?
leetcode-2115:从给定原材料中找到所有可以做出的菜
1.11 - 总线
Shell implements basic file operations (SED edit, awk match)
Nc20806 District interval
线程的启动与优先级
Attributeerror: 'tuple' object has no attribute 'layer' problem solving
NC24325 [USACO 2012 Mar S]Flowerpot
Leetcode 294. Flip game II (game theory)
NC50528 滑动窗口
多进程编程(二):管道
字符设备注册常用的两种方法和步骤
NC24840 [USACO 2009 Mar S]Look Up
数组与集合性能比较
2022上半年值得被看见的10条文案,每一句都能带给你力量!
Extension of flutter
Graduation summary