CCE allows you to use an existing OBS volume to create a StatefulSet through a PVC.
You have created a CCE cluster and installed the CSI plug-in (everest) in the cluster.
The following configuration example applies to clusters of Kubernetes 1.15 or later.
touch obs-statefulset-example.yaml
vi obs-statefulset-example.yaml
Configuration example:
apiVersion: apps/v1 kind: StatefulSet metadata: name: obs-statefulset-example namespace: default spec: replicas: 1 selector: matchLabels: app: obs-statefulset-example template: metadata: labels: app: obs-statefulset-example spec: volumes: - name: pvc-obs-example persistentVolumeClaim: claimName: pvc-obs-example containers: - name: container-0 image: 'nginx:latest' volumeMounts: - name: pvc-obs-example mountPath: /tmp restartPolicy: Always imagePullSecrets: - name: default-secret serviceName: obs-statefulset-example-headless # Name of the headless Service
Parameter |
Description |
---|---|
replicas |
Number of pods. |
name |
Name of the new workload. |
image |
Image used by the workload. |
mountPath |
Mount path of a 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. |
Example of mounting an OBS volume to a StatefulSet (PVC template-based, dedicated volume):
Example YAML:
apiVersion: apps/v1 kind: StatefulSet metadata: name: obs-statefulset-example namespace: default spec: replicas: 1 selector: matchLabels: app: obs-statefulset-example template: metadata: labels: app: obs-statefulset-example spec: containers: - name: container-0 image: 'nginx:latest' volumeMounts: - name: pvc-obs-auto-example mountPath: /tmp restartPolicy: Always imagePullSecrets: - name: default-secret volumeClaimTemplates: - metadata: name: pvc-obs-auto-example namespace: default annotations: everest.io/obs-volume-type: STANDARD spec: accessModes: - ReadWriteMany resources: requests: storage: 1Gi storageClassName: csi-obs serviceName: obs-statefulset-example-headless
kubectl create -f obs-statefulset-example.yaml
kubectl get po | grep obs-statefulset-example
Expected outputs:
obs-statefulset-example-0 1/1 Running 0 2m5s
kubectl exec obs-statefulset-example-0 -- mount|grep /tmp
Expected outputs:
s3fs on /tmp type fuse.s3fs (rw,nosuid,nodev,relatime,user_id=0,group_id=0,allow_other)
kubectl exec obs-statefulset-example-0 -- touch /tmp/test
kubectl exec obs-statefulset-example-0 -- ls -l /tmp
Expected outputs:
-rw-r--r-- 1 root root 0 Jun 1 02:50 test
kubectl delete po obs-statefulset-example-0
kubectl get po
Expected outputs:
obs-statefulset-example-0 1/1 Running 0 2m
kubectl exec obs-statefulset-example-0 -- ls -l /tmp
Expected outputs:
-rw-r--r-- 1 root root 0 Jun 1 02:50 test