Guia de início rápido: propagar recursos de um cluster de hub do Azure Kubernetes Fleet Manager (Fleet) para clusters membros

Neste guia de início rápido, você aprenderá a propagar recursos de um cluster de hub do Azure Kubernetes Fleet Manager (Fleet) para clusters membros.

Pré-requisitos

Se não tiver uma subscrição do Azure, crie uma conta gratuita do Azure antes de começar.

Usar a ClusterResourcePlacement API para propagar recursos para clusters membros

O ClusterResourcePlacement objeto API é usado para propagar recursos de um cluster de hub para clusters membros. O ClusterResourcePlacement objeto API especifica os recursos a serem propagados e a política de posicionamento a ser usada ao selecionar clusters membros. O ClusterResourcePlacement objeto API é criado no cluster de hub e é usado para propagar recursos para clusters membros. Este exemplo demonstra como propagar um namespace para clusters membros usando o ClusterResourcePlacement objeto API com uma PickAll política de posicionamento.

Para obter mais informações, consulte Propagação de recursos do Kubernetes do cluster de hub para clusters membros (Visualização) e a documentação upstream do Fleet.

  1. Crie um namespace para colocar nos clusters de membros usando o kubectl create namespace comando. O exemplo a seguir cria um namespace chamado my-namespace:

    kubectl create namespace my-namespace
    
  2. Crie um ClusterResourcePlacement objeto de API no cluster de hub para propagar o namespace para os clusters membros e implantá-lo usando o kubectl apply -f comando. O exemplo ClusterResourcePlacement a seguir cria um objeto chamado crp e usa o my-namespace namespace com uma PickAll política de posicionamento para propagar o namespace para todos os clusters membros:

    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. Verifique o progresso da propagação do recurso usando o kubectl get clusterresourceplacement comando. O exemplo a seguir verifica o status do ClusterResourcePlacement objeto chamado crp:

    kubectl get clusterresourceplacement crp
    

    Sua saída deve ser semelhante à saída de exemplo a seguir:

    NAME   GEN   SCHEDULED   SCHEDULEDGEN   APPLIED   APPLIEDGEN   AGE
    crp    2     True        2              True      2            10s
    
  4. Exiba os detalhes do crp objeto usando o kubectl describe crp comando. O exemplo a seguir descreve o ClusterResourcePlacement objeto chamado crp:

    kubectl describe clusterresourceplacement crp
    

    Sua saída deve ser semelhante à saída de exemplo a seguir:

    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
    

Clean up resources (Limpar recursos)

Se você não quiser mais usar o ClusterResourcePlacement objeto, você pode excluí-lo usando o kubectl delete comando. O exemplo a seguir exclui o ClusterResourcePlacement objeto chamado crp:

kubectl delete clusterresourceplacement crp

Próximos passos

Para saber mais sobre a propagação de recursos, consulte os seguintes recursos: