Help Center> Cloud Container Engine> User Guide> Old Console> Storage (CSI)> Deployment Examples> SFS Volumes> Creating a StatefulSet Mounted with an SFS Volume
Updated on 2024-03-04 GMT+08:00

Creating a StatefulSet Mounted with an SFS Volume

Scenario

CCE allows you to use an existing SGS volume to create a StatefulSet (by using a PVC).

Prerequisites

You have created a CCE cluster and installed the CSI plug-in (everest) in the cluster.

Notes and Constraints

The following configuration example applies to clusters of Kubernetes 1.15 or later.

Procedure

  1. Create an SFS volume by referring to PersistentVolumeClaims (PVCs) and record the volume name.
  2. Use kubectl to connect to the cluster. For details, see Connecting to a Cluster Using kubectl.
  3. Create a YAML file for creating the workload. Assume that the file name is sfs-statefulset-example.yaml.

    touch sfs-statefulset-example.yaml

    vi sfs-statefulset-example.yaml

    Configuration example:

    apiVersion: apps/v1
    kind: StatefulSet
    metadata:
      name: sfs-statefulset-example
      namespace: default
    spec:
      replicas: 1
      selector:
        matchLabels:
          app: sfs-statefulset-example
      template:
        metadata:
          labels:
            app: sfs-statefulset-example
        spec:
          volumes: 
          - name: pvc-sfs-example 
            persistentVolumeClaim:
              claimName: pvc-sfs-example     
          containers:
          - name: container-0
            image: 'nginx:latest'
            volumeMounts:
              - name: pvc-sfs-example
                mountPath: /tmp
          restartPolicy: Always
          imagePullSecrets:
          - name: default-secret 
      serviceName: sfs-statefulset-example-headless
      updateStrategy:
        type: RollingUpdate
    Table 1 Key parameters

    Parent Parameter

    Parameter

    Description

    spec

    replicas

    Number of pods.

    metadata

    name

    Name of the new workload.

    spec.template.spec.containers

    image

    Image used by the workload.

    spec.template.spec.containers.volumeMounts

    mountPath

    Mount path of a container.

    spec

    serviceName

    Service corresponding to the workload. For details about how to create a Service, see Creating a StatefulSet.

    spec.template.spec.volumes.persistentVolumeClaim

    claimName

    Name of an existing PVC.

    Example of mounting an SFS volume to a StatefulSet (PVC template-based, dedicated volume):

    Example YAML file:
    apiVersion: apps/v1
    kind: StatefulSet
    metadata:
      name: sfs-statefulset-example
      namespace: default
    spec:
      replicas: 1
      selector:
        matchLabels:
          app: sfs-statefulset-example
      template:
        metadata:
          labels:
            app: sfs-statefulset-example
        spec:
          containers:
            - name: container-0
              image: 'nginx:latest'
              volumeMounts:
                - name: pvc-sfs-auto-example
                  mountPath: /tmp
          restartPolicy: Always
          imagePullSecrets:
            - name: default-secret
      volumeClaimTemplates:
        - metadata:
            name: pvc-sfs-auto-example
            namespace: default
          spec:
            accessModes:
              - ReadWriteMany
            resources:
              requests:
                storage: 10Gi
            storageClassName: csi-nas
      serviceName: sfs-statefulset-example-headless
      updateStrategy:
        type: RollingUpdate

    spec.template.spec.containers.volumeMounts.name and spec.template.spec.volumes.name must be consistent because they have a mapping relationship.

  4. Create a StatefulSet.

    kubectl create -f sfs-statefulset-example.yaml