Apigee Hybrid Helm 遷移工具

<0x0

如果您使用 Apigee Hybrid 1.11 版,請參閱 Apigee Hybrid 1.11 版說明文件中的「Apigee Hybrid Helm 遷移工具」。

這項遷移工具可協助您將以 apigeectl 為基礎的混合式叢集,遷移至以 Helm 為基礎的混合式叢集。這項工具不會實際更換任何叢集元件,這個作業是冪等作業,可在同一個叢集上執行多次,每次準備元件和機構的子集。

您可以一次遷移所有 apigee 元件,工具執行完畢後,即可逐一升級 Helm 元件。

如要瞭解如何使用這項工具管理已遷移至 Helm 管理的混合式叢集,請參閱「使用 Helm 圖表安裝及管理 Apigee Hybrid」。

必要條件

  • Helm 3.10 以上版本。
  • 指向叢集的有效 kubeconfig 檔案,且叢集已安裝 Apigee Hybrid 1.10。
  • 修改要遷移的混合元件 Kubernetes 資源中繼資料和註解的權限。

範圍

這個工具在執行階段支援下列選項:

  • 自訂 apigee 資源的命名空間。預設命名空間:apigee
  • 僅遷移所選的混合式元件。預設:遷移所有元件
  • 僅限遷移單一機構
  • 僅遷移單一環境
  • 僅遷移單一環境群組 (apigee-virtualhost)
  • 為機構、環境和環境群組自訂 Helm 版本名稱。

限制

  • 這個工具不支援為下列混合式元件自訂 Helm 版本名稱:apigee-operatorapigee-datastoreapigee-redisapigee-telemetryapigee-ingress-manager
  • 對機構、環境和環境群組的 Helm 版本名稱進行互動式自訂時,這些變更不會自動保留在執行之間。您可以編輯暫時檔案,並在後續執行時提供該檔案做為選項。
  • 環境和環境群組的篩選作業只會依名稱進行。在某些情況下,這可能會導致多個環境和環境群組在多機構叢集上遷移。

    舉例來說,在具有機構 org1org2 的多機構叢集上,如果兩個機構都有環境 prod,且只指定 --env=prod,則兩個環境都會遷移。如要只遷移單一環境,您也必須指定機構篩選器 --org=org1--org=org2

用量

語法

apigee-helm-migration [--apigee-namespace=] [--components=] [--dry-run] [--env=org1] [--env-group=org2] [--org=baz] [--kubeconfig=] [-y] [-v] [-f /path/to/releaseNames.yaml]

產生的 Helm 發布名稱

部署至叢集的每個 Helm Chart 都必須有發布名稱,且該名稱在命名空間中不得重複。相較於圖表名稱,Helm 發布名稱沒有任何命名慣例或限制。遷移工具會為每個元件產生不重複的 Helm 版本名稱。

圖表 單一機構叢集 多機構叢集
apigee-operator operator operator
apigee-datastore datastore datastore
apigee-telemetry telemetry telemetry
apigee-redis redis redis
apigee-ingress-manager ingress-manager ingress-manager
apigee-org ORG_NAME ORG_NAME
apigee-env ENV_NAME[-env[-n]](1) ORG_NAME-ENV_NAME[-env[-n]](1)
apigee-virtualhost (envgroup) VH_NAME[-env-group[-n]](1) ORG_NAME-VH_NAME[-env-group[-n]](1)

(1) 如果產生的名稱與其他產生的名稱衝突,名稱後方會加上 -env-env-group。如果仍有衝突,則會進一步加上 -1-2 … 後置字元。

自訂 Helm 版本名稱

遷移工具可讓您以互動方式自訂 Helm 版本名稱。如要以非互動方式自訂 Helm 版本名稱:

  1. 執行一次工具,並在第一個提示中結束,即可建立包含自動產生發布名稱的暫存檔案。您應該會看到類似下列內容的行:
    INFO: 21:32:56 using temp file for release names:  /tmp/apigee-helm-migration-1229129207-releaseNames
  2. 移動或複製這個檔案,然後編輯。執行遷移工具時,您可以透過 -f 選項傳遞這個編輯過的檔案。自動產生的版本名稱如下:

    orgs:
      example-apigee-org:
        helmReleaseName: example-apigee-org
        envs:
          prod:
            helmReleaseName: prod
        envGroups:
          prod-envgroup:
            helmReleaseName: prod-envgroup

    如要自訂機構、環境或環境群組的 Helm 版本名稱,請編輯該物件的 helmReleaseName 欄位。舉例來說,如要將機構版本重新命名為 custom-org、環境版本重新命名為 custom-env,以及環境群組版本重新命名為 custom-group,產生的檔案會如下所示:

    orgs:
      example-apigee-org:
        helmReleaseName: custom-org
        envs:
          prod:
            helmReleaseName: custom-env
        envGroups:
          prod-envgroup:
            helmReleaseName: custom-group

