k8s pv/pvc
阿新 • • 發佈:2021-10-26
# 定義PV
apiVersion: v1
kind: PersistentVolume
metadata:
name: nginx-pv
spec:
accessModes:
- ReadWriteMany
capacity:
storage: 2Gi
nfs:
path: /nfs/data/nginx # 在nfs server 該路徑需要存在
server: 192.168.136.200
---
# 定義PVC,用於消費PV
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: nginx-pvc
spec:
accessModes:
- ReadWriteMany
resources:
requests:
storage: 2Gi
---
# 定義Pod,指定需要使用的PVC
apiVersion: apps/v1beta1
kind: Deployment
metadata:
name: nginx
spec:
selector:
matchLabels:
app: nginx
template:
metadata:
labels:
app: nginx
spec:
containers:
- image: nginx
name: mysql
ports:
- containerPort: 80
volumeMounts:
- name: nginx-persistent-storage
mountPath: /usr/share/nginx/html
volumes:
- name: nginx-persistent-storage
persistentVolumeClaim:
claimName: nginx-pvc
[email protected]PVC與PV通過
PersistentVolume
中的spec.accessModes
和spec.capacity..storage
與PersistentVolumeClaim
中的spec.accessModes
和spec.resources.requests.storage
值一致來匹配。