k8s的PV/PVC

概述

Volume

kubernentes的存储部分第一个介绍了Volume。Volume可以支持localnfscephfsglusterfs以及各种云计算平台。

官网Volume的配置都是在一个创建pod的yaml文件中,例如

apiVersion: v1
kind: Pod
metadata:
  name: test-pd
spec:
  containers:
  - image: k8s.gcr.io/test-webserver
    name: test-container
    volumeMounts:
    - mountPath: /test-pd
      name: test-volume
  volumes:
  - name: test-volume
    hostPath:
      # directory location on host
      path: /data
      # this field is optional
      type: Directory

Persistent Volume和Persistent Volume Claim

除了Volume之外,kubernetes还提供了Persistent Volume的方法。Volume主要是为了存储一些有必要保存的数据,而Persistent Volume主要是为了管理集群的存储。

Persistent Volume相对独立于Pods,单独创建。比如:

apiVersion: v1
kind: PersistentVolume
metadata:
  name: nfs
spec:
  storageClassName: manual
  capacity:
    storage: 1Gi
  accessModes:
    - ReadWriteMany
  nfs:
    server: 192.168.207.121
    path: "/nas/dg_vd"

Persistent Volume对具体的存储进行配置和分配,而Pods等则可以使用Persistent Volume抽象出来的存储资源,不需要知道集群的存储细节。

Persistent Volume和Persistent Volume Claim类似Pods和Nodes的关系,创建Pods需要消耗一定的Nodes的资源。而Persistent Volume则是提供了各种存储资源,而Persistent Volume Claim提出需要的存储标准,然后从现有存储资源中匹配或者动态建立新的资源,最后将两者进行绑定。

PVC的创建

上面已经提到了创建PV的配置文件。PVC的内容如下:

apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  name: nfs
spec:
  accessModes:
    - ReadWriteMany
  storageClassName: manual
  resources:
    requests:
      storage: 1Gi

Pods的使用

Pods使用的是PersistentVolumeClaim而非PersistentVolume

具体配置如下

apiVersion: v1
kind: Pod
metadata:
  name: testpv
  labels:
    role: web-frontend
spec:
  containers:
  - name: web
    image: nginx
    ports:
      - name: web
        containerPort: 80
    volumeMounts:
        - name: nfs
          mountPath: "/usr/share/nginx/html"
  volumes:
  - name: nfs
    persistentVolumeClaim:
      claimName: nfs

一些注意事项

在配置文件中的kind是PersistentVolumePersistentVolumeClaim。但是查询时,使用的是缩写pv,pvc

概述

Volume

kubernentes的存储部分第一个介绍了Volume。Volume可以支持localnfscephfsglusterfs以及各种云计算平台。

官网Volume的配置都是在一个创建pod的yaml文件中,例如

apiVersion: v1
kind: Pod
metadata:
  name: test-pd
spec:
  containers:
  - image: k8s.gcr.io/test-webserver
    name: test-container
    volumeMounts:
    - mountPath: /test-pd
      name: test-volume
  volumes:
  - name: test-volume
    hostPath:
      # directory location on host
      path: /data
      # this field is optional
      type: Directory

Persistent Volume和Persistent Volume Claim

除了Volume之外,kubernetes还提供了Persistent Volume的方法。Volume主要是为了存储一些有必要保存的数据,而Persistent Volume主要是为了管理集群的存储。

Persistent Volume相对独立于Pods,单独创建。比如:

apiVersion: v1
kind: PersistentVolume
metadata:
  name: nfs
spec:
  storageClassName: manual
  capacity:
    storage: 1Gi
  accessModes:
    - ReadWriteMany
  nfs:
    server: 192.168.207.121
    path: "/nas/dg_vd"

Persistent Volume对具体的存储进行配置和分配,而Pods等则可以使用Persistent Volume抽象出来的存储资源,不需要知道集群的存储细节。

Persistent Volume和Persistent Volume Claim类似Pods和Nodes的关系,创建Pods需要消耗一定的Nodes的资源。而Persistent Volume则是提供了各种存储资源,而Persistent Volume Claim提出需要的存储标准,然后从现有存储资源中匹配或者动态建立新的资源,最后将两者进行绑定。

PVC的创建

上面已经提到了创建PV的配置文件。PVC的内容如下:

apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  name: nfs
spec:
  accessModes:
    - ReadWriteMany
  storageClassName: manual
  resources:
    requests:
      storage: 1Gi

Pods的使用

Pods使用的是PersistentVolumeClaim而非PersistentVolume

具体配置如下

apiVersion: v1
kind: Pod
metadata:
  name: testpv
  labels:
    role: web-frontend
spec:
  containers:
  - name: web
    image: nginx
    ports:
      - name: web
        containerPort: 80
    volumeMounts:
        - name: nfs
          mountPath: "/usr/share/nginx/html"
  volumes:
  - name: nfs
    persistentVolumeClaim:
      claimName: nfs

一些注意事项

在配置文件中的kind是PersistentVolumePersistentVolumeClaim。但是查询时,使用的是缩写pv,pvc

©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

  • 再美的景 也就是景 再美的景 没有人影 仅仅是景 景配上人 无论行走 还是微笑 景就活了 美景佳人 相依共存 景更...
    峰霞仙子阅读 1,657评论 2 10
  •   面向对象设计原则,是一种指导思想,在程序设计过程中,要尽量的去遵守这些原则,用于解决面向对象设计中的可维护性,...
    快乐泥巴阅读 5,422评论 0 3
  • 创建新版本库 $ git init #初始化本地版本库该命令将创建一个名为 .git 的子目录,这个子目录含有你初...
    Frank_io阅读 1,526评论 0 0
  • m1、直通车一天500,一年18万,最后什么都没有,还不如2周花完18万,可能还出个爆款 2、消费行为场景 3、 h
    书雪同学阅读 1,445评论 0 0
  • 0、history 查看历史记录 1、列出文件ls 参数 目录名 例: 看看驱动目录下有什么:ls ...
    __哈哈__阅读 3,552评论 3 1

友情链接更多精彩内容