Prerequisites:
- The virtual-kubelet node is deployed in the target Kubernetes cluster. Note that a serverless Kubernetes cluster is embedded with the virtual-kubelet node.
Elastic Container Instance (ECI) allows you to use FlexVolume to mount an existing disk in the Available state or a new disk that is created based on the specified specifications.
The following sample code shows how to mount an existing disk in the Available state.
Save the following sample code in a YAML file named flexvolume_disk1.yaml:
apiVersion: v1
kind: Pod
metadata:
name: test-flexvolume-disk1
spec:
# You can set the nodeName parameter to schedule a pod in a Container Service for Kubernetes cluster to ECI.
# nodeName: virtual-node-eci-0
containers:
- image: nginx:latest
name: test-container
volumeMounts:
- mountPath: /cache-test
name: cache-volume
volumes:
- name: cache-volume
flexVolume:
driver: alicloud/disk
fsType: ext4
options:
volumeId: "d-2zehdahrwoa7srga8eqw"
performanceLevel: "PL2"
Use the kubectl client to create an ECI based on the preceding configuration file.
# kubectl create -f flexvolume_disk1.yaml
pod/test-flexvolume-disk1 created
# kubectl get pod test-flexvolume-disk1
NAME READY STATUS RESTARTS AGE
test-flexvolume-disk1 1/1 Running 0 45s
# kubectl exec -it test-flexvolume-disk1 bash
root@default-test-flexvolume-disk1:/# ls
bin boot cache-test dev etc home lib lib64 media mnt opt proc root run sbin srv sys tmp usr var
root@default-test-flexvolume-disk1:/# ls cache-test/
lost+found
The following code shows how to mount a new disk that is created based on the specified
specifications. Save the following sample code in a YAML file named flexvolume_disk2.yaml:
apiVersion: v1
kind: Pod
metadata:
name: test-flexvolume-disk2
spec:
# You can set the nodeName parameter to schedule a pod in a Container Service for Kubernetes cluster to ECI.
# nodeName: virtual-node-eci-0
containers:
- image: nginx:latest
name: test-container
volumeMounts:
- mountPath: /cache-test
name: cache-volume
volumes:
- name: cache-volume
flexVolume:
driver: alicloud/disk
fsType: ext4
options:
volumeType: "alicloud-disk-essd"
volumeSize: "100Gi"
performanceLevel: "PL2"
Use the kubectl client to create an ECI based on the preceding configuration file.
# kubectl create -f flexvolume_disk2.yaml
pod/test-flexvolume-disk2 created
# kubectl get pod test-flexvolume-disk2
NAME READY STATUS RESTARTS AGE
test-flexvolume-disk2 1/1 Running 0 45s
# kubectl exec -it test-flexvolume-disk2 bash
root@default-test-flexvolume-disk2:/# ls
bin boot cache-test dev etc home lib lib64 media mnt opt proc root run sbin srv sys tmp usr var
root@default-test-flexvolume-disk2:/# ls cache-test/
lost+found