云容器引擎 CCE-通过StorageClass动态创建SFS Turbo子目录:StatefulSet动态创建subpath模式的数据卷

时间:2024-04-23 19:45:33

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

support.huaweicloud.com/usermanual-cce/cce_bestpractice_00253.html