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.

Enable ClusterProfile sync

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. We recommend that you don't run other workloads in the hub cluster.

Enable ClusterProfile sync on a cluster by adding the label fleet-clusterinventory-management-cluster=true. You can do the following:

After you 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 on a new cluster

To create a cluster for the hub cluster, and enable ClusterProfile sync, use the following command:

gcloud container clusters create CLUSTER --location LOCATION --enable-fleet
    --labels=fleet-clusterinventory-management-cluster=true

Replace the following:

  • CLUSTER: the name of your google_container_cluster resource.
  • LOCATION: the location where the cluster is created.

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

gcloud container clusters update CLUSTER --location LOCATION
    --update-labels=fleet-clusterinventory-namespace=NAMESPACE

Replace the following:

  • CLUSTER: the name of your google_container_cluster resource.
  • LOCATION: the location where the cluster is created.
  • NAMESPACE: the namespace where the cluster profiles are generated. If not specified, the cluster profiles are generated in the fleet-cluster-inventory namespace.

Enable ClusterProfile sync on an existing cluster

To enable ClusterProfile sync on an existing cluster, use the following command:

gcloud container clusters update CLUSTER --location LOCATION
    --update-labels=fleet-clusterinventory-management-cluster=true

Replace the following:

  • CLUSTER: the name of your google_container_cluster resource.
  • LOCATION: the location where the cluster is created.

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

gcloud container clusters update CLUSTER --location LOCATION
    --update-labels=fleet-clusterinventory-namespace=NAMESPACE

Replace the following:

  • CLUSTER: the name of your google_container_cluster resource.
  • LOCATION: the location where the cluster is created.
  • 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 includes the fleet-clusterinventory-management-cluster = true label. To do so, use the following command:

gcloud container clusters describe CLUSTER --location LOCATION

Replace the following::

  • CLUSTER: the name of your google_container_cluster resource.
  • LOCATION: the location where the cluster is created.

The output should be similar to the following:

resourceLabels:
  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 clusters get-credentials CLUSTER --location LOCATION

kubectl get clusterprofiles -n fleet-cluster-inventory

Replace the following:

  • CLUSTER: the name of your google_container_cluster resource.
  • LOCATION: the location where the cluster is created.

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 CLUSTER-LOCATION -n fleet-cluster-inventory -o yaml

Replace the following:

  • CLUSTER: the name of your google_container_cluster resource.
  • LOCATION: the location where the cluster is created.

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 label:

gcloud container clusters update CLUSTER --location LOCATION \
    --remove-labels=fleet-clusterinventory-management-cluster

Replace the following:

  • CLUSTER: the name of your google_container_cluster resource.
  • LOCATION: the location where the cluster is created.

What's next