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

Create a file named spanner-instance.yaml 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 Google Cloud resource is created. Config Connector manages this resource. However, if a Google Cloud 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

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

To update the characteristics of a resource, perform the following steps.

  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/v1alpha2
    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

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

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

What's next

Оцените, насколько информация на этой странице была вам полезна:

Оставить отзыв о...

Текущей странице
Config Connector Documentation