首页
技术小册
AIGC
面试刷题
技术文章
MAGENTO
云计算
视频课程
源码下载
PDF书籍
「涨薪秘籍」
登录
注册
1. Volume
1.1. 模板
1.2. emptyDir
1.2.1. 介绍
1.2.2. 案例
1.3. hostPath
1.4. nfs
2. PV/PVC
2.1. PV/PVC介绍
2.1.1. 介绍
2.1.2. PV/PVC工作方式
2.2. 模板
2.3. 案例
2.3.1. PV/PVC定义和使用
3. ConfigMap
3.1. 介绍
3.2. 模板
3.3. 案例
3.3.1. 创建configmap对象
3.3.2. 使用env方式引用
3.3.3. 使用volume方式引用
4. Secret
4.1. 介绍
4.2. 模板
当前位置:
首页>>
技术小册>>
Kubernets合辑7-存储
小册名称:Kubernets合辑7-存储
准备NFS存储 ``` [root@hdss7-200 volume]# showmount -e Export list for hdss7-200.host.com: /tmp/data/websit/03 10.4.7.0/24 /tmp/data/websit/02 10.4.7.0/24 /tmp/data/websit/01 10.4.7.0/24 ``` 定义PV ``` [root@hdss7-200 volume]# cat /data/k8s-yaml/base_resource/volume/pv.yaml apiVersion: v1 kind: PersistentVolume metadata: name: nfs-pv001 labels: type: SSD fs: nfs speed: fast spec: accessModes: - ReadWriteMany - ReadWriteOnce - ReadOnlyMany capacity: storage: 5Gi nfs: server: hdss7-200 path: /tmp/data/websit/01 --- apiVersion: v1 kind: PersistentVolume metadata: name: nfs-pv002 labels: type: SSD fs: nfs speed: slow spec: accessModes: - ReadWriteMany - ReadOnlyMany capacity: storage: 5Gi nfs: server: hdss7-200 path: /tmp/data/websit/02 --- apiVersion: v1 kind: PersistentVolume metadata: name: nfs-pv003 labels: type: SSD fs: nfs speed: slow spec: accessModes: - ReadWriteMany - ReadWriteOnce capacity: storage: 10Gi nfs: server: hdss7-200 path: /tmp/data/websit/03 ``` 定义PVC和deployment ``` [root@hdss7-200 volume]# cat /data/k8s-yaml/base_resource/volume/pvc-depolyment.yaml apiVersion: v1 kind: PersistentVolumeClaim metadata: name: website-root-pvc namespace: app labels: tier: website type: nfs spec: accessModes: - ReadWriteMany resources: requests: storage: 5Gi selector: matchLabels: fs: nfs speed: fast --- apiVersion: apps/v1 kind: Deployment metadata: name: pvc-deploy namespace: app labels: tier: volume role: nfs spec: replicas: 2 selector: matchLabels: tier: volume role: nfs template: metadata: labels: tier: volume role: nfs spec: containers: - name: main-container image: harbor.od.com/public/busybox:v1.31.1 volumeMounts: - name: web-root mountPath: /data/web/html command: - httpd args: - -f - -h - "/data/web/html" volumes: - name: web-root persistentVolumeClaim: claimName: website-root-pvc ``` 创建 ``` [root@hdss7-21 ~]# kubectl apply -f http://k8s-yaml.od.com/base_resource/volume/pv.yaml [root@hdss7-21 ~]# kubectl apply -f http://k8s-yaml.od.com/base_resource/volume/pvc-depolyment.yaml [root@hdss7-21 ~]# kubectl get pv --show-labels NAME CAPACITY ACCESS MODES RECLAIM POLICY STATUS CLAIM STORAGECLASS REASON AGE LABELS nfs-pv001 5Gi RWO,ROX,RWX Retain Bound app/website-root-pvc 25m fs=nfs,speed=fast,type=SSD nfs-pv002 5Gi ROX,RWX Retain Available 25m fs=nfs,speed=slow,type=SSD nfs-pv003 10Gi RWO,RWX Retain Available 25m fs=nfs,speed=slow,type=SSD [root@hdss7-21 ~]# kubectl get pvc -n app NAME STATUS VOLUME CAPACITY ACCESS MODES STORAGECLASS AGE website-root-pvc Bound nfs-pv001 5Gi RWO,ROX,RWX 13m [root@hdss7-21 ~]# kubectl get pod -l tier=volume -n app -o wide NAME READY STATUS RESTARTS AGE IP NODE NOMINATED NODE READINESS GATES pvc-deploy-86847c7b6b-mqvm5 1/1 Running 0 14m 172.7.21.11 hdss7-21.host.com <none> <none> pvc-deploy-86847c7b6b-x4p6m 1/1 Running 0 8m56s 172.7.22.8 hdss7-22.host.com <none> <none> ``` 测试 ``` [root@hdss7-21 ~]# kubectl exec pvc-deploy-86847c7b6b-mqvm5 -n app -- /bin/sh -c "echo 'hello world' > /data/web/html/index.html" [root@hdss7-21 ~]# curl -s 172.7.21.11;curl -s 172.7.22.8 # 主页文件已生成 hello world hello world [root@hdss7-21 ~]# kubectl delete pod pvc-deploy-86847c7b6b-mqvm5 pvc-deploy-86847c7b6b-x4p6m -n app pod "pvc-deploy-86847c7b6b-mqvm5" deleted pod "pvc-deploy-86847c7b6b-x4p6m" deleted [root@hdss7-21 ~]# kubectl get pod -l tier=volume -n app -o wide NAME READY STATUS RESTARTS AGE IP NODE NOMINATED NODE READINESS GATES pvc-deploy-86847c7b6b-7gqqs 1/1 Running 0 62s 172.7.21.12 hdss7-21.host.com <none> <none> pvc-deploy-86847c7b6b-drm28 1/1 Running 0 62s 172.7.22.11 hdss7-22.host.com <none> <none> [root@hdss7-21 ~]# curl -s 172.7.21.12; curl -s 172.7.22.11 # Pod删除重建后,文件依旧存在 hello world hello world ```
上一篇:
2.3. 案例
下一篇:
3. ConfigMap
该分类下的相关小册推荐:
Kubernets合辑13-集群监控
Kubernets合辑9-资源约束
Kubernets合辑5-Pod控制器
Kubernetes中文教程(五)
Kubernets合辑3-kubernetes介绍
Kubernetes中文教程(三)
Kubernets合辑12-配置中心
Kubernets合辑10-网络
Kubernets合辑4-kubernetes入门
Kubernets合辑8-权限控制
Kubernets合辑15-持续部署
Kubernetes中文教程(六)