Поделиться через


Краткое руководство. Распространение ресурсов из концентратора Azure Kubernetes Fleet Manager (Fleet) в кластеры-члены

Из этого краткого руководства вы узнаете, как распространять ресурсы из кластера концентратора Azure Kubernetes Fleet Manager (Fleet) на кластеры-члены.

Необходимые компоненты

Если у вас еще нет подписки Azure, создайте бесплатную учетную запись Azure, прежде чем начинать работу.

ClusterResourcePlacement Использование API для распространения ресурсов в кластеры-члены

Объект ClusterResourcePlacement API используется для распространения ресурсов из концентратора в кластеры-члены. Объект ClusterResourcePlacement API указывает ресурсы для распространения и политики размещения, используемой при выборе кластеров-членов. ClusterResourcePlacement Объект API создается в кластере концентратора и используется для распространения ресурсов в кластеры-члены. В этом примере показано, как распространить пространство имен на кластеры-члены с помощью ClusterResourcePlacement объекта API с политикой PickAll размещения.

Дополнительные сведения см. в статье о распространении ресурсов Kubernetes из концентратора в кластеры-члены (предварительная версия) и документации по вышестоящий Fleet.

  1. Создайте пространство имен для размещения в кластерах-членах с помощью kubectl create namespace команды. В следующем примере создается пространство имен с именем my-namespace:

    kubectl create namespace my-namespace
    
  2. ClusterResourcePlacement Создайте объект API в кластере концентратора, чтобы распространить пространство имен в кластеры-члены и развернуть его с помощью kubectl apply -f команды. В следующем примере ClusterResourcePlacement создается объект с именем crp и используется my-namespace пространство имен с PickAll политикой размещения для распространения пространства имен ко всем кластерам членов:

    kubectl apply -f - <<EOF
    apiVersion: placement.kubernetes-fleet.io/v1beta1
    kind: ClusterResourcePlacement
    metadata:
      name: crp
    spec:
      resourceSelectors:
        - group: ""
          kind: Namespace
          version: v1          
          name: my-namespace
      policy:
        placementType: PickAll
    EOF
    
  3. Проверьте ход распространения ресурсов с помощью kubectl get clusterresourceplacement команды. В следующем примере проверка состояние ClusterResourcePlacement объекта с именемcrp:

    kubectl get clusterresourceplacement crp
    

    Выходные данные должны выглядеть примерно так:

    NAME   GEN   SCHEDULED   SCHEDULEDGEN   APPLIED   APPLIEDGEN   AGE
    crp    2     True        2              True      2            10s
    
  4. Просмотрите сведения об crp объекте kubectl describe crp с помощью команды. В следующем примере описывается ClusterResourcePlacement объект с именем crp:

    kubectl describe clusterresourceplacement crp
    

    Выходные данные должны выглядеть примерно так:

    Name:         crp
    Namespace:    
    Labels:       <none>
    Annotations:  <none>
    API Version:  placement.kubernetes-fleet.io/v1beta1
    Kind:         ClusterResourcePlacement
    Metadata:
      Creation Timestamp:  2024-04-01T18:55:31Z
      Finalizers:
        kubernetes-fleet.io/crp-cleanup
        kubernetes-fleet.io/scheduler-cleanup
      Generation:        2
      Resource Version:  6949
      UID:               815b1d81-61ae-4fb1-a2b1-06794be3f986
    Spec:
      Policy:
        Placement Type:  PickAll
      Resource Selectors:
        Group:                 
        Kind:                  Namespace
        Name:                  my-namespace
        Version:               v1
      Revision History Limit:  10
      Strategy:
        Type:  RollingUpdate
    Status:
      Conditions:
        Last Transition Time:   2024-04-01T18:55:31Z
        Message:                found all the clusters needed as specified by the scheduling policy
        Observed Generation:    2
        Reason:                 SchedulingPolicyFulfilled
        Status:                 True
        Type:                   ClusterResourcePlacementScheduled
        Last Transition Time:   2024-04-01T18:55:36Z
        Message:                All 3 cluster(s) are synchronized to the latest resources on the hub cluster
        Observed Generation:    2
        Reason:                 SynchronizeSucceeded
        Status:                 True
        Type:                   ClusterResourcePlacementSynchronized
        Last Transition Time:   2024-04-01T18:55:36Z
        Message:                Successfully applied resources to 3 member clusters
        Observed Generation:    2
        Reason:                 ApplySucceeded
        Status:                 True
        Type:                   ClusterResourcePlacementApplied
      Observed Resource Index:  0
      Placement Statuses:
        Cluster Name:  membercluster1
        Conditions:
          Last Transition Time:  2024-04-01T18:55:31Z
          Message:               Successfully scheduled resources for placement in membercluster1 (affinity score: 0, topology spread score: 0): picked by scheduling policy
          Observed Generation:   2
          Reason:                ScheduleSucceeded
          Status:                True
          Type:                  ResourceScheduled
          Last Transition Time:  2024-04-01T18:55:36Z
          Message:               Successfully Synchronized work(s) for placement
          Observed Generation:   2
          Reason:                WorkSynchronizeSucceeded
          Status:                True
          Type:                  WorkSynchronized
          Last Transition Time:  2024-04-01T18:55:36Z
          Message:               Successfully applied resources
          Observed Generation:   2
          Reason:                ApplySucceeded
          Status:                True
          Type:                  ResourceApplied
        Cluster Name:            membercluster2
        Conditions:
          Last Transition Time:  2024-04-01T18:55:31Z
          Message:               Successfully scheduled resources for placement in membercluster2 (affinity score: 0, topology spread score: 0): picked by scheduling policy
          Observed Generation:   2
          Reason:                ScheduleSucceeded
          Status:                True
          Type:                  ResourceScheduled
          Last Transition Time:  2024-04-01T18:55:36Z
          Message:               Successfully Synchronized work(s) for placement
          Observed Generation:   2
          Reason:                WorkSynchronizeSucceeded
          Status:                True
          Type:                  WorkSynchronized
          Last Transition Time:  2024-04-01T18:55:36Z
          Message:               Successfully applied resources
          Observed Generation:   2
          Reason:                ApplySucceeded
          Status:                True
          Type:                  ResourceApplied
        Cluster Name:            membercluster3
        Conditions:
          Last Transition Time:  2024-04-01T18:55:31Z
          Message:               Successfully scheduled resources for placement in membercluster3 (affinity score: 0, topology spread score: 0): picked by scheduling policy
          Observed Generation:   2
          Reason:                ScheduleSucceeded
          Status:                True
          Type:                  ResourceScheduled
          Last Transition Time:  2024-04-01T18:55:36Z
          Message:               Successfully Synchronized work(s) for placement
          Observed Generation:   2
          Reason:                WorkSynchronizeSucceeded
          Status:                True
          Type:                  WorkSynchronized
          Last Transition Time:  2024-04-01T18:55:36Z
          Message:               Successfully applied resources
          Observed Generation:   2
          Reason:                ApplySucceeded
          Status:                True
          Type:                  ResourceApplied
      Selected Resources:
        Kind:     Namespace
        Name:     my-namespace
        Version:  v1
    Events:
      Type    Reason                     Age   From                                   Message
      ----    ------                     ----  ----                                   -------
      Normal  PlacementScheduleSuccess   108s  cluster-resource-placement-controller  Successfully scheduled the placement
      Normal  PlacementSyncSuccess       103s  cluster-resource-placement-controller  Successfully synchronized the placement
      Normal  PlacementRolloutCompleted  103s  cluster-resource-placement-controller  Resources have been applied to the selected clusters
    

Очистка ресурсов

Если вы больше не хотите использовать ClusterResourcePlacement объект, его можно удалить с помощью kubectl delete команды. В следующем примере удаляется ClusterResourcePlacement объект с именем crp:

kubectl delete clusterresourceplacement crp

Следующие шаги

Дополнительные сведения о распространении ресурсов см. в следующих ресурсах: