# (kubectl) Creating a StatefulSet Mounted with an OBS Volume

#### Scenario

CCE allows you to use an existing OBS volume to create a StatefulSet through a PersistentVolumeClaim (PVC).

#### Prerequisites

- You have created a CCE cluster and installed the FlexVolume plug-in (storage-driver) in the cluster.
- The AK/SK has been uploaded. For details, see Preparations.

#### Notes and Constraints

The following configuration example applies to clusters of Kubernetes 1.13 or earlier.

#### Procedure

1. Create an OBS volume by referring to Creating an OBS Volume and obtain the PVC 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 obs-statefulset-example.yaml.

   touch obs-statefulset-example.yaml

   vi obs-statefulset-example.yaml

   Example YAML:

       apiVersion: apps/v1
       kind: StatefulSet
       metadata:
         name: obs-statefulset-example
         namespace: default
       spec:
         replicas: 1
         selector:
           matchLabels:
             app: obs-statefulset-example
         serviceName: qwqq
         template:
           metadata:
             annotations:
               metrics.alpha.kubernetes.io/custom-endpoints: '[{"api":"","path":"","port":"","names":""}]'
               pod.alpha.kubernetes.io/initialized: "true"
             creationTimestamp: null
             labels:
               app: obs-statefulset-example
           spec:
             affinity: {}
             containers:
               image: nginx:latest
               imagePullPolicy: Always
               name: container-0
               volumeMounts:
               - mountPath: /tmp
                 name: pvc-obs-example
             imagePullSecrets:
             - name: default-secret
             volumes:
               - name: pvc-obs-example
                 persistentVolumeClaim:
                   claimName: cce-obs-demo

   Table 1 Key parameters
   Parameter | Description
   --- | ---
   replicas | Number of pods.
   name | Name of the created workload.
   image | Image used by the workload.
   mountPath | Mount path in the container.
   serviceName | Service corresponding to the workload. For details about how to create a Service, see Creating a StatefulSet.
   claimName | Name of an existing PVC.

4. Create the StatefulSet.

   kubectl create -f obs-statefulset-example.yaml

Parent topic: Using OBS Buckets as Storage Volumes