学习pv 的时候没有网络卷什么的,所以我把我的一台虚拟机当作网络存储节点,具体过程如下:
首先构建pv:
apiVersion: v1
kind: PersistentVolume
metadata:
name: example
-pv
labels:
release: "stable"
spec:
capacity:
storage: 10Gi
volumeMode: Filesystem
accessModes:
- ReadWriteOnce
persistentVolumeReclaimPolicy: Delete
storageClassName: local
-storage
local:
path: /data/along
nodeAffinity:
required:
nodeSelectorTerms:
- matchExpressions:
- key: kubernetes.io/hostname
operator: In
values:
- 172.31.0.53
创建成功结果
[root@vm172
-31
-0
-9 store_method
]
NAME CAPACITY ACCESS MODES RECLAIM POLICY STATUS CLAIM STORAGECLASS REASON AGE VOLUMEMODE
example
-pv 10Gi RWO Delete Bound default/example
-local
-claim local
-storage 97m Filesystem
描述如下
[root@vm172
-31
-0
-9 store_method
]
Name: example
-pv
Labels: release=stable
Annotations: pv.kubernetes.io/bound-by-controller: yes
Finalizers: [kubernetes.io/pv
-protection
]
StorageClass: local
-storage
Status: Bound
Claim: default/example
-local
-claim
Reclaim Policy
: Delete
Access Modes
: RWO
VolumeMode: Filesystem
Capacity: 10Gi
Node Affinity
:
Required Terms
:
Term 0
: kubernetes.io/hostname in
[172.31.0.53
]
Message:
Source:
Type: LocalVolume (a persistent volume backed by local storage on a node)
Path: /data/along
Events: <none
>
创建pvc
kind: PersistentVolumeClaim
apiVersion: v1
metadata:
name: example
-local
-claim
spec:
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 50Mi
storageClassName: local
-storage
selector:
matchLabels:
release: "stable"
如下
[root@vm172
-31
-0
-9 store_method
]
NAME STATUS VOLUME CAPACITY ACCESS MODES STORAGECLASS AGE
example
-local
-claim Bound example
-pv 10Gi RWO local
-storage 101m
创建pod使用pvc
apiVersion: v1
kind: Pod
metadata:
name: local
-pvc
-pod
spec:
containers:
- image: busybox
name: test
-local
-pvc
command: [ "sleep", "3600" ]
volumeMounts:
- mountPath: /data
name: data
-volume
volumes:
- name: data
-volume
persistentVolumeClaim:
claimName: example
-local
-claim
结果是这样的
[root@vm172
-31
-0
-9 store_method
]
Name: local
-pvc
-pod
...省略
...
Volumes:
data-volume:
Type: PersistentVolumeClaim (a reference to a PersistentVolumeClaim in the same namespace)
ClaimName: example
-local
-claim
ReadOnly: false
default-token-cnjj9:
Type: Secret (a volume populated by a Secret)
SecretName: default
-token
-cnjj9
Optional: false
...省略
...
进入pod写内容
[root@vm172
-31
-0
-9 store_method
]
/
bin data dev etc home proc root sys tmp usr var
/
[root@vm172
-31
-0
-9 store_method
]
Last login
: Thu Sep 3 16
:40
:00 2020 from 172.31.0.9
[root@vm172
-31
-0
-53 ~
]
[root@vm172
-31
-0
-53 ~
]
are you ok
?
参考文章 3种存储傻傻分不清楚! https://stor.51cto.com/art/201812/588905.htm###