安裝 GCP Service Broker

本文件是 GCP Service Broker 在 GitHub 存放區中說明文件的修改版本。

事前準備

  1. 已安裝 Kf 的叢集。
  2. gcloud:請按照這些操作說明安裝 gcloud CLI。
  3. kubectl:安裝 gcloud 後,請執行 gcloud components install kubectl
  4. helm:請按照這些操作說明安裝 helm CLI。
  5. git:您必須使用 Git 複製存放區。

設定

選取專案

請選擇您要用於本教學課程其餘部分的 Google Cloud 專案。這個專案應與 Kf 叢集使用的專案相同。

您必須是所選專案的擁有者。您可以視需要變更下列值,以反映您的環境,然後在終端機中設定這些環境變數:

export PROJECT_ID=$(gcloud config get-value project)
export SERVICE_ACCOUNT_NAME=kf-gcp-broker

為仲介建立服務帳戶

  1. 建立服務帳戶:

    gcloud iam service-accounts create $SERVICE_ACCOUNT_NAME
  2. 建立新的憑證,讓代管服務業者進行驗證,並將憑證下載至 key.json

    gcloud iam service-accounts keys create key.json --iam-account $SERVICE_ACCOUNT_NAME@$PROJECT_ID.iam.gserviceaccount.com
  3. 將專案擁有者權限授予仲介:

    gcloud projects add-iam-policy-binding $PROJECT_ID --member serviceAccount:$SERVICE_ACCOUNT_NAME@$PROJECT_ID.iam.gserviceaccount.com --role "roles/owner"

啟用必要的 API

您現在需要啟用 API,讓仲介器配置資源。

代理程式有幾個必須執行的 API,以及幾個可選的 API (必須啟用才能佈建特定類型的資源)。

必須使用 Cloud Resource Manager 和 Identity and Access Management API,才能執行仲介器。如要啟用這些功能,請按照下列步驟操作:

gcloud services enable cloudresourcemanager.googleapis.com iam.googleapis.com --project $PROJECT_ID

啟用 API

為了在專案中佈建 Cloud 服務,Kef 建議至少啟用下列 API:

  1. CloudSQL API
  2. CloudSQL Admin API
  3. Pub/Sub API
  4. Redis API
  5. Storage API

GCP 服務代理程式也支援多種其他服務,您可以啟用這裡列出的 API,為這些服務新增支援功能。

安裝服務代理程式

  1. 將 GCP 服務代理程式複製到本機工作站,並將 cd 複製到該工作站:

    git clone --depth=1 "https://github.com/GoogleCloudPlatform/gcp-service-broker"
    cd gcp-service-broker/deployments/helm/gcp-service-broker
  2. 更新 Helm 資訊套件的依附元件:

    helm dependency update
  3. 編輯 values.yaml 檔案,並將 broker.service_account_json 的值設為包含 key.json 完整內容的字串。

    選用:請詳閱其他屬性,並視需要變更符合您環境的屬性。

    # ...
    broker:
      # ...
      service_account_json: "contents of key.json go here"
    # ...
  4. 如果是在實際環境中執行,請將 mysql.embedded 設為 false,並為具有自動備份和容錯功能的外部 MySQL 資料庫提供憑證。

  5. 為 GCP Service Broker 建立 Kubernetes 命名空間:

    kubectl create namespace gcp-service-broker
  6. 安裝代理程式:

    helm install gcp-service-broker --set svccat.register=false --namespace gcp-service-broker .
  7. 使用 Kf 註冊中介服務:

    kf create-service-broker gcp-service-broker \
      "$(kubectl get secret gcp-service-broker-auth -n gcp-service-broker -o jsonpath='{.data.username}' | base64 --decode)" \
      "$(kubectl get secret gcp-service-broker-auth -n gcp-service-broker -o jsonpath='{.data.password}' | base64 --decode)" \
      "http://gcp-service-broker.gcp-service-broker.svc.cluster.local"

確認中介軟體安裝

執行 kf marketplace。 畫面會顯示類似以下的輸出:

Broker              Name                          Space       Status  Description
gcp-service-broker  google-stackdriver-profiler               Active  Continuous CPU and heap profiling to improve performance and reduce costs.
gcp-service-broker  google-stackdriver-monitoring             Active  Stackdriver Monitoring provides visibility into the performance, uptime, and overall health of cloud
gcp-service-broker  google-dataflow                           Active  A managed service for executing a wide variety of data processing patterns built on Apache Beam.
gcp-service-broker  google-cloudsql-mysql                     Active  Google CloudSQL for MySQL is a fully-managed MySQL database service.
gcp-service-broker  google-spanner                            Active  The first horizontally scalable, globally consistent, relational database service.
gcp-service-broker  google-ml-apis                            Active  Machine Learning APIs including Vision, Translate, Speech, and Natural Language.
gcp-service-broker  google-pubsub                             Active  A global service for real-time and reliable messaging and streaming data.
gcp-service-broker  google-datastore                          Active  Google Cloud Datastore is a NoSQL document database service.
gcp-service-broker  google-stackdriver-debugger               Active  Stackdriver Debugger is a feature of the Google Cloud Platform that lets you inspect the state of an
gcp-service-broker  google-firestore                          Active  Cloud Firestore is a fast, fully managed, serverless, cloud-native NoSQL document database that simp
gcp-service-broker  google-bigtable                           Active  A high performance NoSQL database service for large analytical and operational workloads.
gcp-service-broker  google-storage                            Active  Unified object storage for developers and enterprises. Cloud Storage allows world-wide storage and r
gcp-service-broker  google-stackdriver-trace                  Active  Stackdriver Trace is a distributed tracing system that collects latency data from your applications
gcp-service-broker  google-cloudsql-postgres                  Active  Google CloudSQL for PostgreSQL is a fully-managed PostgreSQL database service.
gcp-service-broker  google-dialogflow                         Active  Dialogflow is an end-to-end, build-once deploy-everywhere development suite for creating conversatio
gcp-service-broker  google-bigquery                           Active  A fast, economical and fully managed data warehouse for large-scale data analytics.

安裝 GCP Service Broker 後,您可以使用該工具建立服務,並將服務繫結至透過 Kf 部署的應用程式。