建立並連結帳單帳戶

本文說明如何建立 Google Distributed Cloud (GDC) 實體隔離帳單帳戶,以便追蹤資源用量。

Distributed Cloud 環境需要帳單帳戶,才能追蹤專案和組織的使用費用。組織內的所有帳單帳戶都會使用單一價目表,向客戶收取服務使用費。如果未將帳單帳戶連結至組織或專案,您會失去與資源相關聯的費用資料,導致費用不一致。

本文適用於平台管理員或應用程式操作員群組中的開發人員,他們會在 GDC 中建立及管理帳單帳戶。詳情請參閱「GDC 實體隔離方案的目標對象」說明文件。

事前準備

要求 IAM 角色

請與 IAM 機構組織管理員聯絡,要求在專案中取得下列角色:

  • 全域組織帳單帳戶管理員 (organization-billing-account-admin):建立、管理及繫結 BillingAccount 資源。

  • 全域組織帳單帳戶使用者 (organization-billing-account-user):讀取、列出及繫結 BillingAccount 資源。

  • 全域組織帳單帳戶管理員 (organization-billing-manager):讀取、列出、建立及更新 BillingAccountBinding 資源。

這些角色會繫結至專案命名空間 (用於專案層級計費),或平台命名空間 (用於組織層級計費)。

取得 kubeconfig 檔案

如要對機構全域叢集執行指令,請確認您具備下列資源:

  1. 如果沒有 kubeconfig 檔案,請登入並產生 Org Global 叢集的 kubeconfig 檔案。

  2. 請使用 Org Global 叢集的 kubeconfig 檔案路徑,取代這些操作說明中的 ORG_GLOBAL_CLUSTER_KUBECONFIG。

建立新的帳單帳戶

kubectl

帳單帳戶可透過 name 和 namespace 識別。如要建立帳單帳戶,請使用自訂資源建立 name 和 namespace:

  1. 建立 YAML 檔案,並新增 BillingAccount 自訂資源和下列內容:

    apiVersion: billing.global.gdc.goog/v1
    kind: BillingAccount
    metadata:
      namespace: platform
      name: BIL_ACCOUNT_NAME
    spec:
      displayName: BIL_DISPLAY_NAME
      paymentSystemConfig:
        cloudBillingConfig:
          accountID: "012345-6789AB-CDEF01"
    

    請替換下列變數:

    • BIL_ACCOUNT_NAME:帳單帳戶名稱,例如 test-billing-account。
    • BIL_DISPLAY_NAME:帳單帳戶顯示名稱,例如 "Test Billing Account"。
  2. 確認付款設定類型。Distributed Cloud 帳單帳戶必須採用下列其中一種付款設定:

    • cloudBillingConfig:預設付款設定。這項設定會儲存 Cloud Billing 帳戶 ID。

    • customConfig:合作夥伴用來儲存付款設定,以便向組織收費的自訂設定。customConfig 支援鍵/值字串字典,其中包含必要鍵 payment-config-type。

    以下範例顯示不同付款設定的 BillingAccount YAML 檔案片段:

    cloudBillingConfig 範例:

    spec:
      paymentSystemConfig:
        cloudBillingConfig:
          accountID: CLOUD_BILLING_ACCOUNT_ID
    

    將 CLOUD_BILLING_ACCOUNT_ID 替換為您的Google Cloud 帳單帳戶 ID。

    customConfig 範例:

    spec:
     paymentSystemConfig:
       customConfig:
          "payment-config-type": PAYMENT_CONFIG_TYPE
    

    將 PAYMENT_CONFIG_TYPE 替換為您為自訂帳單設定選擇的付款設定類型。

    如果沒有貴組織的 customConfig 設定資訊,請輸入下列詳細資料:

    spec:
     paymentSystemConfig:
       customConfig:
          "payment-config-type": "N/A"
    

    下列 YAML 檔案顯示完整的 BillingAccount 資源,其中包含 cloudBillingConfig 設定:

    apiVersion: billing.global.gdc.goog/v1
    kind: BillingAccount
    metadata:
      namespace: platform
      name: test-billing-account
    spec:
      displayName: "Test Billing Account"
      paymentSystemConfig:
        cloudBillingConfig:
          accountID: "012345-6789AB-CDEF01"
    
  3. 儲存 YAML 檔案。執行 kubectl CLI,在 Org Global 叢集中套用資源:

    kubectl --kubeconfig ORG_GLOBAL_CLUSTER_KUBECONFIG apply -f billingaccount.yaml
    

    將 ORG_GLOBAL_CLUSTER_KUBECONFIG 替換為組織全域叢集 kubeconfig 檔案。

