Bagikan melalui


Mulai cepat: Menyebarkan sumber daya dari kluster hub Azure Kubernetes Fleet Manager (Armada) ke kluster anggota

Dalam mulai cepat ini, Anda mempelajari cara menyebarluaskan sumber daya dari kluster hub Azure Kubernetes Fleet Manager (Fleet) ke kluster anggota.

Prasyarat

Jika Anda tidak memiliki Langganan Azure, buat Akun gratis Azure sebelum memulai.

Gunakan API untuk menyebarkan ClusterResourcePlacement sumber daya ke kluster anggota

Objek ClusterResourcePlacement API digunakan untuk menyebarkan sumber daya dari kluster hub ke kluster anggota. Objek ClusterResourcePlacement API menentukan sumber daya yang akan disebarluaskan dan kebijakan penempatan yang akan digunakan saat memilih kluster anggota. Objek ClusterResourcePlacement API dibuat di kluster hub dan digunakan untuk menyebarkan sumber daya ke kluster anggota. Contoh ini menunjukkan cara menyebarluaskan namespace layanan ke kluster anggota menggunakan ClusterResourcePlacement objek API dengan PickAll kebijakan penempatan.

Untuk informasi selengkapnya, lihat Penyebaran sumber daya Kubernetes dari kluster hub ke kluster anggota (Pratinjau) dan dokumentasi Armada hulu.

  1. Buat namespace untuk ditempatkan ke kluster anggota menggunakan kubectl create namespace perintah . Contoh berikut membuat namespace bernama my-namespace:

    kubectl create namespace my-namespace
    
  2. Buat ClusterResourcePlacement objek API di kluster hub untuk menyebarluaskan namespace layanan ke kluster anggota dan menyebarkannya menggunakan kubectl apply -f perintah . Contoh ClusterResourcePlacement berikut membuat objek bernama crp dan menggunakan my-namespace namespace layanan dengan PickAll kebijakan penempatan untuk menyebarluaskan namespace layanan ke semua kluster anggota:

    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. Periksa kemajuan penyebaran sumber daya menggunakan kubectl get clusterresourceplacement perintah . Contoh berikut memeriksa status ClusterResourcePlacement objek bernama crp:

    kubectl get clusterresourceplacement crp
    

    Output Anda akan terlihat mirip dengan contoh output berikut:

    NAME   GEN   SCHEDULED   SCHEDULEDGEN   APPLIED   APPLIEDGEN   AGE
    crp    2     True        2              True      2            10s
    
  4. Lihat detail crp objek menggunakan kubectl describe crp perintah . Contoh berikut menjelaskan ClusterResourcePlacement objek bernama crp:

    kubectl describe clusterresourceplacement crp
    

    Output Anda akan terlihat mirip dengan contoh output berikut:

    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
    

Membersihkan sumber daya

Jika Anda tidak lagi ingin menggunakan ClusterResourcePlacement objek, Anda dapat menghapusnya menggunakan kubectl delete perintah . Contoh berikut menghapus ClusterResourcePlacement objek bernama crp:

kubectl delete clusterresourceplacement crp

Langkah berikutnya

Untuk mempelajari selengkapnya tentang penyebaran sumber daya, lihat sumber daya berikut ini: