5.16. プロダクトのエクスポート

3scale プロダクト定義を .yaml 形式でエクスポートすると、そのプロダクトをソース 3scale インスタンスとの接続がない 3scale インスタンスにインポートすることができます。3scale プロダクトを設定してから、そのプロダクトをエクスポートする必要があります。Creating new products to test API calls を参照してください。

2 つの 3scale インスタンスにネットワーク接続がある場合、両方の 3scale インスタンスで同じ 3scale 製品を使用するには、toolbox 3scale copy コマンド を使用します。

説明

3scale プロダクトをエクスポートすると、toolbox は Product および Backend カスタムリソース定義 (CRD) に準拠する .yaml 形式でプロダクト定義をシリアライズします。.yaml 出力には、プロダクトの基本情報の他に、以下が含まれます。

  • プロダクトにリンクされたバックエンド。
  • リンクされたバックエンドのメトリクス、メソッド、およびマッピングルール。
  • アプリケーションプランで定義される制限および課金ルール。
  • 制限および課金ルールで参照されるメトリクスおよびメソッド。

プロダクトのエクスポートは、読み取り専用の操作です。つまり、プロダクトを繰り返しエクスポートしても安全性に問題はありません。toolbox は、エクスポートされるプロダクトを変更しません。必要であれば、別の 3scale インスタンスにインポートする前に .yaml 出力を変更することができます。

3scale プロダクトのエクスポートは、以下の状況を対象としています。

  • 移行元および宛先 3scale インスタンス間の接続がない。たとえば、ネットワークに重大な制限があり、複数の 3scale インスタンスで同じプロダクトを使用するときに toolbox の 3scale copy コマンドを実行できない場合などです。
  • Git またはその他のソースコントロールシステムを使用して、.yaml 形式で 3scale プロダクト定義を維持する。

3scale toolbox の export および import コマンドは、プロダクト定義のバックアップおよび復元にも役立つことがあります。

形式

export コマンドを実行するには、以下の形式を使用します。

3scale product export [-f output-file] <remote> <product>

export コマンドは、出力を stdout またはファイルに送信できます。デフォルトは stdout です。出力をファイルに送信するには、.yaml ファイルの名前を指定して -f または --file オプションを指定します。

<remote> を、プロダクトのエクスポート元の 3scale インスタンスに関連付けられた 3scale プロバイダーアカウントエイリアスまたは URL に置き換えます。これを指定する方法の詳細については、リモートアクセスクレデンシャルの管理 を参照してください。

<product> を、エクスポートするプロダクトのシステム名または 3scale ID に置き換えます。このプロダクトは、指定した 3scale プロバイダーアカウントに関連付けられている必要があります。プロダクトの 概要 ページの 3scale GUI では、プロダクトのシステム名を確認できます。プロダクトの 3scale ID を取得するには、toolbox 3scale services show コマンド を実行します。

以下のコマンドは、my-3scale-1 プロバイダーアカウントに関連付けられた 3scale インスタンスから petstore プロダクトをエクスポートし、それを petstore-product.yaml ファイルに出力します。

3scale product export -f petstore-product.yaml my-3scale-1 petstore

以下は、Default API プロダクトのシリアライズの例です。

