All Products
Search
Document Center

Elastic Container Instance:Deploy a DataCache CRD

Last Updated:Feb 06, 2024

Elastic Container Instance provides the data caching feature for Kubernetes users based on DataCache custom resource definitions (CRDs). Kubernetes users can use the data caching feature to pull large-scale data in advance. This topic describes how to deploy a DataCache CRD in a Kubernetes cluster.

Billing

  • If you deploy a DataCache CRD in a Container Service for Kubernetes (ACK) cluster, the DataCache CRD is deployed on an existing Elastic Compute Service (ECS) node in the cluster by default. You are not charged for the CRD.

  • If you deploy a DataCache CRD in an ACK Serverless cluster, a pod that provides 0.25 vCPU and 0.5 GiB of memory is generated after the DataCache CRD is deployed. You are charged based on the pod. The price is calculated based on the following formula: Price = (0.25 × Unit price of vCPUs + 0.5 × Unit price of memory) × Running duration of the pod. For more information about the billing of pods and the unit prices of vCPUs and memory, see Billing of elastic container instances.

Prerequisites

  • An AccessKey ID and an AccessKey secret are obtained. For more information about how to obtain an AccessKey pair, see Create an AccessKey pair.

    Important

    Make sure that the Alibaba Cloud account or Resource Access Management (RAM) user to which the AccessKey pair belongs has the permissions to call API operations related to DataCaches.

  • The ID of the region in which the cluster resides is obtained.

(Recommended) Deploy a DataCache CRD by using Helm

  1. Connect to the Kubernetes cluster.

  2. Obtain the version of Helm.

    helm version
  3. Deploy a DataCache CRD by using one of the following methods based on the version of Helm:

    Helm 3.7.0 or later

    1. If the version of Helm is 3.7.x, you must enable experimental features.

      If the version of Helm is 3.8.0 or later, skip this step.

      export HELM_EXPERIMENTAL_OCI=1
    2. Configure environment variables.

      Note

      Set the REPO parameter to oci://eci-release-registry.cn-hangzhou.cr.aliyuncs.com/datacache/datacache-operator. You do not need to change the region ID.

      export REPO="oci://eci-release-registry.cn-hangzhou.cr.aliyuncs.com/datacache/datacache-operator"
      export AK='<AccessKey ID>'
      export SK='<AccessKey Secret>'
      export REGION='<Region ID>'
    3. Deploy the DataCache CRD.

      helm install datacache-operator $REPO --set accessKey=$AK --set secretKey=$SK --set regionId=$REGION

    Helm version earlier than 3.7.0

    1. Install a Container Registry plug-in.

      helm plugin install https://github.com/AliyunContainerService/helm-acr

      If you can access GitHub, run the preceding command to install the Container Registry plug-in. If the network condition is unstable, refer to the following commands to install the Container Registry plug-in.

      git clone https://github.com/AliyunContainerService/helm-acr.git
      sed -i 's/github.com/helm-acr-releases.oss-cn-hangzhou.aliyuncs.com/g' helm-acr/scripts/install_plugin.sh
      helm plugin install helm-acr
    2. Add the Helm repository to the on-premises Helm client.

      helm repo add datacache acr://eci-release-chart.cn-hangzhou.cr.aliyuncs.com/datacache/datacache-operator
      helm repo update
    3. Configure environment variables.

      export REPO="datacache/datacache-operator"
      export AK='<AccessKey ID>'
      export SK='<AccessKey Secret>'
      export REGION='<Region ID>'
    4. Deploy the DataCache CRD.

      helm install datacache-operator $REPO --set accessKey=$AK --set secretKey=$SK --set regionId=$REGION

