pv 与pvc的绑定

创建pv

apiVersion: v1

kind: PersistentVolume

metadata:

name: pv003

labels:

app: vnc003

namespace: vnc-space

spec:

capacity:

storage: 5Gi

accessModes:

- ReadWriteMany

persistentVolumeReclaimPolicy: Retain

hostPath:

path: "/home/pv"

 

 

 

创建pvc

apiVersion: v1

kind: PersistentVolumeClaim

metadata:

name: pvc003

labels:

app: vnc003

namespace: vnc-space

spec:

# storageClassName: manual

accessModes:

- ReadWriteMany

resources:

requests:

storage: 100Mi

selector:

matchLabels:

app: vnc003

 

 

 

查看绑定情况

[root@lys-192 ~]# kubectl get pvc --show-labels

NAME STATUS VOLUME CAPACITY ACCESS MODES STORAGECLASS AGE LABELS

pvc003 Bound pv004 5Gi RWX 10m app=vnc

pvc004 Bound pv003 5Gi RWX 5m42s app=vnc

[root@lys-192 ~]# kubectl get pv --show-labels

NAME CAPACITY ACCESS MODES RECLAIM POLICY STATUS CLAIM STORAGECLASS REASON AGE LABELS

pv003 5Gi RWX Retain Bound default/pvc004 4m19s app=vnc003

pv004 5Gi RWX Retain Bound default/pvc003 110s

 

 

创建pod使用pvc

apiVersion: v1

kind: Pod

metadata:

name: nginx

labels:

role: web-frontend

namespace: vnc-space

spec:

containers:

- name: web

image: nginx

ports:

- name: web

containerPort: 80

volumeMounts:

- name: pv001

mountPath: "/usr/share/nginx/html"

volumes:

- name: pv001

persistentVolumeClaim: ## <--这字段

claimName: pvc003

你可能感兴趣的:(kubernetes)