與使用其他 tanzu cluster node-pooltanzu 命令相比,對使用 ClusterClass 定義的叢集使用 tanzu cluster node-pool 命令時,行為存在差異。在針對基於 ClusterClass 的叢集執行時,所有這些 API 的共同點是需要更新叢集,尤其是叢集拓撲。
tanzu cluster node-pool deletetanzu cluster node-pool delete 命令是最直接的變更。此時將更新叢集資源,以移除具有傳遞到刪除 API 的節點集區名稱的機器部署定義。API 仍禁止刪除叢集中的最終節點集區。
tanzu cluster node-pool delete tkg-wc-vsphere -n md–0
tanzu cluster node-pool listtanzu cluster node-pool list 命令將擷取 MachineDeployment 資源,方法與基於計劃的叢集案例相同,並將這些資源與叢集拓撲中的機器部署進行比對。這可讓 tanzu cluster node-pool list 命令傳回具有相同名稱的 MachineDeployment 資源,以比對叢集拓撲中定義的機器部署。
tanzu cluster node-pool list tkg-wc-vsphere
NAME NAMESPACE PHASE REPLICAS READY UPDATED UNAVAILABLE
md-0 default Ready 1 1 1 0
可以在基於 ClusterClass 的叢集中的節點集區上更新的屬性可分為兩種類型:
ClusterClass 層級的變數定義。部署基於 ClusterClass 的叢集時,叢集定義必須指定許多這類的變數,這些變數預設適用於所有機器部署。機器部署拓撲可基於機器部署覆寫這些變數。可以修改的屬性的決定性來源是 ClusterClass 物件本身。TKG ClusterClass 物件均定義了包含 worker 節點虛擬機器屬性的 worker 變數。這分別包括 AWS 和 Azure 的 instanceType 和 vmSize。vSphere 版本包括 diskGiB、memoryMiB 和 numCPU 的屬性。具有主管的 TKG 為 vmClass 和 storageClass 定義了最上層變數,並為 nodePoolVolumes 定義了一個陣列,用於自訂 worker 節點。vSphere 上的 TKG 還定義了 vcenter 變數,用於更新與 vCenter Server 執行個體相關的屬性。
所有 TKG ClusterClass 物件定義一個 nodePoolLabels 變數,該變數指定要套用於 worker 節點上的節點標籤。
重要Tanzu CLI 提供的
node-pool命令需要在ClusterClass上定義上述變數,以支援建立和更新節點集區。如果使用自訂ClusterClass,這些變數需要作為ClusterClass中的最上層變數定義。仍可以使用 Tanzu CLI 取得和刪除基於自訂ClusterClass的叢集上的節點集區。在特殊情況下,tanzu cluster node-pool create和tanzu cluster node-pool update將適用於自訂ClusterClass物件,尤其如果傳遞到 Tanzu CLI 的節點集區定義最多指定replicas、az、name、workerClass和tkrResolver變數。在這種情況下,workerClass必須與自訂workerClass中的ClusterClass定義相符。
tanzu cluster node-pool set 更新現有節點集區使用現有節點集區的名稱叫用 tanzu cluster node-pool set 命令時,更新將僅修改已命名節點集區的複本計數和標籤 (如果已提供)。將忽略提供的任何其他選項。特別是,如果提供了這些值,叢集的拓撲將使用新的複本計數和 nodePoolLabels 變數覆寫進行更新。
tanzu cluster node-pool set 建立一個新節點集區建立節點集區可以依照以下兩個路徑之一。您可以提供 tanzu cluster node-pool set 命令,用作新節點集區起點的基本機器部署。命名的基本機器部署的深層複本充當使用者提供的屬性分層的基礎。通常,這意味著複製的機器部署的所有變數覆寫項都將使用您提供的新值進行更新。這與未提供基本機器部署的情況不同。在這種情況下,將從叢集拓撲中定義的全域變數定義複製變數覆寫項,然後在這些變數上對使用者提供的值進行分層。此外,如果不提供基本機器部署,則必須提供 workerClass 和 tkrResolver 定義。TKG ClusterClass 物件預設定義一個 tkg-worker,除非您已新增自己的 worker 類別定義,否則應使用。tkrResolver 是 tkr-resolver 註解的值。
若要使用基本機器部署來建立新的節點集區,請執行下列命令:
tanzu cluster node-pool set tkg-wc-vsphere -f /path/to/node-pool.yml –-base-machine-deployment md-0
使用 node-pool.yml 檔案中的以下內容:
name: np-1
replicas: 1
nodeMachineType: t3.large
在不使用基礎機器部署的情況下建立新的節點集區,請執行下列命令:
tanzu cluster node-pool set tkg-wc-vsphere -f /path/to/node-pool.yml
使用 node-pool.yml 檔案中的以下內容:
name: np-1
replicas: 1
nodeMachineType: t3.large
workerClass: tkg-worker
tkrResolver: os-name=ubuntu,os-arch=amd64