使用自訂命名空間

Apigee Hybrid 會在兩個 Kubernetes 命名空間中執行:

  • apigee-systemapigee-operator 元件一律會在 apigee-system 命名空間中執行。無論您使用 --apigee-namespace 旗標指定什麼,Helm 遷移工具都會更新 apigee-system 命名空間中的 apigee-operator 元件。
  • apigee:除了 apigee-operator 以外的所有混合式元件,都會在這個命名空間中執行。apigee 是預設名稱。您可以為這些元件使用任何自訂命名空間。

    如果您使用自訂命名空間,執行 Helm 遷移工具時,必須使用 --apigee-namespace my_custom_namespace 標記指定該命名空間。

    您也必須在覆寫檔案中新增 namespace: my_custom_namespace 頂層屬性。

Directions

  1. 下載遷移工具。

    Linux

    1. 使用下列指令將最新版本號碼儲存在變數中:
      export VERSION=$(curl -s "https://storage.googleapis.com/apigee-release/hybrid/apigee-migration-tool/current-version.txt?ignoreCache=1")
    2. 使用下列指令,確認變數是否已填入版本號碼。如要使用其他版本,可以改為將版本儲存在環境變數中。
      echo $VERSION

      例如:

      echo $VERSION
      1.0.5
    3. 使用下列指令,下載適用於您作業系統的版本套件:

      curl -LO https://storage.googleapis.com/apigee-release/hybrid/apigee-migration-tool/${VERSION}/apigee-helm-migration_linux_64.tar.gz
    4. 使用下列指令解壓縮檔案:

      tar -xzf apigee-helm-migration_linux_64.tar.gz

    Mac OS

    1. 使用下列指令將最新版本號碼儲存在變數中:
      export VERSION=$(curl -s "https://storage.googleapis.com/apigee-release/hybrid/apigee-migration-tool/current-version.txt?ignoreCache=1")
    2. 使用下列指令,確認變數是否已填入版本號碼。如要使用其他版本,可以改為將版本儲存在環境變數中。
      echo $VERSION

      例如:

      echo $VERSION
      1.0.5
    3. 使用下列指令,下載適用於您作業系統的版本套件:

      curl -LO https://storage.googleapis.com/apigee-release/hybrid/apigee-migration-tool/${VERSION}/apigee-helm-migration_mac_64.tar.gz
    4. 使用下列指令解壓縮檔案:

      tar -xzf apigee-helm-migration_mac_64.tar.gz

    Windows

    1. 使用下列指令將最新版本號碼儲存在變數中:
      for /f "tokens=*" %a in ('curl -s https://storage.googleapis.com/apigee-release/hybrid/apigee-migration-tool/current-version.txt') do set VERSION=%a
    2. 使用下列指令,確認變數是否已填入版本號碼。如要使用其他版本,可以改為將版本儲存在環境變數中。
      echo %VERSION%

      例如:

      echo %VERSION%
      1.0.5
    3. 使用下列指令,下載適用於您作業系統的版本套件:

      curl -LO https://storage.googleapis.com/apigee-release/hybrid/apigee-migration-tool/%VERSION%/apigee-helm-migration_windows_64.tar.gz
    4. 使用下列指令解壓縮檔案:

      tar xzvf apigee-helm-migration_windows_64.tar.gz
  2. 執行遷移工具。如果預設選項可接受,只要執行工具時不帶任何引數,並在系統提示時核准產生的 Helm 版本名稱即可。以下列舉幾個例子:
    • 簡單的安裝作業,使用預設 kubeconfig (~/.kube/config)、預設 apigee 命名空間和預設 Helm 發布名稱。

      下列指令應適用於大多數 (如果不是全部) 安裝作業。工具執行完畢後,即可針對每個元件執行 Helm 升級作業。

      ./apigee-helm-migration
      
    • 遷移使用自訂命名空間的所有元件:
      ./apigee-helm-migration --apigee-namespace my_custom_namespace
      
    • 只遷移 operatordatastore 元件:

      ./apigee-helm-migration --components operator,datastore
      
        INFO: 00:22:48 using kubeconfig file  /usr/local/google/home/example/.kube/config
        INFO: 00:22:48 namespace for apigee resources:
        INFO: 00:22:48 	 apigee
        INFO: 00:22:48 processing all organizations in cluster
        INFO: 00:22:48 Components to migrate:
        INFO: 00:22:48 	 operator,datastore
        INFO: 00:22:48 dry-run:
        INFO: 00:22:48 	 false
        Continue with patching apigee resources for Helm migration? [y/n]: y
        INFO: 00:22:52 Processing component:  operator
        INFO: 00:22:54 Processing component:  datastore
        INFO: 00:22:55 Migration successful!
    • 指向特定 kubeconfig 檔案,並為 apigee 命名空間指定不同名稱。

      ./apigee-helm-migration --kubeconfig /abs/path/to/kubeconf --namespace org1_namespace
      
    • 遷移所有元件,但只有一個機構:

      ./apigee-helm-migration --org=some-test-org
      

    以下是遷移成功時的輸出範例:

    INFO: 21:32:55 using kubeconfig file  /usr/local/google/home/example/.kube/config
    INFO: 21:32:55 namespace for apigee resources:
    INFO: 21:32:55 	 apigee
    INFO: 21:32:55 processing all organizations in cluster
    INFO: 21:32:55 processing all components
    INFO: 21:32:55 dry-run:
    INFO: 21:32:55 	 false
    INFO: 21:32:55 cluster Apigee information:
    INFO: 21:32:55 Apigee Organizations found:
    INFO: 21:32:56 	 example-hybrid-dev
    INFO: 21:32:56 Apigee Environments found (org: env):
    INFO: 21:32:56 	 example-hybrid-dev : prod
    INFO: 21:32:56 Apigee EnvGroups(apigeerouteconfigs) found (org: envGroup):
    INFO: 21:32:56 	 example-hybrid-dev : prod-envgroup
    INFO: 21:32:56 using temp file for release names:  /tmp/apigee-helm-migration-1229129207-releaseNames
    INFO: 21:32:56 Helm release names for Apigee orgs/envs/envgroups:
    orgs:
    example-hybrid-dev:
    helmReleaseName: example-hybrid-dev
    envs:
      prod:
        helmReleaseName: prod
    envGroups:
      prod-envgroup:
        helmReleaseName: prod-envgroup
    Make changes to the release names for Apigee orgs/env/envgroups? [y/n]: n
    Continue with patching apigee resources for Helm migration? [y/n]: y
    INFO: 21:32:59 Processing component:  operator
    INFO: 21:33:01 Processing component:  datastore
    INFO: 21:33:01 Processing component:  redis
    INFO: 21:33:02 Processing component:  ingress-manager
    INFO: 21:33:02 Processing component:  telemetry
    INFO: 21:33:03 Processing component:  orgs
    INFO: 21:33:05 Processing component:  envs
    INFO: 21:33:06 Processing component:  env-groups
    INFO: 21:33:07 Migration successful!

    潛在錯誤:

    • 錯誤:無法剖析發布名稱檔案:請檢查傳入的發布名稱檔案。
    • 找不到資源:請確認 Apigee Hybrid 已完整安裝,且您有權存取 apigee 資源。

下一步

請按照「使用 Helm 資訊套件安裝及管理 Apigee Hybrid」一文的指示,繼續安裝 Apigee Hybrid Helm 資訊套件。

-help 的輸出內容

./apigee-helm-migration --help
Usage of ./apigee-helm-migration:
  -apigee-namespace string
      namespace used for apigee resources (default "apigee")
  -components string
      CSV of components to migrate. If empty then all components are migrated. Valid values are: operator,datastore,redis,ingress-manager,telemetry,orgs,envs,env-groups
  -dry-run
      perform a dry-run
  -env string
      restrict migration to a singular supplied env. If empty then all envs detected in the cluster are migrated
  -env-group string
      restrict migration to a singular supplied envGroup. If empty then all envGroups detected in the cluster are migrated
  -kubeconfig string
      (optional) absolute path to the kubeconfig file (default "/usr/local/google/home/example/.kube/config")
  -org string
      restrict migration to a singular supplied org. If empty then all orgs detected in the cluster are migrated
  -v	Increased logging verbosity
  -y	don't prompt for confirmation or for configuration of Helm releases