CLI

如要建立帳單帳戶,請使用 gdcloud billing accounts create 指令。

詳情請參閱「gdcloud billing accounts create」。

您必須先將帳單帳戶連結至組織,才能建立專案。這可確保在組織內建立的所有專案,預設都會繼承有效的帳單帳戶。

如果您希望專案與組織的帳單帳戶不同,也可以明確將專案連結至特定帳單帳戶。

如要將組織連結至 BillingAccount,請按照下列步驟操作:

  1. 將下列內容新增至 YAML 檔案 billingaccountbinding.yaml:

    • 在 billingAccountRef 區段中,使用要連結的 BillingAccount 中 name 欄位的內容填入 name 欄位。
    • 在 metadata 區段中,使用 BillingAccount 資源中相同欄位的值填入 namespace 欄位。在本例中,BillingAccount 資源的機構命名空間為 platform:
    apiVersion: billing.global.gdc.goog/v1
    kind: BillingAccountBinding
    metadata:
      name: billing
      namespace: platform
    spec:
      billingAccountRef:
        name: BIL_ACCOUNT_NAME
        namespace: platform
    
  2. 執行下列 kubectl 指令,套用 billingaccountbinding.yaml 檔案:

    kubectl --kubeconfig ORG_GLOBAL_CLUSTER_KUBECONFIG apply -f billingaccountbinding.yaml
    
  3. 檢查 BillingAccountBinding 的狀態,確認沒有錯誤:

    kubectl --kubeconfig ORG_GLOBAL_CLUSTER_KUBECONFIG describe billingaccountbinding billing -n platform
    

如要將專案連結至BillingAccount,請按照下列步驟操作:

  1. 在檔案中新增下列內容:billingaccountbinding.yaml:

    • 在 billingAccountRef 區段中,使用要連結的 BillingAccount 中 name 欄位的內容填入 name 欄位。
    • 在 metadata 區段中,使用 BillingAccount 資源中相同欄位的內容填入 namespace 欄位。
    apiVersion: billing.global.gdc.goog/v1
    kind: BillingAccountBinding
    metadata:
      name: billing
      namespace: PROJECT_NAME
    spec:
      billingAccountRef:
        name: BIL_ACCOUNT_NAME
        namespace: platform
    

    請替換下列變數:

    • PROJECT_NAME 替換為與帳單帳戶繫結的專案名稱。
    • BIL_ACCOUNT_NAME:帳單帳戶名稱,例如 test-billing-account。
  2. 執行下列 kubectl 指令,套用 billingaccountbinding.yaml 檔案:

    kubectl --kubeconfig ORG_GLOBAL_CLUSTER_KUBECONFIG apply -f billingaccountbinding.yaml
    
  3. 檢查 BillingAccountBinding 的狀態,確認沒有錯誤:

    kubectl --kubeconfig ORG_GLOBAL_CLUSTER_KUBECONFIG describe billingaccountbinding billing -n PROJECT_NAME
    

    將 PROJECT_NAME 替換為繫結至帳單帳戶的專案名稱。

列出帳單帳戶繫結

查看組織中所有命名空間內,所有已部署 BillingAccountBinding 資源及其目前狀態的清單:

  kubectl --kubeconfig ORG_GLOBAL_CLUSTER_KUBECONFIG get billingaccountbinding -A -o 'custom-columns=NAME:metadata.name,NAMESPACE:metadata.namespace,BillingAccountName:spec.billingAccountRef.name,STATUS:status.conditions[0].status'

這個指令會輸出每個 BillingAccountBinding 的 NAME、NAMESPACE、BillingAccountName 和 STATUS。STATUS 欄位會指出繫結是否有效,或是否有任何錯誤。

帳單帳戶階層和行為

