リソース伝達エラー: PlacementScheduled が false です

概要

この記事では、Azure Kubernetes Fleet Manager で配置 API を使用してリソースを伝達するときのスケジュール エラーのトラブルシューティング方法について説明します。 この問題は、 ClusterResourcePlacementResourcePlacementの両方に適用され、それぞれに独自のカスタム リソース条件の種類が適用されます。

  • ClusterResourcePlacementScheduled ClusterResourcePlacement の場合
  • ResourcePlacementScheduled ResourcePlacement の場合

サンプル エラー メッセージ:

  - lastTransitionTime: "2024-05-07T23:32:40Z"
    message: "couldn't find all the clusters needed as specified by the scheduling policy"
    observedGeneration: 1
    reason: SchedulingPolicyUnfulfilled
    status: "False"
    type: ClusterResourcePlacementScheduled

症状

Azure Kubernetes Fleet Manager で ClusterResourcePlacement または ResourcePlacement API オブジェクトを使用してリソースを伝達する場合、フリート ワークロードのスケジューラは、スケジュール ポリシーで指定されたすべての必要なクラスターを見つけることができません。また、 ClusterResourcePlacementScheduled (ClusterResourcePlacement の場合) または ResourcePlacementScheduled (ResourcePlacement の場合) の状態は Falseと表示されます。

スケジュールが失敗する理由の詳細を取得するには、スケジューラ ログを確認します。 フリート エージェント ログの表示の詳細については、「 Azure Kubernetes Fleet Manager でのエージェント ログの表示」を参照してください。

原因

この問題は、次のいずれかの理由で発生する可能性があります。

  • 配置ポリシーは PickFixedに設定されていますが、指定されたクラスター名がフリート内の結合されたメンバー クラスター名と一致しないか、指定されたクラスターがフリートに接続されなくなりました。
  • 配置ポリシーは PickN に設定され、N 個のクラスターが指定されていますが、フリートに参加したクラスターや配置ポリシーを満たしたクラスターが N 個よりも少なくなっています。
  • 配置リソース セレクターは、予約済みの名前空間を選択します。

配置ポリシーが PickAllに設定されている場合、 ClusterResourcePlacementScheduled または ResourcePlacementScheduled 条件は常に Trueに設定されます。

ケース スタディ: ClusterResourcePlacement

次の例では、ClusterResourcePlacement配置ポリシーを持つPickNが、env:prodというラベルの付いた 2 つのクラスターにリソースを伝達しようとしています。 (同じスケジューリング ロジックが ResourcePlacementに適用されます)。 kind-cluster-1kind-cluster-2という名前の 2 つのクラスターがフリートに参加しました。 ただし、kind-cluster-1というメンバー クラスターのみがenv:prodのラベルを持っています。

ClusterResourcePlacement の仕様

spec:
  policy:
    affinity:
      clusterAffinity:
        requiredDuringSchedulingIgnoredDuringExecution:
          clusterSelectorTerms:
          - labelSelector:
              matchLabels:
                env: prod
    numberOfClusters: 2
    placementType: PickN
  resourceSelectors:
  ...
  revisionHistoryLimit: 10
  strategy:
    type: RollingUpdate

ClusterResourcePlacement の状態

status:
  conditions:
  - lastTransitionTime: "2024-05-07T22:36:33Z"
    message: could not find all the clusters needed as specified by the scheduling
      policy
    observedGeneration: 1
    reason: SchedulingPolicyUnfulfilled
    status: "False"
    type: ClusterResourcePlacementScheduled
  - lastTransitionTime: "2024-05-07T22:36:33Z"
    message: All 1 cluster(s) start rolling out the latest resource
    observedGeneration: 1
    reason: RolloutStarted
    status: "True"
    type: ClusterResourcePlacementRolloutStarted
  - lastTransitionTime: "2024-05-07T22:36:33Z"
    message: No override rules are configured for the selected resources
    observedGeneration: 1
    reason: NoOverrideSpecified
    status: "True"
    type: ClusterResourcePlacementOverridden
  - lastTransitionTime: "2024-05-07T22:36:33Z"
    message: Works(s) are successfully created or updated in the 1 target clusters'
      namespaces
    observedGeneration: 1
    reason: WorkSynchronized
    status: "True"
    type: ClusterResourcePlacementWorkSynchronized
  - lastTransitionTime: "2024-05-07T22:36:33Z"
    message: The selected resources are successfully applied to 1 clusters
    observedGeneration: 1
    reason: ApplySucceeded
    status: "True"
    type: ClusterResourcePlacementApplied
  - lastTransitionTime: "2024-05-07T22:36:33Z"
    message: The selected resources in 1 cluster are available now
    observedGeneration: 1
    reason: ResourceAvailable
    status: "True"
    type: ClusterResourcePlacementAvailable
  observedResourceIndex: "0"
  placementStatuses:
  - clusterName: kind-cluster-1
    conditions:
    - lastTransitionTime: "2024-05-07T22:36:33Z"
      message: 'Successfully scheduled resources for placement in kind-cluster-1 (affinity
        score: 0, topology spread score: 0): picked by scheduling policy'
      observedGeneration: 1
      reason: Scheduled
      status: "True"
      type: Scheduled
    - lastTransitionTime: "2024-05-07T22:36:33Z"
      message: Detected the new changes on the resources and started the rollout process
      observedGeneration: 1
      reason: RolloutStarted
      status: "True"
      type: RolloutStarted
    - lastTransitionTime: "2024-05-07T22:36:33Z"
      message: No override rules are configured for the selected resources
      observedGeneration: 1
      reason: NoOverrideSpecified
      status: "True"
      type: Overridden
    - lastTransitionTime: "2024-05-07T22:36:33Z"
      message: All of the works are synchronized to the latest
      observedGeneration: 1
      reason: AllWorkSynced
      status: "True"
      type: WorkSynchronized
    - lastTransitionTime: "2024-05-07T22:36:33Z"
      message: All corresponding work objects are applied
      observedGeneration: 1
      reason: AllWorkHaveBeenApplied
      status: "True"
      type: Applied
    - lastTransitionTime: "2024-05-07T22:36:33Z"
      message: All corresponding work objects are available
      observedGeneration: 1
      reason: AllWorkAreAvailable
      status: "True"
      type: Available
  - conditions:
    - lastTransitionTime: "2024-05-07T22:36:33Z"
      message: 'kind-cluster-2 is not selected: ClusterUnschedulable, cluster does not
        match with any of the required cluster affinity terms'
      observedGeneration: 1
      reason: ScheduleFailed
      status: "False"
      type: Scheduled
  selectedResources:
  ...

