码迷,mamicode.com
首页 > 其他好文 > 详细

23,k8s 之PV,PVC

时间:2020-07-08 22:40:04      阅读:66      评论:0      收藏:0      [点我收藏+]

标签:pps   mount   资源管理   temp   sel   rpo   hang   存储   app   

PersistentVolume:
	PersistenVolume(PV):对存储资源创建和使用的抽象,使得存储作为集群中的资源管理
		静态
		动态
	PersistentVolumeClaim(PVC):让用户不需要关心具体的Volume实现细节
	
搭建nfs:
		客户端和服务端都安装:
			yum install -y nfs-utils
		服务端执行:
			[root@centos7 ~]# cat /etc/exports
			/data/nfs/wwwroot *(rw,no_root_squash)
			[root@centos7 ~]#
			[root@centos7 ~]# systemctl start nfs
			
		

	
	
pv 静态供给:
[root@centos7 ~]# cat pv.yaml 
apiVersion: v1
kind: PersistentVolume
metadata:
  name: my-pv
spec:
  capacity:
    storage: 5Gi
  accessModes:
    - ReadWriteMany
  nfs:
    path: /data/nfs/wwwroot
    server: 192.168.0.14
[root@centos7 ~]# 
[root@centos7 ~]# kubectl apply -f pv.yaml 
persistentvolume/my-pv created
[root@centos7 ~]# 
[root@centos7 ~]# kubectl get pv
NAME    CAPACITY   ACCESS MODES   RECLAIM POLICY   STATUS      CLAIM   STORAGECLASS   REASON   AGE
my-pv   5Gi        RWX            Retain           Available                                   8s
[root@centos7 ~]# 

[root@centos7 ~]# cat pod-pvc.yaml 
apiVersion: apps/v1
kind: Deployment
metadata:
  name: nginx-deployment
spec:
  replicas: 3
  selector:
    matchLabels:
      app: nginx
  template:
    metadata:
      labels:
        app: nginx
    spec:
      containers:
      - name: nginx
        image: nginx
        volumeMounts:
        - name: wwwroot
          mountPath: /usr/share/nginx/html
        ports:
        - containerPort: 80
      volumes:
      - name: wwwroot
        persistentVolumeClaim:
          claimName: my-pvc

---

apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  name: my-pvc
spec:
  accessModes:
    - ReadWriteMany
  resources:
    requests:
      storage: 5Gi
[root@centos7 ~]# 
[root@centos7 ~]# 
[root@centos7 ~]# kubectl apply -f pod-pvc.yaml 
deployment.apps/nginx-deployment created
persistentvolumeclaim/my-pvc unchanged
[root@centos7 ~]# 
[root@centos7 ~]# kubectl get pv,pvc
NAME                     CAPACITY   ACCESS MODES   RECLAIM POLICY   STATUS   CLAIM            STORAGECLASS   REASON   AGE
persistentvolume/my-pv   5Gi        RWX            Retain           Bound    default/my-pvc                           3m

NAME                           STATUS   VOLUME   CAPACITY   ACCESS MODES   STORAGECLASS   AGE
persistentvolumeclaim/my-pvc   Bound    my-pv    5Gi        RWX                           2m13s
[root@centos7 ~]# 
[root@centos7 ~]# 
[root@centos7 ~]# kubectl get pods
NAME                               READY   STATUS    RESTARTS   AGE
nginx-deployment-bc96745d9-2mzqx   1/1     Running   0          2m33s
nginx-deployment-bc96745d9-68lmm   1/1     Running   0          2m33s
nginx-deployment-bc96745d9-khlpm   1/1     Running   0          2m33s
[root@centos7 ~]# kubectl exec -it nginx-deployment-bc96745d9-2mzqx bash
root@nginx-deployment-bc96745d9-2mzqx:/# 
root@nginx-deployment-bc96745d9-2mzqx:/# ls /usr/share/nginx/html/
root@nginx-deployment-bc96745d9-2mzqx:/# ls /usr/share/nginx/html/
index.html
root@nginx-deployment-bc96745d9-2mzqx:/# 





pv 动态供给:
	Nfs 不支持动态供给,所以要先安装nfs的插件。
	Dynamic Provisioning机制工作的核心在于StorageClass的API对象。
	StorageClass声明存储插件,用于自动创建PV。



  

23,k8s 之PV,PVC

标签:pps   mount   资源管理   temp   sel   rpo   hang   存储   app   

原文地址:https://www.cnblogs.com/k8s-pod/p/13269485.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!