將帳單帳戶連結至組織和專案時,適用下列階層和行為:

  • 專案層級關聯優先:如果特定專案 (例如 project-A) 明確連結至 BillingAccount (例如 billing-account-1),則 project-A 的所有費用都會計入 billing-account-1。無論組織層級的帳單帳戶設定為何,這項專案層級的關聯都會保持有效。

  • 未連結專案的組織層級關聯:如果組織連結至BillingAccount (例如 billing-account-0),則該組織中沒有明確BillingAccountBinding的所有專案,都會自動與 billing-account-0 建立關聯並向其收費。這項關聯通常會在約 15 分鐘後生效。

  • 變更組織帳單帳戶:如果連結至組織的帳單帳戶有所變更 (例如從 billing-account-0 變更為 billing-account-new),billing-account-0 專案「不會」自動切換至 billing-account-new。這些專案仍會繫結至 billing-account-0,您必須手動更新帳單帳戶,才能讓專案使用 billing-account-new。

變更連結的帳單帳戶

在 Distributed Cloud 中,您無法刪除帳單帳戶。如要變更帳單設定,請修改 BillingAccountBinding,變更連結至組織或專案的帳單帳戶。這個用途的可能情境包括:

  • 貴公司的會計規則要求您將與開發人員和正式環境層級工作負載相關的費用,拆分到不同的帳戶。
  • 您建立帳單帳戶,向客戶收取一年期的合約費用。合約到期後,您必須收取超過一年的剩餘期間費用。

專案

如要變更專案連結的帳單帳戶,請按照下列步驟操作:

  1. 建立新的 BillingAccount 並連結至專案。這個帳戶會取代舊帳戶。

  2. 在專案命名空間中找出 BillingAccountBinding 資源 YAML 檔案,查看連結的帳單帳戶:

    kubectl --kubeconfig ORG_GLOBAL_CLUSTER_KUBECONFIG describe billingaccountbinding billing -n PROJECT_NAME
    
  3. 修改 BillingAccountBinding,連結至新的帳單帳戶。在 billingAccountRef 部分,使用本節步驟 1 中建立的新 BillingAccount 名稱填入 name 欄位。

    kubectl --kubeconfig ORG_GLOBAL_CLUSTER_KUBECONFIG edit billingaccountbinding billing -n PROJECT_NAME
    
  4. 完成變更後,請確認帳單帳戶已正確更新:

    kubectl --kubeconfig ORG_GLOBAL_CLUSTER_KUBECONFIG describe billingaccountbinding billing -n PROJECT_NAME
    

以下範例顯示 BillingAccountBinding YAML 檔案,其中帳戶 expired-billing-account 連結至專案 project-one:

  apiVersion: billing.global.gdc.goog/v1
  kind: BillingAccountBinding
  metadata:
    # The name of a BillingAccountBinding will typically always be `billing`.
    name: billing
    # This is the project.
    namespace: project-one
  spec:
    billingAccountRef:
      # This is an example of a BillingAccount that has expired.
      name: expired-billing-account
      namespace: platform

以下範例顯示修改後的 BillingAccountBinding YAML 檔案,用於連結名為 new-billing-account 的新帳戶:

  apiVersion: billing.global.gdc.goog/v1
  kind: BillingAccountBinding
  metadata:
    name: billing
    # This is the project.
    namespace: project-one
  spec:
    billingAccountRef:
      # This is the example of the new BillingAccount.
      name: new-billing-account
      namespace: platform

機構

如要變更組織連結的帳單帳戶,請按照下列步驟操作:

  1. 建立新的 BillingAccount,連結至機構。這個帳戶會取代舊帳戶。

  2. 在 platform 命名空間中找出 BillingAccountBinding 資源 YAML 檔案,查看連結的帳單帳戶:

    kubectl --kubeconfig ORG_GLOBAL_CLUSTER_KUBECONFIG describe billingaccountbinding billing -n platform
    
  3. 修改 BillingAccountBinding,連結至新的帳單帳戶。在「billingAccountRef」部分,使用步驟 1 建立的新 BillingAccount 名稱填入「name」欄位。

    kubectl --kubeconfig ORG_GLOBAL_CLUSTER_KUBECONFIG edit billingaccountbinding billing -n platform
    
  4. 完成變更後,請確認帳單帳戶已正確更新:

    kubectl --kubeconfig ORG_GLOBAL_CLUSTER_KUBECONFIG describe billingaccountbinding billing -n platform