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

概要

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

  • ClusterResourcePlacementWorkSynchronized ClusterResourcePlacement の場合
  • ResourcePlacementWorkSynchronized ResourcePlacement の場合

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

  - lastTransitionTime: "2024-05-07T23:32:40Z"
    message: Failed to synchronize work(s) for 1 clusters, please check the `failedPlacements` status
    observedGeneration: 1
    reason: WorkNeedSyncedOrUpdated
    status: "False"
    type: ClusterResourcePlacementWorkSynchronized

症状

Azure Kubernetes Fleet Manager で ClusterResourcePlacement または ResourcePlacement API オブジェクトを使用してリソースを伝達する場合、配置が最近更新された場合、関連付けられている作業オブジェクトは最新の選択されたリソースと同期されず、 ClusterResourcePlacementWorkSynchronized (ClusterResourcePlacement の場合) または ResourcePlacementWorkSynchronized (ResourcePlacement の場合) の状態は Falseとして表示されます。

作業オブジェクトの同期が失敗する理由の詳細については、作業ジェネレーター コントローラーのログを確認します。 フリート エージェント ログの表示の詳細については、「 Azure Kubernetes Fleet Manager でのエージェント ログの表示」を参照してください。

原因

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

  • コントローラーで、対応する作業オブジェクトの生成中にエラーが発生します。
  • エンベロープされたオブジェクトの書式が適切に設定されていません。

ケース スタディ: ClusterResourcePlacement

次の例では、 ClusterResourcePlacement は選択したクラスターにリソースを伝達しようとしていますが、選択したクラスターが終了したため、作業オブジェクトは最新の変更を反映するように更新されません。

ClusterResourcePlacement の仕様

spec:
  resourceSelectors:
    - group: rbac.authorization.k8s.io
      kind: ClusterRole
      name: secret-reader
      version: v1
  policy:
    placementType: PickN
    numberOfClusters: 1
  strategy:
    type: RollingUpdate

ClusterResourcePlacement の状態

spec:
  policy:
    numberOfClusters: 1
    placementType: PickN
  resourceSelectors:
  - group: ""
    kind: Namespace
    name: test-ns
    version: v1
  revisionHistoryLimit: 10
  strategy:
    type: RollingUpdate
status:
  conditions:
  - lastTransitionTime: "2024-05-14T18:05:04Z"
    message: found all cluster needed as specified by the scheduling policy, found
      1 cluster(s)
    observedGeneration: 1
    reason: SchedulingPolicyFulfilled
    status: "True"
    type: ClusterResourcePlacementScheduled
  - lastTransitionTime: "2024-05-14T18:05:05Z"
    message: All 1 cluster(s) start rolling out the latest resource
    observedGeneration: 1
    reason: RolloutStarted
    status: "True"
    type: ClusterResourcePlacementRolloutStarted
  - lastTransitionTime: "2024-05-14T18:05:05Z"
    message: No override rules are configured for the selected resources
    observedGeneration: 1
    reason: NoOverrideSpecified
    status: "True"
    type: ClusterResourcePlacementOverridden
  - lastTransitionTime: "2024-05-14T18:05:05Z"
    message: There are 1 cluster(s) which didn't finish creating or updating work(s)
      yet
    observedGeneration: 1
    reason: WorkNotSynchronizedYet
    status: "False"
    type: ClusterResourcePlacementWorkSynchronized
  observedResourceIndex: "0"
  placementStatuses:
  - clusterName: kind-cluster-1
    conditions:
    - lastTransitionTime: "2024-05-14T18:05:04Z"
      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-14T18:05:05Z"
      message: Detected the new changes on the resources and started the rollout process
      observedGeneration: 1
      reason: RolloutStarted
      status: "True"
      type: RolloutStarted
    - lastTransitionTime: "2024-05-14T18:05:05Z"
      message: No override rules are configured for the selected resources
      observedGeneration: 1
      reason: NoOverrideSpecified
      status: "True"
      type: Overridden
    - lastTransitionTime: "2024-05-14T18:05:05Z"
      message: 'Failed to synchronize the work to the latest: works.placement.kubernetes-fleet.io
        "crp1-work" is forbidden: unable to create new content in namespace fleet-member-kind-cluster-1
        because it is terminating'
      observedGeneration: 1
      reason: SyncWorkFailed
      status: "False"
      type: WorkSynchronized
  selectedResources:
  - kind: Namespace
    name: test-ns
    version: v1

ClusterResourcePlacement状態では、ClusterResourcePlacementWorkSynchronized条件の状態がFalseとして表示されます。 このメッセージは、 crp1-work 作業オブジェクトが現在終了しているため、名前空間 fleet-member-kind-cluster-1 内で新しいコンテンツを生成することは禁止されていることを示します。

解決策

このような状況では、いくつかの潜在的な解決策を次に示します。

  • 新しく選択したクラスターで ClusterResourcePlacement を変更します。
  • ガベージ コレクションを使用して作業を削除するには、 ClusterResourcePlacement を削除します。
  • メンバー クラスターに再度参加します。 名前空間は、クラスターに再参加した後にのみ再生成できます。

その他の状況では、作業の反映が完了するまで待機することを選択できます。

一般的な注意事項

ResourcePlacement の場合、調査は同じです。.status.placementStatuses[*].conditionsWorkSynchronizedを調べ、fleet-member-{clusterName}名前空間内の関連する Work を確認します。