After an EVS volume is created or imported to CCE, you can mount it to a workload.
EVS disks cannot be attached across AZs. Before mounting a volume, you can run the kubectl get pvc command to query the available PVCs in the AZ where the current cluster is located.
You have created a 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 evs-deployment-example.yaml
vi evs-deployment-example.yaml
apiVersion: apps/v1 kind: Deployment metadata: name: evs-deployment-example namespace: default spec: replicas: 1 selector: matchLabels: app: evs-deployment-example template: metadata: labels: app: evs-deployment-example spec: containers: - image: nginx name: container-0 volumeMounts: - mountPath: /tmp name: pvc-evs-example imagePullSecrets: - name: default-secret restartPolicy: Always volumes: - name: pvc-evs-example persistentVolumeClaim: claimName: pvc-evs-auto-example
Parent Parameter |
Parameter |
Description |
---|---|---|
spec.template.spec.containers.volumeMounts |
name |
Name of the volume mounted to the container. |
spec.template.spec.containers.volumeMounts |
mountPath |
Mount path of the container. In this example, the volume is mounted to the /tmp directory. |
spec.template.spec.volumes |
name |
Name of the volume. |
spec.template.spec.volumes.persistentVolumeClaim |
claimName |
Name of an existing PVC. |
spec.template.spec.containers.volumeMounts.name and spec.template.spec.volumes.name must be consistent because they have a mapping relationship.
kubectl create -f evs-deployment-example.yaml
touch evs-statefulset-example.yaml
vi evs-statefulset-example.yaml
Mounting an EVS volume to a StatefulSet (PVC template-based, non-shared volume):
apiVersion: apps/v1
kind: StatefulSet
metadata:
name: evs-statefulset-example
namespace: default
spec:
replicas: 1
selector:
matchLabels:
app: evs-statefulset-example
template:
metadata:
labels:
app: evs-statefulset-example
spec:
containers:
- name: container-0
image: 'nginx:latest'
volumeMounts:
- name: pvc-evs-auto-example
mountPath: /tmp
restartPolicy: Always
imagePullSecrets:
- name: default-secret
volumeClaimTemplates:
- metadata:
name: pvc-evs-auto-example
namespace: default
labels:
failure-domain.beta.kubernetes.io/region: eu-de
failure-domain.beta.kubernetes.io/zone:
annotations:
everest.io/disk-volume-type: SAS
spec:
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 10Gi
storageClassName: csi-disk
serviceName: evs-statefulset-example-headless
updateStrategy:
type: RollingUpdate
Parent Parameter |
Parameter |
Description |
---|---|---|
metadata |
name |
Name of the created workload. |
spec.template.spec.containers |
image |
Image of the workload. |
spec.template.spec.containers.volumeMount |
mountPath |
Mount path of the container. In this example, the volume is mounted to the /tmp directory. |
spec |
serviceName |
Service corresponding to the workload. For details about how to create a Service, see Creating a StatefulSet. |
spec.template.spec.containers.volumeMounts.name and spec.volumeClaimTemplates.metadata.name must be consistent because they have a mapping relationship.
kubectl create -f evs-statefulset-example.yaml
kubectl get po | grep evs-statefulset-example
Expected outputs:
evs-statefulset-example-0 1/1 Running 0 22h
kubectl exec evs-statefulset-example-0 -- df tmp
Expected outputs:
/dev/sda 10255636 36888 10202364 1% /tmp
kubectl exec evs-statefulset-example-0 -- touch /tmp/test
kubectl exec evs-statefulset-example-0 -- ls -l /tmp
Expected outputs:
-rw-r--r-- 1 root root 0 Jun 1 02:50 test
kubectl delete po evs-statefulset-example-0
kubectl get po
Expected outputs:
evs-statefulset-example-0 1/1 Running 0 2m
kubectl exec evs-statefulset-example-0 -- ls -l /tmp
Expected outputs:
-rw-r--r-- 1 root root 0 Jun 1 02:50 test