ClusterResourcePlacement状態では、ClusterResourcePlacementScheduled条件の状態がFalseとして表示されます。 スケジューラが指定された配置ポリシーのリソースをスケジュールできない理由を把握するには、 ClusterSchedulingPolicySnapshot の仕様と状態を確認します。 最新のClusterSchedulingPolicySnapshotを取得する方法については、「ClusterResourcePlacement デプロイの最新の ClusterSchedulingPolicySnapshot を見つけて確認する方法」を参照してください。

最新のクラスタースケジューリングポリシースナップショット

apiVersion: placement.kubernetes-fleet.io/v1
kind: ClusterSchedulingPolicySnapshot
metadata:
  annotations:
    kubernetes-fleet.io/CRP-generation: "1"
    kubernetes-fleet.io/number-of-clusters: "2"
  creationTimestamp: "2024-05-07T22:36:33Z"
  generation: 1
  labels:
    kubernetes-fleet.io/is-latest-snapshot: "true"
    kubernetes-fleet.io/parent-CRP: crp-2
    kubernetes-fleet.io/policy-index: "0"
  name: crp-2-0
  ownerReferences:
  - apiVersion: placement.kubernetes-fleet.io/v1beta1
    blockOwnerDeletion: true
    controller: true
    kind: ClusterResourcePlacement
    name: crp-2
    uid: 48bc1e92-a8b9-4450-a2d5-c6905df2cbf0
  resourceVersion: "10090"
  uid: 2137887e-45fd-4f52-bbb7-b96f39854625
spec:
  policy:
    affinity:
      clusterAffinity:
        requiredDuringSchedulingIgnoredDuringExecution:
          clusterSelectorTerms:
          - labelSelector:
              matchLabels:
                env: prod
    placementType: PickN
  policyHash: ZjE0Yjk4YjYyMTVjY2U3NzQ1MTZkNWRhZjRiNjQ1NzQ4NjllNTUyMzZkODBkYzkyYmRkMGU3OTI3MWEwOTkyNQ==
status:
  conditions:
  - lastTransitionTime: "2024-05-07T22:36:33Z"
    message: could not find all the clusters needed as specified by the scheduling
      policy
    observedGeneration: 1
    reason: SchedulingPolicyUnfulfilled
    status: "False"
    type: Scheduled
  observedCRPGeneration: 1
  targetClusters:
  - clusterName: kind-cluster-1
    clusterScore:
      affinityScore: 0
      priorityScore: 0
    reason: picked by scheduling policy
    selected: true
  - clusterName: kind-cluster-2
    reason: ClusterUnschedulable, cluster does not match with any of the required
      cluster affinity terms
    selected: false

解決策

このシナリオでは、この問題を解決するには、リソースを伝達するクラスターをスケジューラが選択できるように、env:prodのメンバー クラスター リソースにも kind-cluster-2 ラベルを追加します。

一般的な注意事項

スケジュールエラー調査フローは、ClusterResourcePlacement と ResourcePlacement の場合と同じです。スナップショット オブジェクトの種類のみが異なります。 名前空間スコープの配置を使用する場合は、ClusterResourcePlacement (CRP) 固有のオブジェクトの種類を ResourcePlacement (RP) と同等のものに置き換えます。