Accelerate online application data access

更新时间:
复制 MD 格式

In serverless scenarios, Fluid uses JindoRuntime to optimize access to Object Storage Service (OSS). Fluid supports both cache mode and no cache mode. This topic describes how to use no cache mode to accelerate data access for online applications.

Prerequisites

  • You have created an ACK Pro cluster of v1.18 or later that runs on an operating system other than ContainerOS. For more information, see Create an ACK Pro cluster.

    Important

    The ack-fluid component does not support ContainerOS.

  • You have installed the cloud-native AI suite and the ack-fluid component.

    Important

    If you have open-source Fluid installed, uninstall it before you deploy the ack-fluid component.

    • If you have not installed the cloud-native AI suite: deploy the Fluid component. For more information, see Install the cloud-native AI suite.

    • If you have installed the cloud-native AI suite: in the ACK console, go to the Cloud-native AI Suite page and deploy ack-fluid.

  • You have deployed a virtual node. For more information, see Create an ECI pod by deploying the ACK Virtual Node component.

  • You have connected to your Kubernetes cluster using kubectl. For more information, see Connect to a Kubernetes cluster by using kubectl.

  • You have activated Object Storage Service (OSS) and created a bucket. For more information, see Activate OSS and Create a bucket.

Limitations

This feature is incompatible with the elastic scheduling feature of ACK. For more information about the elastic scheduling feature, see Custom scheduling of elastic resources based on priorities.

Step 1: Upload test data to OSS

  1. Create a 2 GB test file. This topic uses test as an example.

  2. Upload the test file to your OSS bucket.

    You can use ossutil, a client tool provided by OSS, to upload data. For more information, see Install ossutil.

Step 2: Create a dataset and a JindoRuntime

After configuring the Kubernetes and OSS environments, you can deploy the dataset and JindoRuntime in minutes.

  1. Use the following content to create the secret.yaml file.

    Before you create a dataset, you can create the following YAML file to save the OSS fs.oss.accessKeyId and fs.oss.accessKeySecret.

    apiVersion: v1
    kind: Secret
    metadata:
      name: access-key
    stringData:
      fs.oss.accessKeyId: ****
      fs.oss.accessKeySecret: ****
  2. Run the following command to deploy the Secret.

    kubectl create -f secret.yaml
  3. Use the following content to create a resource.yaml file.

    The YAML file contains two resource definitions:

    • Dataset: Defines information about a remote storage dataset and UFS.

    • JindoRuntime: Starts a JindoFS cluster and provides a caching service.

    apiVersion: data.fluid.io/v1alpha1
    kind: Dataset
    metadata:
      name: serverless-data
    spec:
      mounts:
      - mountPoint: oss://large-model-sh/
        name: demo
        path: /
        options:
          fs.oss.endpoint: oss-cn-shanghai.aliyuncs.com
        encryptOptions:
          - name: fs.oss.accessKeyId
            valueFrom:
              secretKeyRef:
                name: access-key
                key: fs.oss.accessKeyId
          - name: fs.oss.accessKeySecret
            valueFrom:
              secretKeyRef:
                name: access-key
                key: fs.oss.accessKeySecret
      accessModes:
        - ReadWriteMany
    ---
    apiVersion: data.fluid.io/v1alpha1
    kind: JindoRuntime
    metadata:
      name: serverless-data
    spec:
      master:
        disabled: true
      worker:
        disabled: true

    The following table describes some of the parameters.

    Parameter

    Description

    mountPoint

    Specifies the path to mount the UFS. The path format is oss://<oss_bucket>/<bucket_dir>.

    The path does not need to include Endpoint information. If you directly access the Bucket, you can omit <bucket_dir>.

    fs.oss.endpoint

    The endpoint of the OSS bucket. You can specify a public or private endpoint.

    Configuring a private endpoint can improve data access performance, but this requires that your K8s cluster and OSS are in the same region. For example, if your bucket is in the China (Hangzhou) region, the public endpoint is oss-cn-hangzhou.aliyuncs.com, and the private endpoint is oss-cn-hangzhou-internal.aliyuncs.com.

    fs.oss.accessKeyId

    The AccessKey ID with permission to access the OSS bucket.

    fs.oss.accessKeySecret

    The AccessKey secret that corresponds to the AccessKey ID.

    accessModes

    The supported access modes include ReadWriteOnce, ReadOnlyMany, ReadWriteMany, and ReadWriteOncePod. The default value is ReadOnlyMany.

    disabled

    The Master and Worker are both set to true, which enables no cache mode.

  4. Run the following command to deploy the JindoRuntime and dataset.

    kubectl create -f resource.yaml
  5. Run the following command to check the status of the dataset.

    kubectl get dataset serverless-data

    Expected output:

    NAME              UFS TOTAL SIZE   CACHED   CACHE CAPACITY   CACHED PERCENTAGE   PHASE   AGE
    serverless-data                                                                  Bound   1d

    A PHASE of Bound indicates that the dataset is successfully deployed.

  6. Run the following command to check the status of the JindoRuntime.

    kubectl get jindoruntime serverless-data

    Expected output:

    NAME              MASTER PHASE   WORKER PHASE   FUSE PHASE   AGE
    serverless-data                                 Ready        3m41s

    The expected output shows that FUSE is Ready, which indicates that the JindoRuntime is deployed successfully.

Step 3: Create a serverless application

You can create an application container or submit a machine learning job to use the JindoFS acceleration service. This topic uses a Deployment to create a serverless application that accesses data in OSS.

  1. Create a serving.yaml file with the following content.

    apiVersion: apps/v1
    kind: Deployment
    metadata:
      name: model-serving
    spec:
      selector:
        matchLabels:
          app: model-serving
      template:
        metadata:
          labels:
            app: model-serving
            alibabacloud.com/fluid-sidecar-target: eci
            alibabacloud.com/eci: "true"
          annotations:
             k8s.aliyun.com/eci-use-specs: ecs.g7.4xlarge
        spec:
          containers:
            - image: fluidcloudnative/serving
              name: serving
              ports:
                - name: http1
                  containerPort: 8080
              env:
                - name: TARGET
                  value: "World"
              volumeMounts:
                - mountPath: /data
                  name: data
          volumes:
            - name: data
              persistentVolumeClaim:
                claimName: serverless-data
  2. Run the following command to create the application container.

    kubectl create -f serving.yaml
  3. Check the test file size.

    1. Run the following command to open a shell in the application container.

      kubectl exec -it model-serving-85b645b5d5-2trnf -c serving -- bash
    2. In the pod, run the following command to check the test file size.

      bash-4.4# du -sh /data/test

      Expected output:

      2.0G    /data/test   
  4. Run the following command to view the startup logs.

    kubectl  logs model-serving-85b9587c5b-w5528  -c serving

    Expected output:

    Begin loading models at 18:23:59
    
    real    0m27.107s
    user    0m0.000s
    sys    0m0.742s
    Finish loading models at 18:24:26

    As shown in the expected output, the real file copy time is 0m27.107s. This copy time depends on network latency and bandwidth. If you want to accelerate data access, see Use cache mode to accelerate online application data access.

Step 4: Clean up the environment

When you no longer need the data access feature, you can clean up the resources.

  1. Run the following command to delete the application Deployment.

    kubectl delete deployment model-serving
  2. Run the following command to delete the dataset.

    kubectl delete dataset serverless-data

Related documents