自訂 Google Cloud 安裝作業

瞭解如何在 GKE 叢集中安裝 Knative Serving Google Cloud。Knative serving 現在使用 Cloud Service Mesh 和 GKE Enterprise 機群。瞭解 Knative serving 叢集安裝作業的新功能和異動項目

您可以使用這個頁面自訂新安裝項目,或設定現有的 Knative Serving 機群安裝項目。舉例來說,您可以設定私人叢集或設定 Cloud Monitoring 憑證。

預設安裝步驟會自動部署下列 CloudRun 自訂資源,在 Google Cloud 叢集上啟用 GKE Enterprise 指標:

  apiVersion: operator.run.cloud.google.com/v1alpha1
  kind: CloudRun
  metadata:
    name: cloud-run

如要瞭解一般自訂資源,請參閱「自訂資源」。

事前準備

  • 請務必符合安裝必要條件

  • 如果叢集已安裝 Knative Serving,請務必先確認「GKE 外掛程式」不存在,再執行這些艦隊元件安裝步驟。如果已安裝「外掛程式」,請按照升級至 GKE Enterprise 艦隊的步驟操作

    檢查是否已安裝「GKE 外掛程式」。

    如要檢查 Knative Serving 安裝是否為「GKE 外掛程式」,請執行下列指令:

    gcloud container clusters describe \
    CLUSTER_NAME \
    --region CLUSTER_LOCATION \
    --project PROJECT_ID --format='get(addonsConfig.cloudRunConfig)'

    取代:

    • CLUSTER_NAME 改為叢集名稱。
    • CLUSTER_LOCATION 替換為叢集所在的位置
    • PROJECT_ID 替換為專案的 ID。 Google Cloud

    結果:

    • 未安裝「GKE add-on
      • 如果從未安裝外掛程式,終端機不會傳回任何內容。
      • 如果先前已解除安裝外掛程式,則會傳回 disabled=true
    • 已安裝「GKE 外掛程式:如果叢集已安裝外掛程式,系統會傳回外掛程式的設定詳細資料。範例:loadBalancerType=LOAD_BALANCER_TYPE_EXTERNAL
    範例:
    以下範例顯示 Knative Serving 是透過「GKE 外掛程式」安裝在 my-addon-cluster 叢集中,且已設定為處理外部流量:
    gcloud container clusters describe my-addon-cluster \
    --region us-central1-c --project my-gcp-project \
    --format='get(addonsConfig.cloudRunConfig)'

    回應:

    loadBalancerType=LOAD_BALANCER_TYPE_EXTERNAL

設定 CloudRun 自訂資源

您需要手動建立及設定 CloudRun 自訂資源,才能設定安裝作業。

如要在 CloudRun 上為 GKE 叢集手動建立 Google Cloud自訂資源:
  1. 建立 YAML 檔案並納入預設設定,例如:cloudrunanthos.yaml

    apiVersion: operator.run.cloud.google.com/v1alpha1
    kind: CloudRun
    metadata:
      name: cloud-run
    
  2. cloudrunanthos.yaml 中,您可以透過設定 spec 區段下的一或多個屬性,自訂安裝作業:

    • 私有叢集:您必須新增 clusterConfigisPrivate 屬性集,才能在私有叢集上安裝 Knative 服務。 Google Cloud

      clusterConfigisPrivate 屬性:

      spec:
        clusterConfig:
          isPrivate: true
      

      請注意,這項設定會停用受管理 TLS,因為私人叢集預設無法與憑證授權單位通訊。

    • 指標:新增 metricscollector 屬性集,以設定 Cloud Monitoring。根據預設,系統會為 Google Cloud 叢集上的 GKE Enterprise 啟用指標。

      spec:
        metricscollector:
          stackdriver:
            projectid: PROJECT_ID
            gcpzone: CLUSTER_LOCATION
            clustername: CLUSTER_NAME
            secretname: SECRET_NAME
            secretkey: SECRET_KEY
      

      更改下列內容:

      • PROJECT_ID 替換為專案的 ID。 Google Cloud
      • CLUSTER_LOCATION,並將 region 或 zone 替換為叢集所在的區域。
      • CLUSTER_NAME 改成叢集 ID 或叢集的完整 ID。
      • SECRET_NAME,並將 knative-serving 命名空間的服務帳戶私密金鑰名稱。
      • SECRET_KEY,並將 knative-serving 命名空間的服務帳戶私密金鑰。例如:key.json

        如要進一步瞭解服務帳戶,請參閱:

