本頁面說明排程器選項,以及如何在 Google Distributed Cloud 軟體 (僅限裸機叢集) 中,設定預設 Pod 排程限制。
Google Distributed Cloud 提供多項標準 Kubernetes 功能,可用於控管排程 Pod,例如:
如要瞭解 Kubernetes 中的 Pod 拓撲分布限制,請參閱 Kubernetes 說明文件中的「Kubernetes 排程器」。
事前準備
設定預設 Pod 分布前,請確認叢集中的每個節點都有正確的拓撲標籤。您可以使用 Nodepool.Spec.TaintsAndLabels API 套用標籤。手動使用 kubectl label 標記節點可提供更多彈性,但當您將新節點新增至叢集時,必須手動標記。
設定預設自訂排程器 {#:config-default}
標籤節點
在叢集和節點集區 YAML 檔案中新增拓撲標籤。以下範例假設兩個 worker 節點集區位於不同的機架,而控制層節點位於
rack1。apiVersion: baremetal.cluster.gke.io/v1 kind: Cluster metadata: name: abm-cluster namespace: cluster-abm-cluster spec: controlPlane: nodePoolSpec: labels: topology.k8s.io/rack: rack1 --- apiVersion: baremetal.cluster.gke.io/v1 kind: NodePool metadata: name: nodepool-rack1 namespace: cluster-abm-cluster spec: labels: topology.k8s.io/rack: rack1 --- apiVersion: baremetal.cluster.gke.io/v1 kind: NodePool metadata: name: nodepool-rack2 namespace: cluster-abm-cluster spec: labels: topology.k8s.io/rack: rack2套用更新後的叢集設定。
bmctl update cluster -c CLUSTER_NAME將
CLUSTER_NAME替換為叢集名稱。等待
topology.k8s.io/rack標籤傳播至叢集中的所有節點。
啟用預設 Pod 分散限制
將
preview.baremetal.cluster.gke.io/custom-scheduler-configuration:enable註解新增至叢集 YAML 檔案。在叢集 YAML 檔案的
cluster.spec.controlPlane下方,新增schedulerConfiguration區段。apiVersion: baremetal.cluster.gke.io/v1 kind: Cluster metadata: name: abm-cluster namespace: cluster-abm-cluster annotations: preview.baremetal.cluster.gke.io/custom-scheduler-configuration: enable spec: controlPlane: schedulerConfiguration: defaultTopologySpreadConstraint: defaultConstraints: - topologyKey: topology.k8s.io/rack whenUnsatisfiable: DoNotSchedule maxSkew: 1 defaultingType: List套用更新後的叢集設定。
bmctl update cluster -c CLUSTER_NAME將
CLUSTER_NAME替換為叢集名稱。等待叢集協調完成。監控
cluster.status.clusterState,直到顯示Running為止。在這個程序中,系統會為每個控制層節點執行control-plane-update工作。
驗證 Pod 分散設定
建立含有五個副本的測試 Deployment。
觀察 Pod 分布情形。
nodepool-rack1和nodepool-rack2上的 Pod 數量差異應恰好為一。驗證每個控制層節點上的
kube-scheduler-profile.config檔案。檔案位於/etc/kubernetes/kube-scheduler-profile.config,必須包含cluster.spec的拓撲分布設定。
疑難排解
如要診斷及解決預設 Pod 分布問題,請檢查下列項目:
- 查看
BareMetalMachine.Status.ControlPlaneComponents,瞭解功能狀態。 - 檢查
cluster-operator和cap-controller-manager的記錄,找出相關事件。 - 如果
kube-scheduler靜態 Pod 當機,請檢查叢集 YAML 檔案中的排程器設定是否正確。
後續步驟
- 如要進一步瞭解 Pod 拓撲分布限制,請參閱 Kubernetes 說明文件。
- 如果遇到問題,請參閱「排解 Kubernetes 排程器問題」。