すべてのプロダクト
Search
ドキュメントセンター

Elastic Container Instance:DataCache CRD のデプロイ

最終更新日:Dec 28, 2024

Elastic Container Instance は、DataCache カスタムリソース定義 (CRD) に基づいて、Kubernetes ユーザー向けのデータキャッシング機能を提供します。 Kubernetes ユーザーは、データキャッシング機能を使用して、大規模データを事前にプルできます。 このトピックでは、Kubernetes クラスターに DataCache CRD をデプロイする方法について説明します。

課金

  • コンテナサービス Kubernetes 版 (ACK) クラスターに DataCache CRD をデプロイする場合、DataCache CRD はデフォルトでクラスター内の既存の Elastic Compute Service (ECS) ノードにデプロイされます。 CRD に対する課金は発生しません。

  • ACK Serverless クラスターに DataCache CRD をデプロイすると、DataCache CRD のデプロイ後に 0.25 vCPU と 0.5 GiB のメモリを提供するポッドが生成されます。 ポッドに基づいて課金されます。 価格は次の式に基づいて計算されます。価格 = (0.25 × vCPU の単価 + 0.5 × メモリの単価) × ポッドの実行時間。 ポッドの課金と vCPU およびメモリの単価の詳細については、エラスティックコンテナインスタンスの課金 を参照してください。

前提条件

  • AccessKey ID と AccessKey シークレットを取得します。 AccessKey ペアの取得方法の詳細については、AccessKey ペアの作成 を参照してください。

    重要

    AccessKey ペアが属する Alibaba Cloud アカウントまたは Resource Access Management (RAM) ユーザーに、DataCache に関連する API オペレーションを呼び出す権限があることを確認してください。

  • クラスターが存在するリージョンの ID を取得します。

(推奨) Helm を使用して DataCache CRD をデプロイする

  1. Kubernetes クラスターに接続します。

  2. Helm のバージョンを取得します。

    helm version
  3. Helm のバージョンに基づいて、次のいずれかの方法を使用して DataCache CRD をデプロイします。

    Helm 3.7.0 以降

    1. Helm のバージョンが 3.7.x の場合は、実験的機能を有効にする必要があります。

      Helm のバージョンが 3.8.0 以降の場合は、この手順をスキップします。

      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='<Region ID>'
    3. DataCache CRD をデプロイします。

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

    Helm 3.7.0 より前のバージョン

    1. Container Registry プラグインをインストールします。

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

      GitHub にアクセスできる場合は、上記のコマンドを実行して Container Registry プラグインをインストールします。 ネットワークの状態が不安定な場合は、次のコマンドを参照して Container Registry プラグインをインストールします。

      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='<Region ID>'
    4. DataCache CRD をデプロイします。

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

YAML ファイルを使用して DataCache CRD をデプロイする

  1. Kubernetes クラスターに接続します。

  2. DataCache CRD 用の aliyun-datacache-controller.yaml という名前の YAML 設定ファイルを準備します。

    次のテンプレートは、YAML 設定ファイルの内容を提供します。 テンプレートの AccessKey ID (13 行目)、AccessKey シークレット (14 行目)、およびリージョン ID (211 行目) に実際の値を入力します。

    展開

    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 シークレットを入力します。
    ---
    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: バケットの名前。 デフォルト名は default です。 eci-system という名前のバケットは、Elastic Container Instance の共通キャッシュを格納するために予約されており、値として使用することはできません。
                    path:
                      type: string
                      description: バケットのディレクトリ。
                    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。これは、エラスティックブロックストレージ (EBS) の最小サイズです。
                    retentionDays:
                      type: integer
                      description: データキャッシュの保持期間。 デフォルトでは、データキャッシュの有効期限は切れません。
                    netConfig:
                      type: object
                      properties:
                        securityGroupId:
                          type: string
                          description: セキュリティグループの ID。
                        vSwitchId:
                          type: string
                          description: vSwitch の ID。
                        eipInstanceId:
                          type: string
                          description: エラスティック IP アドレス (EIP) の ID。 vSwitch にソースネットワークアドレス変換 (SNAT) エントリが作成されていない場合は、EIP をバインドしてインターネットデータをプルできます。
                        eipCreateParam:
                          type: object
                          description: EIP を作成するために使用されるパラメーター。 EipInstanceId または EipCreateParam を指定できます。
                          properties:
                            bandwidth:
                              type: integer
                              description: パブリック帯域幅。 単位: MB。 デフォルト値: 5。
                            commonBandwidthPackage:
                              type: string
                              description: EIP 帯域幅プラン。
                            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: *** # 実際のリージョン 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. DataCache CRD をデプロイします。

    kubectl apply -f aliyun-datacache-controller.yaml