Getting started with Config Connector

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

Before you begin

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 GCP projects.

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

kubectl create namespace [PROJECT_ID]

Discovering available resource kinds

To view available resources in Config Connector, run:

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

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

Create spanner-instance.yaml

Many of the example tasks use a file named spanner-instance.yaml. Create a file with this name with the following contents:

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

Creating a resource

When you create a Config Connector resource, an associated GCP resource is created. Config Connector manages this resource. However, if a GCP resource already exists with the same name, then Config Connector acquires the resource and manages it.

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

To view a resource, use kubectl describe.

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

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

  2. To update the resource, use kubectl apply. Update the SpannerInstance with apply, 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

Deleting a resource

...
metadata:
  annotations:
    cnrm.cloud.google.com/deletion-policy: abandon
...

For example, the YAML for the Cloud Spanner instance including the abandon deletion policy is below:

apiVersion: spanner.cnrm.cloud.google.com/v1alpha2
kind: SpannerInstance
metadata:
  labels:
    label-one: "value-one"
  annotations:
    cnrm.cloud.google.com/deletion-policy: abandon
  name: spannerinstance-sample
spec:
  config: regional-us-central1
  displayName: Spanner Two
  numNodes: 1

To delete resources, use kubectl delete. Delete the SpannerInstance, replacing [PROJECT_ID] with your project ID:

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

What's next

¿Te ha resultado útil esta página? Enviar comentarios:

Enviar comentarios sobre...

Config Connector Documentation