apiVersion: v1
kind: List
items:
- apiVersion: capabilities.3scale.net/v1beta1
  kind: Product
  metadata:
    annotations:
      3scale_toolbox_created_at: '2021-02-17T10:59:23Z'
      3scale_toolbox_version: 0.17.1
    name: api.xysnalcj
  spec:
    name: Default API
    systemName: api
    description: ''
    mappingRules:
    - httpMethod: GET
      pattern: "/v2"
      metricMethodRef: hits
      increment: 1
      last: false
    metrics:
      hits:
        friendlyName: Hits
        unit: hit
        description: Number of API hits
    methods:
      servicemethod01:
        friendlyName: servicemethod01
        description: ''
    policies:
    - name: apicast
      version: builtin
      configuration: {}
      enabled: true
    applicationPlans:
      basic:
        name: Basic
        appsRequireApproval: false
        trialPeriod: 0
        setupFee: 0.0
        custom: false
        state: published
        costMonth: 0.0
        pricingRules:
        - from: 1
          to: 1000
          pricePerUnit: 1.0
          metricMethodRef:
            systemName: hits
        limits:
        - period: hour
          value: 1222222
          metricMethodRef:
            systemName: hits
            backend: backend_01
    backendUsages:
      backend_01:
        path: "/v1/pets"
      backend_02:
        path: "/v1/cats"
    deployment:
      apicastSelfManaged:
        authentication:
          oidc:
            issuerType: rest
            issuerEndpoint: https://hello:test@example.com/auth/realms/3scale-api-consumers
            jwtClaimWithClientID: azp
            jwtClaimWithClientIDType: plain
            authenticationFlow:
              standardFlowEnabled: false
              implicitFlowEnabled: true
              serviceAccountsEnabled: false
              directAccessGrantsEnabled: true
            credentials: query
            security:
              hostHeader: ''
              secretToken: some_secret
            gatewayResponse:
              errorStatusAuthFailed: 403
              errorHeadersAuthFailed: text/plain; charset=us-ascii
              errorAuthFailed: Authentication failed
              errorStatusAuthMissing: 403
              errorHeadersAuthMissing: text/plain; charset=us-ascii
              errorAuthMissing: Authentication parameters missing
              errorStatusNoMatch: 404
              errorHeadersNoMatch: text/plain; charset=us-ascii
              errorNoMatch: No Mapping Rule matched
              errorStatusLimitsExceeded: 429
              errorHeadersLimitsExceeded: text/plain; charset=us-ascii
              errorLimitsExceeded: Usage limit exceeded
        stagingPublicBaseURL: http://staging.example.com:80
        productionPublicBaseURL: http://example.com:80
- apiVersion: capabilities.3scale.net/v1beta1
  kind: Backend
  metadata:
    annotations:
      3scale_toolbox_created_at: '2021-02-17T10:59:34Z'
      3scale_toolbox_version: 0.17.1
    name: backend.01.pcjwxbdu
  spec:
    name: Backend 01
    systemName: backend_01
    privateBaseURL: https://b1.example.com:443
    description: new desc
    mappingRules:
    - httpMethod: GET
      pattern: "/v1/pets"
      metricMethodRef: hits
      increment: 1
      last: false
    metrics:
      hits:
        friendlyName: Hits
        unit: hit
        description: Number of API hits
    methods:
      mybackendmethod01:
        friendlyName: mybackendmethod01
        description: ''
- apiVersion: capabilities.3scale.net/v1beta1
  kind: Backend
  metadata:
    annotations:
      3scale_toolbox_created_at: '2021-02-17T10:59:34Z'
      3scale_toolbox_version: 0.17.1
    name: backend.02.tiedgjsk
  spec:
    name: Backend 02
    systemName: backend_02
    privateBaseURL: https://b2.example.com:443
    description: ''
    mappingRules:
    - httpMethod: GET
      pattern: "/v1/cats"
      metricMethodRef: hits
      increment: 1
      last: false
    metrics:
      hits:
        friendlyName: Hits
        unit: hit
        description: Number of API hits
    methods:
      backend02_method01:
        friendlyName: backend02_method01
        description: ''

Product CR へのエクスポートおよびパイプ

export コマンドを実行すると、出力をパイプして プロダクトカスタムリソース (CR) を作成できます。この CR が含まれる 3scale インスタンスは以下により異なります。

  • threescale-provider-account シークレットが定義されている場合、3scale operator はそのシークレットによって識別される 3scale インスタンスにプロダクト CR を作成します。
  • threescale-provider-account シークレットが定義されていない場合は、新規プロダクト CR が置かれている namespace に 3scale インスタンスがインストールされていると、3scale operator はその namespace にプロダクト CR を作成します。
  • threescale-provider-account シークレットが定義されておらず、新規プロダクト CR が置かれている namespace に 3scale インスタンスが含まれていない場合は、3scale operator はプロダクト CR を failed 状態とマークします。

threescale-provider-account シークレットが含まれる namespace で以下のコマンドを実行するとします。toolbox は、threescale-provider-account シークレットで識別された 3scale インスタンスに petstore CR をパイプ処理します。

3scale product export my-3scale-1 petstore | oc apply -f -

詳細は、3scale Operator が、カスタムリソースのリンク先となるテナントを識別する方法 を参照してください。