毛台

Hello,how is going,everybody!

[k8s]pod持久存储的几种方式图解

参考: https://kubernetes.io/docs/concepts/storage/volumes/

1.emptyDir

apiVersion: v1
kind: Pod
metadata:
  name: test-pd
spec:
  containers:
  - image: gcr.io/google_containers/test-webserver
    name: test-container
    volumeMounts:
    - mountPath: /cache
      name: cache-volume
  volumes:
  - name: cache-volume
    emptyDir: {}

2.hostPath

apiVersion: v1
kind: Pod
metadata:
  name: test-pd
spec:
  containers:
  - image: gcr.io/google_containers/test-webserver
    name: test-container
    volumeMounts:
    - mountPath: /test-pd
      name: test-volume
  volumes:
  - name: test-volume
    hostPath:
      # directory location on host
      path: /data

3.pod持久存储

  • 方式1: pod直接挂载nfs-server
volumes:
  - name: nfs
    nfs:
      server: 192.168.1.1
      path:"/"

静态提供:管理员手动创建多个PV,供PVC使用。
动态提供:动态创建PVC特定的PV,并绑定。

  • 方式2: 手动创建pv
pv.yaml
apiVersion: v1
kind: PersistentVolume
metadata:
  name: pv003
spec:
  capacity:
    storage: 5Gi
  accessModes:
    - ReadWriteOnce
  nfs:
    path: /somepath
    server: 192.168.1.1
$ kubectl get pv
NAME                                       CAPACITY   ACCESSMODES   RECLAIMPOLICY   STATUS    CLAIM                             STORAGECLASS     REASON    AGE
nfs-pv-heketi                              300Mi      ROX           Retain          Bound     default/nfs-pvc-heketi                                       7d
pvc-02b8a30d-8e28-11e7-a07a-025622f1d9fa   50Gi       RWX           Retain          Bound     kube-public/jenkins-pvc           heketi-storage             5d

pv可以设置三种回收策略:保留(Retain),回收(Recycle)和删除(Delete)。

  • 保留策略:允许人工处理保留的数据。
  • 删除策略:将删除pv和外部关联的存储资源,需要插件支持。
  • 回收策略:将执行清除操作,之后可以被新的pvc使用,需要插件支持。

pv的状态:

  • Available – 资源尚未被claim使用
  • Bound – 已经绑定到某个pvc上
  • Released – 对应的pvc被删除,但是资源还没有被集群回收
  • Failed – 自动回收失败

访问权限

ReadWriteOnce – 被单个节点mount为读写rw模式
ReadOnlyMany – 被多个节点mount为只读ro模式
ReadWriteMany – 被多个节点mount为读写rw模式
参考: http://dockone.io/article/2290 没什么卵用
这里写图片描述

pvc.yaml
kind: PersistentVolumeClaim
apiVersion: v1
metadata:
  name: myclaim
spec:
  accessModes:
    - ReadWriteOnce
  resources:
    requests:
      storage: 5Gi
mypod.yaml

volumes:
  - name: mypod
    persistentVolumeClaim:
      claimName: myclaim

逻辑关系图解1

逻辑关系图解2

为了说明一个class对应多个pvc.

$ kubectl get pvc
NAME             STATUS    VOLUME          CAPACITY   ACCESSMODES   STORAGECLASS   AGE
nfs-nginx        Bound     nfs-xx          300Mi      ROX                          7d
$ kubectl get pv
NAME                                       CAPACITY   ACCESSMODES   RECLAIMPOLICY   STATUS    CLAIM                             STORAGECLASS     REASON    AGE
nfs-pv-heketi                              300Mi      ROX           Retain          Bound     default/nfs-pvc-heketi                                       7d
pvc-02b8a30d-8e28-11e7-a07a-025622f1d9fa   50Gi       RWX           Retain          Bound     kube-public/jenkins-pvc           heketi-storage             5d
pvc-05bbb05c-8edf-11e7-a07a-025622f1d9fa   30Gi       RWX           Retain          Bound     kube-public/mysql-develop-pvc     heketi-storage             5d
pvc-0b3ecd56-8ffb-11e7-a07a-025622f1d9fa   50Gi       RWX           Retain          Bound     kube-public/gitlab-pvc            heketi-storage             3d
pvc-4e657ad5-9205-11e7-a07a-025622f1d9fa   2Gi        RWX           Delete          Bound     kube-public/private-pvc           heketi-storage             1d
pvc-73dec4f4-8feb-11e7-a07a-025622f1d9fa   10Gi       RWX           Retain          Bound     kube-public/gitlab-postgres-pvc   heketi-storage             3d
pvc-d74aff4a-91fc-11e7-a07a-025622f1d9fa   2Gi        RWX           Delete          Bound     kube-public/spring-pvc            heketi-storage             1d
pvc-db821d79-8fb6-11e7-a07a-025622f1d9fa   3Gi        RWX           Retain          Bound     kube-public/gitlab-redis-pvc      heketi-storage             3d

参考nfs更能看清晰一些

代码配置逻辑关系图解

实例

阅读更多
版权声明:亦余心之所善兮,虽九死其犹未悔. https://blog.csdn.net/iiiiher/article/details/77867686
想对作者说点什么? 我来说一句

没有更多推荐了,返回首页

加入CSDN,享受更精准的内容推荐,与500万程序员共同成长!
关闭
关闭