凯发k8国际娱乐官网入口-k8凯发> 云容器引擎 cce> > > sfs turbo动态创建子目录并挂载
更新时间:2023-10-27 gmt 08:00

sfs turbo动态创建子目录并挂载-凯发k8国际娱乐官网入口

背景信息

sfs turbo容量最小500g,且不是按使用量计费。sfs turbo挂载时默认将根目录挂载到容器,而通常情况下负载不需要这么大容量,造成浪费。

everest插件支持一种在sfs turbo下动态创建子目录的方法,能够在sfs turbo下动态创建子目录并挂载到容器,这种方法能够共享使用sfs turbo,从而更加经济合理的利用sfs turbo存储容量。

约束与限制

  • 仅支持1.15 集群。
  • 集群必须使用everest插件,插件版本要求1.1.13 。
  • 不支持安全容器。
  • 使用everest 1.2.69之前或2.1.11之前的版本时,使用子目录功能时不能同时并发创建超过10个pvc。推荐使用everest 1.2.69及以上或2.1.11及以上的版本。

创建subpath类型sfs turbo存储卷

subpath模式的卷请勿通过前端进行“扩容”、“解关联”、“删除”等操作。

  1. 创建sfs turbo资源,选择网络时,请选择与集群相同的vpc与子网。
  2. 新建一个storageclass的yaml文件,例如sfsturbo-subpath-sc.yaml。

    配置示例:

    apiversion: storage.k8s.io/v1
    allowvolumeexpansion: true
    kind: storageclass
    metadata:
      name: sfsturbo-subpath-sc
    mountoptions:
    - lock
    parameters:
      csi.storage.k8s.io/csi-driver-name: sfsturbo.csi.everest.io
      csi.storage.k8s.io/fstype: nfs
      everest.io/archive-on-delete: "true"
      everest.io/share-access-to: 7ca2dba2-1234-1234-1234-626371a8fb3a
      everest.io/share-expand-type: bandwidth
      everest.io/share-export-location: 192.168.1.1:/sfsturbo/
      everest.io/share-source: sfs-turbo
      everest.io/share-volume-type: standard
      everest.io/volume-as: subpath
      everest.io/volume-id: 0d773f2e-1234-1234-1234-de6a35074696
    provisioner: everest-csi-provisioner
    reclaimpolicy: delete
    volumebindingmode: immediate

    其中:

    • name:storageclass的名称。
    • mountoptions:选填字段;mount挂载参数。
      • everest 1.2.8以下,1.1.13以上版本仅开放对nolock参数配置,mount操作默认使用nolock参数,无需配置。nolock=false时,使用lock参数。
      • everest 1.2.8及以上版本支持更多参数,默认使用如下所示配置,具体请参见。此处不能配置为nolock=true,会导致挂载失败。
        mountoptions:
        - vers=3
        - timeo=600
        - nolock
        - hard
    • everest.io/volume-as:该参数需设置为“subpath”来使用subpath模式。
    • everest.io/share-access-to:选填字段。subpath模式下,填写sfs turbo资源的所在vpc的id。
    • everest.io/share-expand-type:选填字段。若sfs turbo资源存储类型为增强版(标准型增强版、性能型增强版),设置为bandwidth。
    • everest.io/share-export-location:挂载目录配置。由sfs turbo共享路径和子目录组成,共享路径可至sfs turbo服务页面查询,子路径由用户自定义,后续指定该storageclass创建的pvc均位于该子目录下。
    • everest.io/share-volume-type:选填字段。填写sfs turbo的类型。标准型为standard,性能型为performance。对于增强型需配合“everest.io/share-expand-type”字段使用,everest.io/share-expand-type设置为“bandwidth”。
    • everest.io/zone:选填字段。指定sfs turbo资源所在的可用区。
    • everest.io/volume-id:sfs turbo资源的卷id,可至sfs turbo界面查询。
    • everest.io/archive-on-delete:若该参数设置为“true”,在回收策略为“delete”时,删除pvc会将pv的原文档进行归档,归档目录的命名规则“archived-$pv名称.时间戳”。该参数设置为“false”时,会将pv对应的sfs turbo子目录删除。默认设置为“true”,即删除pvc时进行归档。
  1. 执行kubectl create -f sfsturbo-subpath-sc.yaml
  2. 新建一个pvc的yaml文件,sfs-turbo-test.yaml。

    配置示例:

    apiversion: v1
    kind: persistentvolumeclaim
    metadata:
      name: sfs-turbo-test
      namespace: default
    spec:
      accessmodes:
      - readwritemany
      resources:
        requests:
          storage: 50gi
      storageclassname: sfsturbo-subpath-sc
      volumemode: filesystem

    其中:

    • name: pvc的名称。
    • storageclassname:sc的名称。
    • storage:subpath模式下,该参数无实际意义,容量受限于sfs turbo资源的总容量,若sfs turbo资源总容量不足,请及时到sfs turbo界面扩容。
  1. 执行kubectl create -f sfs-turbo-test.yaml