Deploy a DataCache CRD by using a YAML file

  1. Connect to the Kubernetes cluster.

  2. Prepare a YAML configuration file named aliyun-datacache-controller.yaml for the DataCache CRD.

    The following template provides the content of the YAML configuration file. Enter actual values for AccessKey ID (line 13), AccessKey secret (line 14), and region ID (line 211) in the template.

    Unfold

    apiVersion: v1 
    kind: Namespace 
    metadata: 
      name: datacache-controller
    ---
    apiVersion: v1
    kind: Secret
    metadata:
      name: accesskey.eci.aliyun.com
      namespace: datacache-controller
    type: Opaque
    stringData:
      accessKey: ***            # Enter the AccessKey ID.
      secretKey: ***            # Enter the AccessKey secret.
    ---
    apiVersion: apiextensions.k8s.io/v1
    kind: CustomResourceDefinition
    metadata:
      name: datacaches.eci.aliyun.com
    spec:
      group: eci.aliyun.com
      scope: Cluster
      names:
        kind: DataCache
        plural: datacaches
        singular: datacache
        shortNames:
          - edc
        categories:
          - all
      versions:
        - name: v1alpha1
          served: true
          storage: true
          subresources:
            status: {}
          schema:
            openAPIV3Schema:
              type: object
              required:
                - spec
              properties:
                spec:
                  type: object
                  required:
                    - path
                    - dataSource
                  properties:
                    bucket:
                      type: string
                      default: default
                      description: the name of a bucket. The default name is default. The bucket named eci-system is reserved to store common caches of Elastic Container Instance and cannot be used as a value.
                    path:
                      type: string
                      description: the directory of the bucket.
                    dataSource:
                      type: object
                      description: the cache data source.
                      properties:
                        type:
                          type: string
                          description: the property of the cache data source. Valid values: NAS, OSS, URL, and SNAPSHOT.
                        options:
                          type: object
                          description: the options for a specific type of cache data source. For more information, see the DataCache documentation.
                          x-kubernetes-preserve-unknown-fields: true
                    size:
                      type: integer
                      default: 20
                      description: the size of the data cache. You must plan the size. Default value: 20 GiB, which is the minimum size of an elastic block storage (EBS).
                    retentionDays:
                      type: integer
                      description: the retention period of the data cache. By default, data caches never expire.
                    netConfig:
                      type: object
                      properties:
                        securityGroupId:
                          type: string
                          description: the ID of the security group.
                        vSwitchId:
                          type: string
                          description: the ID of the vSwitch.
                        eipInstanceId:
                          type: string
                          description: the ID of the elastic IP address (EIP). If no source network address translation (SNAT) entry is created for the vSwitch, you can bind an EIP to pull Internet data.
                        eipCreateParam:
                          type: object
                          description: the parameter that is used to create an EIP. You can specify EipInstanceId or EipCreateParam.
                          properties:
                            bandwidth:
                              type: integer
                              description: the public bandwidth. Unit: MB. Default value: 5.
                            commonBandwidthPackage:
                              type: string
                              description: the EIP bandwidth plan.
                            internetChargeType:
                              type: string
                              description: the billing method of the EIP.
                            publicIpAddressPoolId:
                              type: string
                              description: the IP address pool.
                            ISP:
                              type: string
                              description: the EIP line type.
                status:
                  type: object
                  properties:
                    status: 
                      type: string
                    progress:
                      type: string
                    snapshotId:
                      type: string
                    dataCacheId:
                      type: string
          additionalPrinterColumns:
            - name: Age
              type: date
              jsonPath: .metadata.creationTimestamp
            - name: dataCacheId
              type: string
              jsonPath: .status.dataCacheId
            - name: Status
              type: string
              jsonPath: .status.status
            - name: Progress
              type: string
              jsonPath: .status.progress
            - name: Bucket
              type: string
              jsonPath: .spec.bucket
            - name: Path
              type: string
              jsonPath: .spec.path
    --- 
    apiVersion: v1
    kind: ServiceAccount
    metadata:
      name: aliyun-datacache-controller
      namespace: datacache-controller
    --- 
    apiVersion: rbac.authorization.k8s.io/v1
    kind: ClusterRole
    metadata:
      name: aliyun-datacache-controller
      namespace: datacache-controller
    rules:
      - apiGroups:
          - "eci.aliyun.com"
        resources:
          - datacaches
          - datacaches/status
        verbs:
          - "*"
      - apiGroups:
          - ""
        resources:
          - events
        verbs:
          - create
          - patch
          - update
      - apiGroups:
          - ""
        resources:
          - configmaps
        verbs:
          - get
    --- 
    apiVersion: rbac.authorization.k8s.io/v1
    kind: ClusterRoleBinding
    metadata:
      name: aliyun-datacache-controller
    roleRef:
      apiGroup: rbac.authorization.k8s.io
      kind: ClusterRole
      name: aliyun-datacache-controller
    subjects:
      - kind: ServiceAccount
        name: aliyun-datacache-controller
        namespace: datacache-controller
    --- 
    apiVersion: apps/v1
    kind: Deployment
    metadata:
      name: aliyun-datacache-controller
      namespace: datacache-controller
    spec:
      selector:
        matchLabels:
          app: aliyun-datacache-controller
      replicas: 1
      template:
        metadata:
          labels:
            app: aliyun-datacache-controller
        spec:
          serviceAccountName: aliyun-datacache-controller
          containers:
          - name: datacache-operator
            image: eci-release-registry.cn-hangzhou.cr.aliyuncs.com/datacache/datacache-operator:latest
            resources:
              limits: 
                memory: "512Mi"
                cpu: "250m"
              requests:
                memory: "64Mi"
                cpu: "50m"
            env: 
            - name: REGION_ID
              value: *** # Specify the actual region ID.
            - name: ACCESS_KEY
              valueFrom:
                secretKeyRef:
                  name: accesskey.eci.aliyun.com
                  key: accessKey
            - name: SECRET_KEY
              valueFrom: 
                secretKeyRef:
                  name: accesskey.eci.aliyun.com
                  key: secretKey
  3. Deploy the DataCache CRD.

    kubectl apply -f aliyun-datacache-controller.yaml