标签:pts 挂载点 tar 磁盘 art name files ken tps
PVC和PV的设计,类似“接口”和“实现”的思想,开发者只知道使用“接口”PVC,运维人员负责给“接口”绑定具体的实现PV,说白了PVC就是一种特殊的Volume
大多数情况,持久化Volume的实现,依赖于远程存储服务,如远程文件存储(NFS、GlusterFS)、远程块存储(公有云提供的远程磁盘)等。
K8s需要使用这些存储服务,来为容器准备一个持久化的宿主机目录,以供以后挂载使用,创建这个目录分为两阶段:
可以理解为创建了一块NFS磁盘,相当于执行
gcloud compute instances attach-disk < 虚拟机名字 > --disk < 远程磁盘名字 >
为了使用这块磁盘,还需要挂载操作
这远程磁盘挂载到宿主机上,相当于执行
mount -t nfs <NFS 服务器地址 >:/ /var/lib/kubelet/pods/<Pod 的 ID>/volumes/kubernetes.io~<Volume 类型 >/<Volume 名字 >
通过这个挂载操作,Volume的宿主机目录就成为了一个远程NFS目录的挂载点,以后写入的所有文件,都会被保存在NFS服务器上
如果是已经有NFS磁盘,第一步可以省略.
同样,删除PV的时候,也需要Umount和Dettach两个阶段处理
apiVersion: v1
kind: PersistentVolume
metadata:
name: cqh
labels:
cqh: chenqionghe
spec:
capacity:
storage: 100Mi
volumeMode: Filesystem
accessModes: ["ReadWriteMany"]
persistentVolumeReclaimPolicy: Delete
storageClassName: local-storage
local:
path: /data/pv
nodeAffinity:
required:
nodeSelectorTerms:
- matchExpressions:
- key: cqh
operator: In
values:
- chenqionghe
创建后查看
root@VM-0-8-ubuntu:/home/ubuntu/statefulset# kubectl get pv
NAME CAPACITY ACCESS MODES RECLAIM POLICY STATUS CLAIM STORAGECLASS REASON AGE
cqh 100Mi RWX Delete Bound default/cqh local-storage 4m
kind: PersistentVolumeClaim
apiVersion: v1
metadata:
name: cqh
spec:
storageClassName: local-storage
accessModes:
- ReadWriteMany
resources:
requests:
storage: 100Mi
selector:
matchLabels:
cqh: chenqionghe
AccessModes为ReadWriteMany,表示这个Volume是可读写的,并且能挂载在多个节点上(官方支持的AccessMode)
执行创建后查看
root@VM-0-8-ubuntu:/home/ubuntu/statefulset# kubectl get pvc
NAME STATUS VOLUME CAPACITY ACCESS MODES STORAGECLASS AGE
cqh Bound cqh 100Mi RWX local-storage 4m
apiVersion: v1
kind: Pod
metadata:
name: cqh
spec:
containers:
- name: cqh-container
image: nginx
ports:
- containerPort: 80
name: "http-server"
volumeMounts:
- mountPath: "/usr/share/nginx/html"
name: pv-storage
volumes:
- name: pv-storage
persistentVolumeClaim:
claimName: cqh
创建后查看
NAME READY STATUS RESTARTS AGE IP NODE NOMINATED NODE
cqh 1/1 Running 0 4m 10.244.0.46 vm-0-8-ubuntu <none>
root@VM-0-8-ubuntu:/home/ubuntu/statefulset# kubectl describe po cqh
Name: cqh
Namespace: default
...
Volumes:
pv-storage:
Type: PersistentVolumeClaim (a reference to a PersistentVolumeClaim in the same namespace)
ClaimName: cqh
ReadOnly: false
default-token-gqfrx:
Type: Secret (a volume populated by a Secret)
SecretName: default-token-gqfrx
Optional: false
...
Events:
Type Reason Age From Message
---- ------ ---- ---- -------
Normal Scheduled 4m default-scheduler Successfully assigned default/cqh to vm-0-8-ubuntu
Normal Pulling 4m kubelet, vm-0-8-ubuntu pulling image "nginx"
Normal Pulled 4m kubelet, vm-0-8-ubuntu Successfully pulled image "nginx"
Normal Created 4m kubelet, vm-0-8-ubuntu Created container
Normal Started 4m kubelet, vm-0-8-ubuntu Started container
标签:pts 挂载点 tar 磁盘 art name files ken tps
原文地址:https://www.cnblogs.com/chenqionghe/p/11609008.html