Getting started with Config Connector

This guide shows the basics of Config Connector resource management by teaching you how to:

  • Enable a Google Cloud API
  • Create and manage a Cloud Spanner instance

Before you begin

To complete the steps on this page:

  • Install Config Connector.

  • Configure Config Connector to use a default project.

  • Config Connector uses the Resource Manager API to enable service APIs. To perform these steps, you need to enable the Resource Manager API. You can enable this API with the following `gcloud` command.
    gcloud services enable cloudresourcemanager.googleapis.com

Discovering available Google Cloud resources

To see what kinds of Google Cloud resources you can create with Config Connector, run:

kubectl get crds --selector cnrm.cloud.google.com/managed-by-kcc=true

The output is a list of all the resources your version of Config Connector can create and manage.

For example, you can view the API description for the SpannerInstance resource with kubectl describe:

kubectl describe crd spannerinstances.spanner.cnrm.cloud.google.com

Enable the Cloud Spanner Service

You can use Config Connector to enable the Cloud Spanner API by applying a YAML configuration to your cluster.

  1. Copy the following YAML into a file named enable-spanner.yaml.

    apiVersion: serviceusage.cnrm.cloud.google.com/v1beta1
    kind: Service
    metadata:
      name: spanner.googleapis.com
    
  2. Use kubectl apply to apply the configuration to your cluster. To enable the Cloud Spanner API, run the following command:

    kubectl --namespace [CC_NAMESPACE] apply -f enable-spanner.yaml

    Replace [CC_NAMESPACE] with the namespace Config Connector manages resources from.

Creating a Cloud Spanner instance

Create a file named spanner-instance.yaml with the following contents:

apiVersion: spanner.cnrm.cloud.google.com/v1beta1
kind: SpannerInstance
metadata:
  annotations:
    cnrm.cloud.google.com/project-id: [PROJECT_ID]
  labels:
    label-one: "value-one"
  name: spannerinstance-sample
spec:
  config: regional-us-west1
  displayName: Spanner Instance Sample
  numNodes: 1

Replace [PROJECT_ID] with your project ID.

When you create a resource, Config Connector creates the resource if it doesn't already exist. If a Google Cloud resource already exists with the same name, then Config Connector acquires the resource and manages it. To learn more about acquiring an existing resource, see Managing and deleting resources.

Use the kubectl apply command to create resources. To create the Cloud Spanner instance, copy the following command:

kubectl apply -f spanner-instance.yaml --namespace [CC_NAMESPACE]

Replace [CC_NAMESPACE] with your Config Connector namespace.

Describing a resource

Use kubectl describe to get details on a resource.

For example, to view the Cloud Spanner instance, run the following command:

kubectl describe spannerinstance spannerinstance-sample

Updating a resource

You can update metadata on your resources by updating your YAML file and re-applying it with kubectl. To update the metadata on the spanner instance you created earlier:

  1. Modify the spanner-instance.yaml file to change spec.displayName from "Spanner Instance Sample" to "My Spanner Instance".

    apiVersion: spanner.cnrm.cloud.google.com/v1beta1
    kind: SpannerInstance
    metadata:
      annotations:
        cnrm.cloud.google.com/project-id: [PROJECT_ID]
      labels:
        label-one: "value-one"
      name: spannerinstance-sample
    spec:
      config: regional-us-west1
      displayName: My Spanner Instance
      numNodes: 1
    

    Replace [PROJECT_ID] with your project ID.

  2. Use kubectl apply to update the resource. Run the following command:

    kubectl apply -f spanner-instance.yaml
  3. Check the Cloud Spanner instance for the change in name.

    kubectl describe spannerinstance spannerinstance-sample

    The description should include the new name, My Spanner Instance.

Deleting a resource

Use kubectl delete to delete resources. For example, to delete the SpannerInstance you created earlier, run kubectl delete with your spanner-instance.yaml file:

kubectl delete -f spanner-instance.yaml

You receive confirmation that the resource was deleted.

spannerinstance.spanner.cnrm.cloud.google.com "spannerinstance-sample" deleted

By default, Config Connector deletes the SpannerInstance resource. If you prefer to keep this resource, see the instructions in Managing and deleting resources.

What's next