#我的新年Flag#K8s PVC
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了#我的新年Flag#K8s PVC相关的知识,希望对你有一定的参考价值。
PV
PersistentVolume: 集群中的一块存储,由管理员配置或使用存储类动态配置。
PVC
PersistentVolumeClaim: 是一个持久化存储卷,我们在创建pod时
可以定义这个类型的存储卷。
nfs 创建共享目录
[root@k8smaster5 /]# mkdir /data/volume_test/v1,2,3,4,5,6,7,8,9,10 -p
共享目录导入nfs配置文件
[root@k8smaster5 etc]# vi exports
/data/volumes *(rw,no_root_squash)
/data/volumes_test/v1 *(rw,no_root_squash)
/data/volumes_test/v2 *(rw,no_root_squash)
/data/volumes_test/v3 *(rw,no_root_squash)
/data/volumes_test/v4 *(rw,no_root_squash)
/data/volumes_test/v5 *(rw,no_root_squash)
/data/volumes_test/v6 *(rw,no_root_squash)
/data/volumes_test/v7 *(rw,no_root_squash)
/data/volumes_test/v8 *(rw,no_root_squash)
/data/volumes_test/v9 *(rw,no_root_squash)
/data/volumes_test/v10 *(rw,no_root_squash)
nfs配置生效
[root@k8smaster5 etc]# exportfs -arv
exporting *:/data/volume_test/v10
exporting *:/data/volume_test/v9
exporting *:/data/volume_test/v8
exporting *:/data/volume_test/v7
exporting *:/data/volume_test/v6
exporting *:/data/volume_test/v5
exporting *:/data/volume_test/v4
exporting *:/data/volume_test/v3
exporting *:/data/volume_test/v2
exporting *:/data/volume_test/v1
exporting *:/data/volumes
创建PV Yaml
[root@k8smaster4 dir]# cat pv.yaml
apiVersion: v1
kind: PersistentVolume
metadata:
name: v1
labels:
app: v1
spec:
nfs:
server: 192.168.0.220
path: /data/volume_test/v1
accessModes: ["ReadWriteOnce"]
capacity:
storage: 1Gi
---
apiVersion: v1
kind: PersistentVolume
metadata:
name: v2
labels:
app: v2
spec:
nfs:
server: 192.168.0.220
path: /data/volume_test/v2
accessModes: ["ReadOnlyMany"]
capacity:
storage: 2Gi
---
apiVersion: v1
kind: PersistentVolume
metadata:
name: v3
labels:
app: v3
spec:
nfs:
server: 192.168.0.220
path: /data/volume_test/v3
accessModes: ["ReadWriteMany"]
capacity:
storage: 1Gi
查看创建结果
[root@k8smaster4 dir]# kubectl get pv
NAME CAPACITY ACCESS MODES RECLAIM POLICY STATUS CLAIM STORAGECLASS REASON AGE
v1 1Gi RWO Retain Available 65s
v2 2Gi ROX Retain Available 65s
v3 1Gi RWX Retain Available 65s
创建PVC Yaml
[root@k8smaster4 dir]# cat pvc.yaml
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: pvc-v1
spec:
accessModes: ["ReadWriteOnce"]
selector:
matchLabels:
app: v1
resources:
requests: 1Gi
---
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: pvc-v2
spec:
accessModes: ["ReadOnlyMany"]
selector:
matchLabels:
app: v2
resources:
requests: 2Gi
---
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: pvc-v3
spec:
accessModes: ["ReadWriteMany"]
selector:
matchLabels:
app: v3
resources:
requests: 1Gi
查看PVC创建结果
[root@k8smaster4 dir]# kubectl get pvc
NAME STATUS VOLUME CAPACITY ACCESS MODES STORAGECLASS AGE
pvc-v1 Bound v1 1Gi RWO 5s
pvc-v2 Bound v2 2Gi ROX 5s
pvc-v3 Bound v3 1Gi RWX 5s
Pod挂载PVC
[root@k8smaster4 dir]# cat pod-pvc.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
name: pvc-test
spec:
replicas: 3
selector:
matchLabels:
cunchu: pvc
template:
metadata:
labels:
cunchu: pvc
spec:
containers:
- name: test-pvc
image: docker.io/library/nginx
imagePullPolicy: IfNotPresent
ports:
- containerPort: 80
protocol: TCP
volumeMounts:
- name: nginx-html
mountPath: /usr/share/nginx/html
volumes:
- name: nginx-html
persistentVolumeClaim:
claimName: pvc-v1
以上是关于#我的新年Flag#K8s PVC的主要内容,如果未能解决你的问题,请参考以下文章