对subpath类型的sfs turbo扩容时,没有实际的扩容意义。该操作不会对sfs turbo资源进行实际的扩容,需要用户自行保证sfs turbo的总容量不被耗尽。

创建deployment挂载已有数据卷

  1. 新建一个deployment的yaml文件,例如deployment-test.yaml。
    配置示例:
    apiversion: apps/v1
    kind: deployment
    metadata:
      name: test-turbo-subpath-example
      namespace: default
      generation: 1
      labels:
        appgroup: ''
    spec: 
      replicas: 1 
      selector: 
        matchlabels: 
          app: test-turbo-subpath-example 
      template: 
        metadata: 
          labels: 
            app: test-turbo-subpath-example 
        spec: 
          containers: 
          - image: nginx:latest 
            name: container-0 
            volumemounts: 
            - mountpath: /tmp
              name: pvc-sfs-turbo-example 
          restartpolicy: always 
          imagepullsecrets:
          - name: default-secret
          volumes: 
          - name: pvc-sfs-turbo-example 
            persistentvolumeclaim: 
              claimname: sfs-turbo-test

    其中:

    • name:创建的工作负载名称。
    • image:工作负载的镜像。
    • mountpath:容器内挂载路径,示例中挂载到“/tmp”路径。
    • claimname:已有的pvc名称。
  1. 创建deployment负载。

    kubectl create -f deployment-test.yaml

statefulset动态创建subpath模式的数据卷

  1. 新建一个statefulset的yaml文件,例如statefulset-test.yaml。

    配置示例:

    apiversion: apps/v1
    kind: statefulset
    metadata:
      name: test-turbo-subpath
      namespace: default
      generation: 1
      labels:
        appgroup: ''
    spec:
      replicas: 2
      selector:
        matchlabels:
          app: test-turbo-subpath
      template:
        metadata:
          labels:
            app: test-turbo-subpath
          annotations:
            metrics.alpha.kubernetes.io/custom-endpoints: '[{"api":"","path":"","port":"","names":""}]'
            pod.alpha.kubernetes.io/initialized: 'true'
        spec:
          containers:
            - name: container-0
              image: 'nginx:latest'
              resources: {}
              volumemounts:
                - name: sfs-turbo-160024548582479676
                  mountpath: /tmp
              terminationmessagepath: /dev/termination-log
              terminationmessagepolicy: file
              imagepullpolicy: ifnotpresent
          restartpolicy: always
          terminationgraceperiodseconds: 30
          dnspolicy: clusterfirst
          securitycontext: {}
          imagepullsecrets:
            - name: default-secret
          affinity: {}
          schedulername: default-scheduler
      volumeclaimtemplates:
        - metadata:
            name: sfs-turbo-160024548582479676
            namespace: default
            annotations: {}
          spec:
            accessmodes:
              - readwriteonce
            resources:
              requests:
                storage: 10gi
            storageclassname: sfsturbo-subpath-sc
      servicename: wwww
      podmanagementpolicy: orderedready
      updatestrategy:
        type: rollingupdate
      revisionhistorylimit: 10

    其中:

    • name:创建的工作负载名称。
    • image:工作负载的镜像。
    • mountpath:容器内挂载路径,示例中挂载到“/tmp”路径。
    • “spec.template.spec.containers.volumemounts.name ”和 “spec.volumeclaimtemplates.metadata.name”有映射关系,必须保持一致。
    • storageclassname: 填写自建的sc名称。
  1. 创建statefulset负载。

    kubectl create -f statefulset-test.yaml

分享:
网站地图