Getting started with Config Connector

This guide shows the basics of Config Connector resource management by managing a Cloud Spanner instance.

Installing Config Connector

To complete the steps on this page, first install Config Connector on your cluster.

Enable the Cloud Spanner Service

Before using Cloud Spanner, the service must be enabled for your project. To enable it for your project run the following command:

gcloud services enable spanner.googleapis.com

Organizing resources

Config Connector uses Kubernetes Namespaces to organize resources. To learn more, see Kubernetes Namespaces and Google Cloud projects.

To get started, you need a Namespace mapped to your Google Cloud project. To create this Namespace, run the following command, replacing [PROJECT_ID] with your Google Cloud project ID:

kubectl create namespace [PROJECT_ID]

Discovering available Google Cloud resources

To view available Google Cloud resources in 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 manage.

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

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

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:
  labels:
    label-one: "value-one"
  name: spannerinstance-sample
spec:
  config: regional-us-west1
  displayName: Spanner Instance Sample
  numNodes: 1

When you create a Config Connector resource, an associated Google Cloud resource is created. Config Connector manages this resource. 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, replacing [PROJECT_ID] with your project ID:

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

Describing a resource

Use kubectl describe to get details on a resource.

For example, to view the Cloud Spanner instance, run the following command, replacing [PROJECT_ID] with your project ID:

kubectl --namespace [PROJECT_ID] 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:
      labels:
        label-one: "value-one"
      name: spannerinstance-sample
    spec:
      config: regional-us-west1
      displayName: My Spanner Instance
      numNodes: 1
    
  2. Use kubectl apply to update the resource. Run the following command, replacing [PROJECT_ID] with your project ID:

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

    kubectl --namespace [PROJECT_ID] 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 theSpannerInstance, run the following command, replacing [PROJECT_ID] with your project ID:

kubectl --namespace [PROJECT_ID] delete -f spanner-instance.yaml

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