文档

部署DataCache CRD

更新时间:

阿里云以DataCache CRD的方式将ECI的数据缓存功能提供给Kubernetes用户,以便Kubernetes用户可以使用该功能来提前拉取大规模数据。本文介绍如何在Kubernetes集群中部署DataCache CRD。

计费说明

  • 如果是ACK集群,部署DataCache CRD会默认部署在已有ECS节点上,无需额外付费。

  • 如果是ACK Serverless集群,部署DataCache CRD后会生成一个0.25 vCPU 、0.5 GiB的ECI Pod,收取ECI实例费用。费用=(0.25*vCPU单价+0.5*内存单价)*运行时长。关于ECI实例如何计费,以及vCPU和内存的具体单价,请参见ECI实例计费

准备工作

操作前,请准备好以下信息:

  • AccessKey ID和AccessKey Secret。获取方式请参见创建AccessKey

    重要

    请确保AccessKey所属阿里云账号或者RAM用户具有数据缓存相关API的权限。

  • 集群所属的地域ID。

(推荐)通过Helm部署

  1. 连接Kubernetes集群。

  2. 确认Helm版本。

    helm version
  3. 根据Helm版本选择以下一种方式部署DataCache CRD。

    Helm版本为3.7及以上版本

    1. 如果Helm版本为3.7,需开启实验功能。

      Helm版本为3.8及以上版本可跳过该步骤。

      export HELM_EXPERIMENTAL_OCI=1
    2. 设置环境变量。

      说明

      设置REPO时,请直接使用oci://eci-release-registry.cn-hangzhou.cr.aliyuncs.com/datacache/datacache-operator,无需修改地域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='<地域ID>'
    3. 部署DataCache CRD。

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

    Helm版本低于3.7

    1. 安装阿里云ACR插件。

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

      如果您访问Github比较流畅,可以直接执行上述命令。如果网络不流畅,可以参考以下命令安装。

      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. 添加Helm仓库到本地Helm客户端。

      helm repo add datacache acr://eci-release-chart.cn-hangzhou.cr.aliyuncs.com/datacache/datacache-operator
      helm repo update
    3. 设置环境变量。

      export REPO="datacache/datacache-operator"
      export AK='<AccessKey ID>'
      export SK='<AccessKey Secret>'
      export REGION='<地域ID>'
    4. 部署DataCache CRD。

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

通过YAML部署

  1. 连接Kubernetes集群。

  2. 准备DataCache CRD的YAML配置文件,命名为aliyun-datacache-controller.yaml。

    YAML配置文件内容如下,请根据实际修改代码中的AccessKey ID(第13行)、AccessKey Secret(第14行)和地域ID(第211行)。

    展开查看详细YAML

    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: ***            #请按实际填写AccessKey ID
      secretKey: ***            #请按实际填写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: 对应一个bucket,缺省为default,eci-system为ECI公共缓存保留空间,不可使用
                    path:
                      type: string
                      description: 对应的bucket的目录
                    dataSource:
                      type: object
                      description: 缓存数据源
                      properties:
                        type:
                          type: string
                          description: 支持NAS/OSS/URL/SNAPSHOT等
                        options:
                          type: object
                          description: 具体类型参数,详见DataCache文档
                          x-kubernetes-preserve-unknown-fields: true
                    size:
                      type: integer
                      default: 20
                      description: 缓存大小,需要提前评估好,默认取最小的块存储大小,即20 GiB
                    retentionDays:
                      type: integer
                      description: 保留天数,默认不过期
                    netConfig:
                      type: object
                      properties:
                        securityGroupId:
                          type: string
                          description: 安全组
                        vSwitchId:
                          type: string
                          description: 交换机
                        eipInstanceId:
                          type: string
                          description: 如果交换机没有配置SNAT,可以绑定EIP,拉取公网数据
                        eipCreateParam:
                          type: object
                          description: 与EipInstanceId二选一
                          properties:
                            bandwidth:
                              type: integer
                              description: 公网带宽,单位为MB,缺省值为5
                            commonBandwidthPackage:
                              type: string
                              description: 共享带宽包
                            internetChargeType:
                              type: string
                              description: EIP计费类型
                            publicIpAddressPoolId:
                              type: string
                              description: IP地址池
                            ISP:
                              type: string
                              description: EIP线路类型
                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: ***          #请根据实际填写地域
            - 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. 部署DataCache CRD。

    kubectl apply -f aliyun-datacache-controller.yaml
  • 本页导读 (1)
文档反馈