Generate inventory for third-party integrations

This page describes how to generate a cluster inventory for an existing fleet. A cluster inventory for a fleet lets you work with open source and third party integrations that use the ClusterProfile specification.

A cluster inventory is the open-source equivalent of a fleet: a logical grouping of Kubernetes clusters and other resources that can be managed together. The ClusterProfile specification contains information that is a subset of the information in a fleet.

ClusterProfile sync feature is a one-way sync between a fleet and a cluster inventory. When ClusterProfile sync is enabled, the fleet is the source of truth, and any changes to the fleet are automatically applied to the cluster inventory by ClusterProfile sync. Changes made directly to the cluster profile resources are not applied to the fleet.

Before you begin

  1. Ensure that you have followed the general prerequisites for working with fleets.

  2. Create a fleet or identify an existing fleet to work with.

  3. Grant the required Identity and Access Management role (roles/gkehub.editor) to the user running the commands on this page. This role is needed to update the fleet membership.

Identify a hub cluster

ClusterProfile sync runs against one cluster within the fleet. This cluster is called a hub cluster and can be used to run multi-cluster controllers that need information about the rest of the clusters in the fleet. Examples of multi-cluster controllers include Argo CD controllers, and multi-cluster orchestrator.

Identify a cluster in the fleet to use as the hub cluster.

Enable ClusterProfile sync

After you the enable the ClusterProfile sync feature for a fleet, it automatically creates a cluster profile for each cluster in the fleet using the ClusterProfile API. These cluster profiles are automatically created, updated, and deleted when changes are made to the fleet.

Enable ClusterProfile sync by labeling the fleet membership of the hub cluster with fleet-clusterinventory-management-cluster = true. To do so, use the following command:

gcloud container fleet memberships update MEMBERSHIP --location LOCATION
    --update-labels=fleet-clusterinventory-management-cluster=true

Replace the following:

  • MEMBERSHIP: the cluster membership name.
  • LOCATION: the location where the hub cluster is registered.

By default, cluster profiles are created in the fleet-cluster-inventory namespace. To change the namespace, specify the fleet-clusterinventory-namespace label.

gcloud container fleet memberships update MEMBERSHIP --location LOCATION
    --update-labels=fleet-clusterinventory-namespace=NAMESPACE

Replace the following:

  • MEMBERSHIP: the cluster membership name.
  • LOCATION: the location where the cluster profiles are generated.
  • NAMESPACE: the namespace where the cluster profiles are generated. If not specified, the cluster profiles are generated in the fleet-cluster-inventory namespace.

Verify the ClusterProfile sync is enabled

Verify that ClusterProfile sync is enabled by verifying that the hub cluster membership includes the fleet-clusterinventory-management-cluster = true label. To do so, use the following command:

gcloud container fleet memberships describe MEMBERSHIP --location LOCATION

Replace the following::

  • MEMBERSHIP: the cluster membership name.
  • LOCATION: the location where the cluster is registered.

The output should be similar to the following:

labels:
  fleet-clusterinventory-management-cluster: 'true'

Verify the generated cluster profile resources

Verify that the cluster profile resources are generated in the hub cluster by using the following command:

gcloud container fleet memberships get-credentials MEMBERSHIP --location LOCATION

kubectl get clusterprofiles -n fleet-cluster-inventory

Replace the following:

  • MEMBERSHIP: the cluster membership name.
  • LOCATION: the location where the cluster is registered.

The output should be similar to:

NAME                           AGE
cluster-1-us-west1             10s
cluster-2-us-west1             20s

This output should include a cluster profile for each cluster in the fleet. The cluster profile name has the format MEMBERSHIP-LOCATION.

View the contents of the cluster profile

To view the contents of the cluster profile for a specific cluster, use the following command:

kubectl get clusterprofile MEMBERSHIP-LOCATION -n fleet-cluster-inventory -o yaml

Replace the following:

  • MEMBERSHIP: the cluster membership name.
  • LOCATION: the location where the cluster is registered.

The output should be similar to:

apiVersion: multicluster.x-k8s.io/v1alpha1
kind: ClusterProfile
metadata:
  annotations:
    fleet.gke.io/membershipName: projects/123456789/locations/us-west1/memberships/cluster-1
  labels:
    x-k8s.io/cluster-manager: gke-fleet
  name: cluster-1-us-west1
  namespace: fleet-cluster-inventory

Disable ClusterProfile Sync

Disable ClusterProfile sync on the fleet's hub cluster by removing the fleet-clusterinventory-management-cluster fleet membership label:

gcloud container fleet memberships update MEMBERSHIP --location LOCATION \
    --remove-labels=fleet-clusterinventory-management-cluster

Replace the following:

  • MEMBERSHIP: the cluster membership name.
  • LOCATION: the location where the cluster is registered.

What's next