管理及刪除資源


瞭解 Config Connector 如何管理現有資源,以及如何刪除資源

建立資源

建立資源時,如果資源不存在,Config Connector 會建立該資源。如果已存在名稱相同的 Google Cloud 資源,Config Connector 會取得並管理該資源。

如要進一步瞭解如何建立資源,請參閱入門指南

您也可以使用 resourceID 欄位管理資源。詳情請參閱「使用 resourceID 欄位管理資源」。

取得現有資源

本節說明如何使用 Config 連接器取得現有的 BigQuery 資源。

事前準備

  1. 啟用 BigQuery API
  2. 確認您有權存取 bq 指令列工具。如果您沒有 bq,請使用 Cloud Shell 或透過 gcloud CLI 安裝。

取得 BigQuery 資料集

當資訊清單中的值與資源名稱相符時,Config Connector 會取得或控制資源。如果資源沒有名稱 (例如專案 ID),系統會使用資源的 ID。

您可以建立空白的 BigQuery 資料集,然後使用 Config Connector 取得資料集,瞭解 Config Connector 如何處理現有資源。

  1. 使用 bq 建立名為 bigquerydatasetsample 的 BigQuery 資料集。

    bq --location=US mk \
    --dataset \
    --default_table_expiration 3600 \
    --description description \
    PROJECT_ID:bigquerydatasetsample
  2. 將下列內容複製到名為 bq-sample.yaml 的檔案中。

      apiVersion: bigquery.cnrm.cloud.google.com/v1beta1
      kind: BigQueryDataset
      metadata:
        name: bigquerydatasetsample
      spec:
        defaultTableExpirationMs: 3600000
        description: "BigQuery Dataset Sample"
        friendlyName: bigquerydataset-sample
        location: US
    
  3. 將 yaml 套用至叢集。

    kubectl apply --namespace CC_NAMESPACE -f bq-sample.yaml

    CC_NAMESPACE 替換為 Config Connector 管理資源的命名空間。

  4. 使用 kubectl describe 查看資料集詳細資料。

    kubectl describe --namespace CC_NAMESPACE bigquerydataset bigquerydatasetsample

    CC_NAMESPACE 替換為 Config Connector 管理資源的命名空間。

    kubectl describe 的輸出內容包含資源狀態和擁有權的中繼資料。

刪除資料集

根據預設,Config Connector 取得並管理資源後,從叢集中刪除物件就會刪除該資源。如果您想保留資料集,請設定資源的 deletion-policy

舉例來說,刪除取得 bigquerydataset-sample 的資訊清單,就會從 BigQuery 刪除資料集。

  1. 您可以使用 kubectl delete 刪除 bigquerydataset-sample 資料集。

    kubectl delete --namespace CC_NAMESPACE -f bq-sample.yaml

    CC_NAMESPACE 替換為 Config Connector 管理資源的命名空間。

    kubectl 的輸出內容會確認刪除作業。 bigquerydataset.bigquery.cnrm.cloud.google.com "bigquerydatasetsample" deleted

  2. 使用 bq 確認資料集已不存在。

    bq show PROJECT_ID:bigquerydatasetsample

    指令輸出內容包含 Not Found

取得資源時受限的資源

含有服務產生資源 ID 的資源

您只能使用 resourceID 欄位取得具有服務產生的資源 ID 的 Google Cloud 資源。

下列 Config Connector 資源對應至 Google Cloud具有服務產生資源 ID 的資源:

  • AccessContextManagerAccessPolicy
  • ApigeeOrganization
  • BillingBudgetsBudget
  • CloudIdentityGroup
  • CloudIdentityMembership
  • ComputeFirewallPolicy
  • DLPDeidentifyTemplate
  • DLPInspectTemplate
  • DLPJobTrigger
  • DLPStoredInfoType
  • Folder
  • IAPBrand
  • IAPIdentityAwareProxyClient
  • IdentityPlatformTenant
  • MonitoringAlertPolicy
  • MonitoringGroup
  • MonitoringNotificationChannel
  • MonitoringUptimeCheckConfig
  • RecaptchaEnterpriseKey
  • ResourceManagerLien
  • SQLSSLCert
  • SecretManagerSecretVersion
  • StorageNotification
  • StorageTransferJob
  • VertexAIDataset
  • VertexAIIndex

如要瞭解如何使用 resourceID 欄位,請參閱「使用 resourceID 欄位管理資源」。

無法取得的資源

下列 Config Connector 資源不支援取得現有 Google Cloud 資源:

  • DataflowFlexTemplateJob
  • FirestoreIndex
  • IAMServiceAccountKey

刪除後保留資源

...
metadata:
  annotations:
    cnrm.cloud.google.com/deletion-policy: abandon
...

例如,先前所述 BigQuery 資料集的 YAML 格式,包括 abandon 刪除政策,如下所示:

apiVersion: bigquery.cnrm.cloud.google.com/v1beta1
kind: BigQueryDataset
metadata:
  name: bigquerydatasetsample
  annotations:
    cnrm.cloud.google.com/deletion-policy: abandon
spec:
  defaultTableExpirationMs: 3600000
  description: "BigQuery Dataset Sample"
  friendlyName: bigquerydataset-sample
  location: US

後續步驟

  • 瞭解 Config Connector 如何使用 Kubernetes 結構體模擬 Google Cloud 資源。
  • 請參閱 Google Cloud 資源 Config Connector 可管理的資源。
  • 如需其他範例,請參閱 GitHub 存放區,瞭解如何使用 Config Connector。
  • 瞭解 Kubernetes 如何處理物件的宣告式設定