Mount a local disk

更新时间:
复制 MD 格式

A local disk is a storage device on the physical machine that hosts an instance. Local disks provide low latency, high random IOPS, and high throughput, making them a cost-effective solution. This topic describes how to specify an ECS instance type that provides local disks to create an ECI pod, and then mount the local disk in the pod.

Configuration

You can add an annotation such as k8s.aliyun.com/eci-use-specs: ecs.i2g.2xlarge to the pod metadata to specify an ECS instance type that provides local disks. To mount a local disk, set the medium of an emptyDir volume to LocalRaid0. ECI automatically combines the local disks into a RAID 0 array and mounts it to the specified path in the pod.

Important
  • Annotations must be added to the metadata in the configuration file of the pod. For example, when you create a Deployment, you must add annotations in the spec.template.metadata section.

  • Elastic Container Instance-related annotations are only applied when a pod is created. Adding or modifying these annotations on an existing pod will have no effect.

ECI supports the following ECS instance families that provide local disks:

  • d1, big data instance family that includes a variety of instance types such as ecs.d1.2xlarge

  • d1ne, big data instance family with enhanced network performance, which includes a variety of instance types such as ecs.d1ne.2xlarge

  • i2, instance family equipped with local SSDs, which includes a variety of instance types such as ecs.i2.xlarge

  • i2g, instance family equipped with local SSDs, which includes a variety of instance types such as ecs.i2g.2xlarge

  • gn5, GPU-accelerated compute-optimized instance family, which includes a variety of instance types such as ecs.gn5-c4g1.xlarge.

    Note

    gn5 is a GPU-accelerated instance family. If you select this instance family, you must specify GPU-related parameters in addition to local disk-related parameters.

For more information about ECS instance types, see the following topics:

Example

  1. Create a file named localdis.yaml.

    vim localdis.yaml

    The following code provides a sample localdis.yaml file that defines a Deployment. The annotation k8s.aliyun.com/eci-use-specs: ecs.i2g.2xlarge requests an instance type that provides a local disk. The emptyDir volume with medium: LocalRaid0 instructs ECI to mount this disk to the /localdisk-test path.

    apiVersion: apps/v1
    kind: Deployment
    metadata:
      name: localdisk-test
      labels:
        app: test
    spec:
      replicas: 1
      selector:
        matchLabels:
          app: nginx
      template:
        metadata:
          name: nginx-test
          labels:
            app: nginx
            alibabacloud.com/eci: "true" 
          annotations:
            k8s.aliyun.com/eci-use-specs: ecs.i2g.2xlarge  # Specify an ECS instance type that supports local disks.
        spec:
          containers:
          - name: nginx
            image: registry.cn-shanghai.aliyuncs.com/eci_open/nginx:1.14.2
            ports:
            - containerPort: 80
            volumeMounts:
              - name: localdisk
                mountPath: /localdisk-test
          volumes:
            - name: localdisk
              emptyDir:
                medium: LocalRaid0
  2. Create the Deployment.

    kubectl create -f localdis.yaml
  3. Verify the result.

    After the pod is created, check the pod details. The output shows that the local disk is configured as a RAID 0 array (/dev/md0) and mounted to the specified /localdisk-test path.

    xxx:~$ kubectl get pod
    NAME                              READY   STATUS    RESTARTS   AGE
    localdisk-test-5f8c979c48-j4bkj   1/1     Running   0          76s
    xxx:~$ kubectl exec -it localdisk-test-5f8c979c48-j4bkj -- bash
    root@localdisk-test-5f8c979c48-j4bkj:/# df -h
    Filesystem      Size  Used Avail Use% Mounted on
    overlay          30G  4.1G   26G  14% /
    tmpfs            64M     0   64M   0% /dev
    tmpfs            16G     0   16G   0% /sys/fs/cgroup
    /dev/md0        879G   77M  835G   1% /localdisk-test
    /dev/vda4        30G  4.1G   26G  14% /etc/hosts
    overlay         8.8G  4.9G  3.5G  59% /etc/hostname
    shm              64M     0   64M   0% /dev/shm
    tmpfs            32G   12K   32G   1% /run/secrets/kubernetes.io/serviceaccount
    tmpfs            16G     0   16G   0% /proc/acpi
    tmpfs            16G     0   16G   0% /sys/firmware