設定排程

本頁面說明排程器選項,以及如何在 Google Distributed Cloud 軟體 (僅限裸機叢集) 中,設定預設 Pod 排程限制。

Google Distributed Cloud 提供多項標準 Kubernetes 功能,可用於控管排程 Pod,例如:

如要瞭解 Kubernetes 中的 Pod 拓撲分布限制,請參閱 Kubernetes 說明文件中的「Kubernetes 排程器」。

事前準備

設定預設 Pod 分布前,請確認叢集中的每個節點都有正確的拓撲標籤。您可以使用 Nodepool.Spec.TaintsAndLabels API 套用標籤。手動使用 kubectl label 標記節點可提供更多彈性,但當您將新節點新增至叢集時,必須手動標記。

設定預設自訂排程器 {#:config-default}

標籤節點

  1. 在叢集和節點集區 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
    
  2. 套用更新後的叢集設定。

    bmctl update cluster -c CLUSTER_NAME
    

    將 CLUSTER_NAME 替換為叢集名稱。

  3. 等待 topology.k8s.io/rack 標籤傳播至叢集中的所有節點。

啟用預設 Pod 分散限制

  1. 將 preview.baremetal.cluster.gke.io/custom-scheduler-configuration:enable 註解新增至叢集 YAML 檔案。

  2. 在叢集 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
    
  3. 套用更新後的叢集設定。

    bmctl update cluster -c CLUSTER_NAME
    

    將 CLUSTER_NAME 替換為叢集名稱。

  4. 等待叢集協調完成。監控 cluster.status.clusterState,直到顯示 Running 為止。在這個程序中,系統會為每個控制層節點執行 control-plane-update 工作。

驗證 Pod 分散設定

  1. 建立含有五個副本的測試 Deployment。

  2. 觀察 Pod 分布情形。nodepool-rack1 和 nodepool-rack2 上的 Pod 數量差異應恰好為一。

  3. 驗證每個控制層節點上的 kube-scheduler-profile.config 檔案。檔案位於 /etc/kubernetes/kube-scheduler-profile.config,必須包含 cluster.spec 的拓撲分布設定。

疑難排解

如要診斷及解決預設 Pod 分布問題,請檢查下列項目:

  1. 查看 BareMetalMachine.Status.ControlPlaneComponents,瞭解功能狀態。
  2. 檢查 cluster-operator 和 cap-controller-manager 的記錄,找出相關事件。
  3. 如果 kube-scheduler 靜態 Pod 當機,請檢查叢集 YAML 檔案中的排程器設定是否正確。

後續步驟