範例

在這個 CloudRun 自訂資源範例中,Cloud Monitoring 的設定詳細資料會指定使用 my-gcp-logging-secret 密鑰和 key.json 金鑰:

 apiVersion: operator.run.cloud.google.com/v1alpha1
 kind: CloudRun
 metadata:
   name: cloud-run
 spec:
   metricscollector:
     stackdriver:
       projectid: my-gcp-project-id
       gcpzone: us-central1-c
       clustername: my-anthos-cluster-name
       secretname: my-gcp-logging-secret
       secretkey: key.json
 ```

啟用並安裝 Knative serving

在 GKE Enterprise 機群中啟用 Knative 服務元件,然後部署 CloudRun 自訂資源:

  1. 在機群中啟用 Knative serving:

    gcloud container fleet cloudrun enable --project=PROJECT_ID
    

    PROJECT_ID 替換為專案 ID。 Google Cloud

    如需詳細資料和其他選項,請參閱 gcloud container fleet cloudrun enable 參考資料。

  2. 選用:確認 Knative serving 功能元件已啟用:

    控制台

    在Google Cloud 控制台中查看 Knative serving 元件是否已啟用

    前往功能管理工具

    指令列

    查看 appdevexperience 狀態是否為 ACTIVE

    gcloud container fleet features list  --project=PROJECT_ID
    

    PROJECT_ID 替換為專案 ID。 Google Cloud

    如需詳細資料和其他選項,請參閱 gcloud container fleet features list 參考資料。

    結果:

    NAME               STATE
    appdevexperience   ACTIVE
    
  3. 如要在每個 GKE Enterprise 叢集安裝 Knative Serving,您必須部署CloudRun自訂資源:

    gcloud

    gcloud container fleet cloudrun apply --gke-cluster=CLUSTER_LOCATION/CLUSTER_NAME --config=CONFIG_FILE
    

    更改下列內容:

    • CLUSTER_LOCATION,並將 region 或 zone 替換為叢集所在的區域。
    • CLUSTER_NAME 改成叢集 ID 或叢集的完整 ID。
    • CONFIG_FILE,並將檔案名稱設為自訂資源的相對路徑。cloudRun範例 cloudrunanthos.yaml

    如需詳細資料和其他選項,請參閱 gcloud container fleet cloudrun apply 參考資料。

    kubectl

    kubectl apply --kubeconfig=KUBECONFIG --filename CONFIG_FILE
    

    更改下列內容:

    • KUBECONFIG 是 kubectl 設定檔的絕對路徑。
    • CONFIG_FILE,其中包含檔案名稱和自訂資源的相對路徑。cloudRun例如:cloudrunanthos.yaml

    如需詳細資料和其他選項,請參閱 kubectl apply 參考資料。

  4. 確認叢集已啟用 Knative Serving:
    1. 開啟 Google Cloud 控制台:

      前往 GKE 叢集

    2. 按一下叢集名稱,開啟詳細資料窗格。

    3. 執行下列指令,確認是否能看到 Knative serving 版本詳細資料: kubectl get all -n knative-serving -o 'go-template={{index .metadata.labels "serving.knative.dev/release"}}'
    4. 確認 knative-servingappdevexperience 命名空間下,所有 Knative 服務專屬的部署作業都處於執行狀態。

後續步驟

設定 Knative serving 安裝項目