Orchestrate CockroachDB in a Single Kubernetes Cluster (Insecure)

2020-02-16

This page shows you how to orchestrate the deployment, management, and monitoring of an insecure 3-node CockroachDB cluster in a single Kubernetes cluster, using the StatefulSet feature directly or via the Helm Kubernetes package manager.

To deploy across multiple Kubernetes clusters in different geographic regions instead, see Kubernetes Multi-Cluster Deployment. Also, for details about potential performance bottlenecks to be aware of when running CockroachDB in Kubernetes and guidance on how to optimize your deployment for better performance, see CockroachDB Performance on Kubernetes.

{{site.data.alerts.callout_danger}} If you plan to use CockroachDB in production, we strongly recommend using a secure cluster instead. Select Secure above for instructions. {{site.data.alerts.end}}

Before you begin

Before getting started, it's helpful to review some Kubernetes-specific terminology and current limitations.

Kubernetes terminology

Feature Description
instance A physical or virtual machine. In this tutorial, you'll create GCE or AWS instances and join them into a single Kubernetes cluster from your local workstation.
pod A pod is a group of one or more Docker containers. In this tutorial, each pod will run on a separate instance and include one Docker container running a single CockroachDB node. You'll start with 3 pods and grow to 4.
StatefulSet A StatefulSet is a group of pods treated as stateful units, where each pod has distinguishable network identity and always binds back to the same persistent storage on restart. StatefulSets are considered stable as of Kubernetes version 1.9 after reaching beta in version 1.5.
persistent volume A persistent volume is a piece of networked storage (Persistent Disk on GCE, Elastic Block Store on AWS) mounted into a pod. The lifetime of a persistent volume is decoupled from the lifetime of the pod that's using it, ensuring that each CockroachDB node binds back to the same storage on restart.

This tutorial assumes that dynamic volume provisioning is available. When that is not the case, persistent volume claims need to be created manually.

Limitations

Kubernetes version

Kubernetes 1.8 or higher is required in order to use our most up-to-date configuration files. Earlier Kubernetes releases do not support some of the options used in our configuration files. If you need to run on an older version of Kubernetes, we have kept around configuration files that work on older Kubernetes releases in the versioned subdirectories of https://github.com/cockroachdb/cockroach/tree/master/cloud/kubernetes (e.g., v1.7).

Storage

At this time, orchestrations of CockroachDB with Kubernetes use external persistent volumes that are often replicated by the provider. Because CockroachDB already replicates data automatically, this additional layer of replication is unnecessary and can negatively impact performance. High-performance use cases on a private Kubernetes cluster may want to consider a DaemonSet deployment until StatefulSets support node-local storage.

Step 1. Start Kubernetes

Choose whether you want to orchestrate CockroachDB with Kubernetes using the hosted Google Kubernetes Engine (GKE) service or manually on Google Compute Engine (GCE) or AWS. The instructions below will change slightly depending on your choice.

Hosted GKE

  1. Complete the Before You Begin steps described in the Google Kubernetes Engine Quickstart documentation.

    This includes installing gcloud, which is used to create and delete Kubernetes Engine clusters, and kubectl, which is the command-line tool used to manage Kubernetes from your workstation.

    {{site.data.alerts.callout_success}}The documentation offers the choice of using Google's Cloud Shell product or using a local shell on your machine. Choose to use a local shell if you want to be able to view the CockroachDB Admin UI using the steps in this guide.{{site.data.alerts.end}}

  2. From your local workstation, start the Kubernetes cluster:

    $ gcloud container clusters create cockroachdb --machine-type n1-standard-4
    
    Creating cluster cockroachdb...done.
    

    This creates GKE instances and joins them into a single Kubernetes cluster named cockroachdb. The --machine-type flag tells the node pool to use the n1-standard-4 machine type (4 vCPUs, 15 GB memory), which meets our recommended CPU and memory configuration.

    The process can take a few minutes, so do not move on to the next step until you see a Creating cluster cockroachdb...done message and details about your cluster.

  3. Get the email address associated with your Google Cloud account:

    $ gcloud info | grep Account
    
    Account: [your.google.cloud.email@example.org]
    

    {{site.data.alerts.callout_danger}} This command returns your email address in all lowercase. However, in the next step, you must enter the address using the accurate capitalization. For example, if your address is YourName@example.com, you must use YourName@example.com and not yourname@example.com. {{site.data.alerts.end}}

  4. Create the RBAC roles CockroachDB needs for running on GKE, using the address from the previous step:

    $ kubectl create clusterrolebinding $USER-cluster-admin-binding --clusterrole=cluster-admin --user=<your.google.cloud.email@example.org>
    
    clusterrolebinding "cluster-admin-binding" created
    

Manual GCE

From your local workstation, install prerequisites and start a Kubernetes cluster as described in the Running Kubernetes on Google Compute Engine documentation.

The process includes:

  • Creating a Google Cloud Platform account, installing gcloud, and other prerequisites.
  • Downloading and installing the latest Kubernetes release.
  • Creating GCE instances and joining them into a single Kubernetes cluster.
  • Installing kubectl, the command-line tool used to manage Kubernetes from your workstation.

Manual AWS

From your local workstation, install prerequisites and start a Kubernetes cluster as described in the Running Kubernetes on AWS EC2 documentation.

Step 2. Start CockroachDB

To start your CockroachDB cluster, you can either use our StatefulSet configuration and related files directly, or you can use the Helm package manager for Kubernetes to simplify the process.

{% include {{ page.version.version }}/orchestration/start-cockroachdb-insecure.md %}
{% include {{ page.version.version }}/orchestration/start-cockroachdb-helm-insecure.md %}

Step 3. Use the built-in SQL client

  1. Launch a temporary interactive pod and start the built-in SQL client inside it:

    {% include copy-clipboard.html %} ~~~ shell $ kubectl run cockroachdb -it --image=cockroachdb/cockroach --rm --restart=Never \ -- sql --insecure --host=cockroachdb-public ~~~
    {% include copy-clipboard.html %} ~~~ shell $ kubectl run cockroachdb -it --image=cockroachdb/cockroach --rm --restart=Never \ -- sql --insecure --host=my-release-cockroachdb-public ~~~
  2. Run some basic CockroachDB SQL statements:

    > CREATE DATABASE bank;
    

    > CREATE TABLE bank.accounts (
        id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
    	  balance DECIMAL
      );
    

    > INSERT INTO bank.accounts (balance)
      VALUES
    	  (1000.50), (20000), (380), (500), (55000);
    

    > SELECT * FROM bank.accounts;
    
                       id                  | balance
    +--------------------------------------+---------+
      6f123370-c48c-41ff-b384-2c185590af2b |     380
      990c9148-1ea0-4861-9da7-fd0e65b0a7da | 1000.50
      ac31c671-40bf-4a7b-8bee-452cff8a4026 |     500
      d58afd93-5be9-42ba-b2e2-dc00dcedf409 |   20000
      e6d8f696-87f5-4d3c-a377-8e152fdc27f7 |   55000
    (5 rows)
    
  3. Exit the SQL shell and delete the temporary pod:

    > \q
    

Step 4. Access the Admin UI

To access the cluster's Admin UI:

  1. Port-forward from your local machine to one of the pods:

    {% include copy-clipboard.html %} ~~~ shell $ kubectl port-forward cockroachdb-0 8080 ~~~
    {% include copy-clipboard.html %} ~~~ shell $ kubectl port-forward my-release-cockroachdb-0 8080 ~~~
    Forwarding from 127.0.0.1:8080 -> 8080
    

    {{site.data.alerts.callout_info}}The port-forward command must be run on the same machine as the web browser in which you want to view the Admin UI. If you have been running these commands from a cloud instance or other non-local shell, you will not be able to view the UI without configuring kubectl locally and running the above port-forward command on your local machine.{{site.data.alerts.end}}

  1. Go to https://localhost:8080 and log in with the username and password you created earlier.
  1. Go to http://localhost:8080.
  1. In the UI, verify that the cluster is running as expected:
    • Click View nodes list on the right to ensure that all nodes successfully joined the cluster.
    • Click the Databases tab on the left to verify that bank is listed.

Step 5. Simulate node failure

Based on the replicas: 3 line in the StatefulSet configuration, Kubernetes ensures that three pods/nodes are running at all times. When a pod/node fails, Kubernetes automatically creates another pod/node with the same network identity and persistent storage.

To see this in action:

  1. Kill one of CockroachDB nodes:

    {% include copy-clipboard.html %} ~~~ shell $ kubectl delete pod cockroachdb-2 ~~~ ~~~ pod "cockroachdb-2" deleted ~~~
    {% include copy-clipboard.html %} ~~~ shell $ kubectl delete pod my-release-cockroachdb-2 ~~~ ~~~ pod "my-release-cockroachdb-2" deleted ~~~
  2. In the Admin UI, the Cluster Overview will soon show one node as Suspect. As Kubernetes auto-restarts the node, watch how the node once again becomes healthy.

  3. Back in the terminal, verify that the pod was automatically restarted:

    {% include copy-clipboard.html %} ~~~ shell $ kubectl get pod cockroachdb-2 ~~~ ~~~ NAME READY STATUS RESTARTS AGE cockroachdb-2 1/1 Running 0 12s ~~~
    {% include copy-clipboard.html %} ~~~ shell $ kubectl get pod my-release-cockroachdb-2 ~~~ ~~~ NAME READY STATUS RESTARTS AGE my-release-cockroachdb-2 1/1 Running 0 44s ~~~

Step 6. Set up monitoring and alerting

Despite CockroachDB's various built-in safeguards against failure, it is critical to actively monitor the overall health and performance of a cluster running in production and to create alerting rules that promptly send notifications when there are events that require investigation or intervention.

Configure Prometheus

Every node of a CockroachDB cluster exports granular timeseries metrics formatted for easy integration with Prometheus, an open source tool for storing, aggregating, and querying timeseries data. This section shows you how to orchestrate Prometheus as part of your Kubernetes cluster and pull these metrics into Prometheus for external monitoring.

This guidance is based on CoreOS's Prometheus Operator, which allows a Prometheus instance to be managed using native Kubernetes concepts.

{{site.data.alerts.callout_info}} If you're on Hosted GKE, before starting, make sure the email address associated with your Google Cloud account is part of the cluster-admin RBAC group, as shown in Step 1. Start Kubernetes. {{site.data.alerts.end}}

  1. From your local workstation, edit the cockroachdb service to add the prometheus: cockroachdb label:

    {% include copy-clipboard.html %} ~~~ shell $ kubectl label svc cockroachdb prometheus=cockroachdb ~~~ ~~~ service "cockroachdb" labeled ~~~ This ensures that there is a prometheus job and monitoring data only for the `cockroachdb` service, not for the `cockroach-public` service.
    {% include copy-clipboard.html %} ~~~ shell $ kubectl label svc my-release-cockroachdb prometheus=cockroachdb ~~~ ~~~ service "cockroachdb" labeled ~~~ This ensures that there is a prometheus job and monitoring data only for the `my-release-cockroachdb` service, not for the `my-release-cockroach-public` service.
  2. Install CoreOS's Prometheus Operator:

    $ kubectl apply -f https://raw.githubusercontent.com/coreos/prometheus-operator/release-0.20/bundle.yaml
    
    clusterrolebinding "prometheus-operator" created
    clusterrole "prometheus-operator" created
    serviceaccount "prometheus-operator" created
    deployment "prometheus-operator" created
    
  3. Confirm that the prometheus-operator has started:

    $ kubectl get deploy prometheus-operator
    
    NAME                  DESIRED   CURRENT   UP-TO-DATE   AVAILABLE   AGE
    prometheus-operator   1         1         1            1           1m
    
  4. Use our prometheus.yaml file to create the various objects necessary to run a Prometheus instance:

    $ kubectl apply -f https://raw.githubusercontent.com/cockroachdb/cockroach/master/cloud/kubernetes/prometheus/prometheus.yaml
    
    clusterrole "prometheus" created
    clusterrolebinding "prometheus" created
    servicemonitor "cockroachdb" created
    prometheus "cockroachdb" created
    
  5. Access the Prometheus UI locally and verify that CockroachDB is feeding data into Prometheus:

    1. Port-forward from your local machine to the pod running Prometheus:

      $ kubectl port-forward prometheus-cockroachdb-0 9090
      
    2. Go to http://localhost:9090 in your browser.

    3. To verify that each CockroachDB node is connected to Prometheus, go to Status > Targets. The screen should look like this:

      Prometheus targets

    4. To verify that data is being collected, go to Graph, enter the sys_uptime variable in the field, click Execute, and then click the Graph tab. The screen should like this:

      Prometheus graph

    {{site.data.alerts.callout_success}} Prometheus auto-completes CockroachDB time series metrics for you, but if you want to see a full listing, with descriptions, port-forward as described in and then point your browser to http://localhost:8080/_status/vars.

    For more details on using the Prometheus UI, see their official documentation. {{site.data.alerts.end}}

Configure Alertmanager

Active monitoring helps you spot problems early, but it is also essential to send notifications when there are events that require investigation or intervention. This section shows you how to use Alertmanager and CockroachDB's starter alerting rules to do this.

  1. Download our alertmanager-config.yaml configuration file.

  2. Edit the alertmanager-config.yaml file to specify the desired receivers for notifications. Initially, the file contains a dummy web hook.

  3. Add this configuration to the Kubernetes cluster as a secret, renaming it to alertmanager.yaml and labelling it to make it easier to find:

    $ kubectl create secret generic alertmanager-cockroachdb --from-file=alertmanager.yaml=alertmanager-config.yaml
    
    secret "alertmanager-cockroachdb" created
    

    $ kubectl label secret alertmanager-cockroachdb app=cockroachdb
    
    secret "alertmanager-cockroachdb" labeled
    

    {{site.data.alerts.callout_danger}} The name of the secret, alertmanager-cockroachdb, must match the name used in the altermanager.yaml file. If they differ, the Alertmanager instance will start without configuration, and nothing will happen. {{site.data.alerts.end}}

  4. Use our alertmanager.yaml file to create the various objects necessary to run an Alertmanager instance, including a ClusterIP service so that Prometheus can forward alerts:

    $ kubectl apply -f https://raw.githubusercontent.com/cockroachdb/cockroach/master/cloud/kubernetes/prometheus/alertmanager.yaml
    
    alertmanager "cockroachdb" created
    service "alertmanager-cockroachdb" created
    
  5. Verify that Alertmanager is running:

    1. Port-forward from your local machine to the pod running Alertmanager:

      $ kubectl port-forward alertmanager-cockroachdb-0 9093
      
    2. Go to http://localhost:9093 in your browser. The screen should look like this:

      Alertmanager

  6. Ensure that the Alertmanagers are visible to Prometheus by opening http://localhost:9090/status. The screen should look like this:

    Alertmanager

  7. Add CockroachDB's starter alerting rules:

    $ kubectl apply -f https://raw.githubusercontent.com/cockroachdb/cockroach/master/cloud/kubernetes/prometheus/alert-rules.yaml
    
    prometheusrule "prometheus-cockroachdb-rules" created
    
  8. Ensure that the rules are visible to Prometheus by opening http://localhost:9090/rules. The screen should look like this:

    Alertmanager

  9. Verify that the example alert is firing by opening http://localhost:9090/alerts. The screen should look like this:

    Alertmanager

  10. To remove the example alert:

    1. Use the kubectl edit command to open the rules for editing:

      $ kubectl edit prometheusrules prometheus-cockroachdb-rules
      
    2. Remove the dummy.rules block and save the file:

      - name: rules/dummy.rules
        rules:
        - alert: TestAlertManager
          expr: vector(1)
      

Step 7. Maintain the cluster

Add nodes

The Kubernetes cluster contains 4 nodes, one master and 3 workers. Pods get placed only on worker nodes, so to ensure that you do not have two pods on the same node (as recommended in our production best practices), you need to add a new worker node and then edit your StatefulSet configuration to add another pod. The Kubernetes cluster we created contains 3 nodes that pods can be run on. To ensure that you do not have two pods on the same node (as recommended in our production best practices), you need to add a new node and then edit your StatefulSet configuration to add another pod.

  1. Add a worker node:
  2. Use the kubectl scale command to add a pod to your StatefulSet:

    {% include copy-clipboard.html %} ~~~ shell $ kubectl scale statefulset cockroachdb --replicas=4 ~~~ ~~~ statefulset "cockroachdb" scaled ~~~
    {% include copy-clipboard.html %} ~~~ shell $ kubectl scale statefulset my-release-cockroachdb --replicas=4 ~~~ ~~~ statefulset "my-release-cockroachdb" scaled ~~~
  1. Verify that a fourth pod was added successfully:

    $ kubectl get pods
    

Remove nodes

To safely remove a node from your cluster, you must first decommission the node and only then adjust the --replicas value of your StatefulSet configuration to permanently remove it. This sequence is important because the decommissioning process lets a node finish in-flight requests, rejects any new requests, and transfers all range replicas and range leases off the node.

{{site.data.alerts.callout_danger}} If you remove nodes without first telling CockroachDB to decommission them, you may cause data or even cluster unavailability. For more details about how this works and what to consider before removing nodes, see Decommission Nodes. {{site.data.alerts.end}}

  1. Launch a temporary interactive pod and use the cockroach node status command to get the internal IDs of nodes:

    {% include copy-clipboard.html %} ~~~ shell $ kubectl run cockroachdb -it --image=cockroachdb/cockroach --rm --restart=Never \ -- node status --insecure --host=cockroachdb-public ~~~ ~~~ id | address | build | started_at | updated_at | is_available | is_live +----+---------------------------------------------------------------------------------+--------+----------------------------------+----------------------------------+--------------+---------+ 1 | cockroachdb-0.cockroachdb.default.svc.cluster.local:26257 | v2.1.1 | 2018-11-29 16:04:36.486082+00:00 | 2018-11-29 18:24:24.587454+00:00 | true | true 2 | cockroachdb-2.cockroachdb.default.svc.cluster.local:26257 | v2.1.1 | 2018-11-29 16:55:03.880406+00:00 | 2018-11-29 18:24:23.469302+00:00 | true | true 3 | cockroachdb-1.cockroachdb.default.svc.cluster.local:26257 | v2.1.1 | 2018-11-29 16:04:41.383588+00:00 | 2018-11-29 18:24:25.030175+00:00 | true | true 4 | cockroachdb-3.cockroachdb.default.svc.cluster.local:26257 | v2.1.1 | 2018-11-29 17:31:19.990784+00:00 | 2018-11-29 18:24:26.041686+00:00 | true | true (4 rows) ~~~
    {% include copy-clipboard.html %} ~~~ shell $ kubectl run cockroachdb -it --image=cockroachdb/cockroach --rm --restart=Never \ -- node status --insecure --host=my-release-cockroachdb-public ~~~ ~~~ id | address | build | started_at | updated_at | is_available | is_live +----+---------------------------------------------------------------------------------+--------+----------------------------------+----------------------------------+--------------+---------+ 1 | my-release-cockroachdb-0.my-release-cockroachdb.default.svc.cluster.local:26257 | v2.1.1 | 2018-11-29 16:04:36.486082+00:00 | 2018-11-29 18:24:24.587454+00:00 | true | true 2 | my-release-cockroachdb-2.my-release-cockroachdb.default.svc.cluster.local:26257 | v2.1.1 | 2018-11-29 16:55:03.880406+00:00 | 2018-11-29 18:24:23.469302+00:00 | true | true 3 | my-release-cockroachdb-1.my-release-cockroachdb.default.svc.cluster.local:26257 | v2.1.1 | 2018-11-29 16:04:41.383588+00:00 | 2018-11-29 18:24:25.030175+00:00 | true | true 4 | my-release-cockroachdb-3.my-release-cockroachdb.default.svc.cluster.local:26257 | v2.1.1 | 2018-11-29 17:31:19.990784+00:00 | 2018-11-29 18:24:26.041686+00:00 | true | true (4 rows) ~~~
  2. Note the ID of the node with the highest number in its address (in this case, the address including cockroachdb-3) and use the cockroach node decommission command to decommission it:

    {{site.data.alerts.callout_info}} It's important to decommission the node with the highest number in its address because, when you reduce the --replica count, Kubernetes will remove the pod for that node. {{site.data.alerts.end}}

    {% include copy-clipboard.html %} ~~~ shell $ kubectl run cockroachdb -it --image=cockroachdb/cockroach --rm --restart=Never \ -- node decommission --insecure --host=cockroachdb-public ~~~
    {% include copy-clipboard.html %} ~~~ shell $ kubectl run cockroachdb -it --image=cockroachdb/cockroach --rm --restart=Never \ -- node decommission --insecure --host=my-release-cockroachdb-public ~~~

    You'll then see the decommissioning status print to stderr as it changes:

     id | is_live | replicas | is_decommissioning | is_draining  
    +---+---------+----------+--------------------+-------------+
      4 |  true   |       73 |        true        |    false     
    (1 row)
    

    Once the node has been fully decommissioned and stopped, you'll see a confirmation:

     id | is_live | replicas | is_decommissioning | is_draining  
    +---+---------+----------+--------------------+-------------+
      4 |  true   |        0 |        true        |    false     
    (1 row)
    
    No more data reported on target nodes. Please verify cluster health before removing the nodes.
    
  3. Once the node has been decommissioned, use the kubectl scale command to remove a pod from your StatefulSet:

    {% include copy-clipboard.html %} ~~~ shell $ kubectl scale statefulset cockroachdb --replicas=3 ~~~ ~~~ statefulset "cockroachdb" scaled ~~~
    {% include copy-clipboard.html %} ~~~ shell $ kubectl scale statefulset my-release-cockroachdb --replicas=3 ~~~ ~~~ statefulset "my-release-cockroachdb" scaled ~~~

Upgrade the cluster

As new versions of CockroachDB are released, it's strongly recommended to upgrade to newer versions in order to pick up bug fixes, performance improvements, and new features. The general CockroachDB upgrade documentation provides best practices for how to prepare for and execute upgrades of CockroachDB clusters, but the mechanism of actually stopping and restarting processes in Kubernetes is somewhat special.

Kubernetes knows how to carry out a safe rolling upgrade process of the CockroachDB nodes. When you tell it to change the Docker image used in the CockroachDB StatefulSet, Kubernetes will go one-by-one, stopping a node, restarting it with the new image, and waiting for it to be ready to receive client requests before moving on to the next one. For more information, see the Kubernetes documentation.

  1. Decide how the upgrade will be finalized.

    {{site.data.alerts.callout_info}} This step is relevant only when upgrading from v2.0.x to v2.1. For upgrades within the v2.1.x series, skip this step. {{site.data.alerts.end}}

    By default, after all nodes are running the new version, the upgrade process will be auto-finalized. This will enable certain performance improvements and bug fixes introduced in v2.1. After finalization, however, it will no longer be possible to perform a downgrade to v2.0. In the event of a catastrophic failure or corruption, the only option will be to start a new cluster using the old binary and then restore from one of the backups created prior to performing the upgrade.

    We recommend disabling auto-finalization so you can monitor the stability and performance of the upgraded cluster before finalizing the upgrade:

    1. Get a shell into the pod with the cockroach binary created earlier and start the CockroachDB built-in SQL client:

      {% include copy-clipboard.html %} ~~~ shell $ kubectl exec -it cockroachdb-client-secure -- ./cockroach sql --certs-dir=/cockroach-certs --host=cockroachdb-public ~~~
      {% include copy-clipboard.html %} ~~~ shell $ kubectl exec -it cockroachdb-client-secure -- ./cockroach sql --certs-dir=/cockroach-certs --host=my-release-cockroachdb-public ~~~

    1. Launch a temporary interactive pod and start the built-in SQL client inside it:

      {% include copy-clipboard.html %} ~~~ shell $ kubectl run cockroachdb -it --image=cockroachdb/cockroach --rm --restart=Never \ -- sql --insecure --host=cockroachdb-public ~~~
      {% include copy-clipboard.html %} ~~~ shell $ kubectl run cockroachdb -it --image=cockroachdb/cockroach --rm --restart=Never \ -- sql --insecure --host=my-release-cockroachdb-public ~~~

    1. Set the cluster.preserve_downgrade_option cluster setting:

      > SET CLUSTER SETTING cluster.preserve_downgrade_option = '2.0';
      
  2. Kick off the upgrade process by changing the desired Docker image. To do so, pick the version that you want to upgrade to, then run the following command, replacing "VERSION" with your desired new version:

    {% include copy-clipboard.html %} ~~~ shell $ kubectl patch statefulset cockroachdb --type='json' -p='[{"op": "replace", "path": "/spec/template/spec/containers/0/image", "value":"cockroachdb/cockroach:VERSION"}]' ~~~ ~~~ statefulset "cockroachdb" patched ~~~
    {% include copy-clipboard.html %} ~~~ shell $ kubectl patch statefulset my-release-cockroachdb --type='json' -p='[{"op": "replace", "path": "/spec/template/spec/containers/0/image", "value":"cockroachdb/cockroach:VERSION"}]' ~~~ ~~~ statefulset "my-release0-cockroachdb" patched ~~~
  3. If you then check the status of your cluster's pods, you should see one of them being restarted:

    $ kubectl get pods
    
    ~~~ NAME READY STATUS RESTARTS AGE cockroachdb-0 1/1 Running 0 2m cockroachdb-1 1/1 Running 0 2m cockroachdb-2 1/1 Running 0 2m cockroachdb-3 0/1 Terminating 0 1m ~~~
    ~~~ NAME READY STATUS RESTARTS AGE my-release-cockroachdb-0 1/1 Running 0 2m my-release-cockroachdb-1 1/1 Running 0 2m my-release-cockroachdb-2 1/1 Running 0 2m my-release-cockroachdb-3 0/1 Terminating 0 1m ~~~
  4. This will continue until all of the pods have restarted and are running the new image. To check the image of each pod to determine whether they've all be upgraded, run:

    $ kubectl get pods -o jsonpath='{range .items[*]}{.metadata.name}{"\t"}{.spec.containers[0].image}{"\n"}'
    
    ~~~ cockroachdb-0 cockroachdb/cockroach:{{page.release_info.version}} cockroachdb-1 cockroachdb/cockroach:{{page.release_info.version}} cockroachdb-2 cockroachdb/cockroach:{{page.release_info.version}} cockroachdb-3 cockroachdb/cockroach:{{page.release_info.version}} ~~~
    ~~~ my-release-cockroachdb-0 cockroachdb/cockroach:{{page.release_info.version}} my-release-cockroachdb-1 cockroachdb/cockroach:{{page.release_info.version}} my-release-cockroachdb-2 cockroachdb/cockroach:{{page.release_info.version}} my-release-cockroachdb-3 cockroachdb/cockroach:{{page.release_info.version}} ~~~
  5. Finish the upgrade.

    {{site.data.alerts.callout_info}}This step is relevant only when upgrading from v2.0.x to v2.1. For upgrades within the v2.1.x series, skip this step.{{site.data.alerts.end}}

    If you disabled auto-finalization in step 1 above, monitor the stability and performance of your cluster for as long as you require to feel comfortable with the upgrade (generally at least a day). If during this time you decide to roll back the upgrade, repeat the rolling restart procedure with the old binary.

    Once you are satisfied with the new version, re-enable auto-finalization:

    1. Get a shell into the pod with the cockroach binary created earlier and start the CockroachDB built-in SQL client:

      {% include copy-clipboard.html %} ~~~ shell $ kubectl exec -it cockroachdb-client-secure -- ./cockroach sql --certs-dir=/cockroach-certs --host=cockroachdb-public ~~~
      {% include copy-clipboard.html %} ~~~ shell $ kubectl exec -it cockroachdb-client-secure -- ./cockroach sql --certs-dir=/cockroach-certs --host=my-release-cockroachdb-public ~~~

    1. Launch a temporary interactive pod and start the built-in SQL client inside it:

      {% include copy-clipboard.html %} ~~~ shell $ kubectl run cockroachdb -it --image=cockroachdb/cockroach --rm --restart=Never \ -- sql --insecure --host=cockroachdb-public ~~~
      {% include copy-clipboard.html %} ~~~ shell $ kubectl run cockroachdb -it --image=cockroachdb/cockroach --rm --restart=Never \ -- sql --insecure --host=my-release-cockroachdb-public ~~~

    1. Re-enable auto-finalization:

      > RESET CLUSTER SETTING cluster.preserve_downgrade_option;
      

Stop the cluster

To shut down the CockroachDB cluster:

  1. Delete all of the resources you created, including the logs and remote persistent volumes:

    {% include copy-clipboard.html %} ~~~ shell $ kubectl delete pods,statefulsets,services,persistentvolumeclaims,persistentvolumes,poddisruptionbudget,jobs,rolebinding,clusterrolebinding,role,clusterrole,serviceaccount,alertmanager,prometheus,prometheusrule,serviceMonitor -l app=cockroachdb ~~~ ~~~ pod "cockroachdb-0" deleted pod "cockroachdb-1" deleted pod "cockroachdb-2" deleted pod "cockroachdb-3" deleted service "alertmanager-cockroachdb" deleted service "cockroachdb" deleted service "cockroachdb-public" deleted persistentvolumeclaim "datadir-cockroachdb-0" deleted persistentvolumeclaim "datadir-cockroachdb-1" deleted persistentvolumeclaim "datadir-cockroachdb-2" deleted persistentvolumeclaim "datadir-cockroachdb-3" deleted poddisruptionbudget "cockroachdb-budget" deleted job "cluster-init" deleted clusterrolebinding "prometheus" deleted clusterrole "prometheus" deleted serviceaccount "prometheus" deleted alertmanager "cockroachdb" deleted prometheus "cockroachdb" deleted prometheusrule "prometheus-cockroachdb-rules" deleted servicemonitor "cockroachdb" deleted ~~~
    {% include copy-clipboard.html %} ~~~ shell $ kubectl delete pods,statefulsets,services,persistentvolumeclaims,persistentvolumes,poddisruptionbudget,jobs,rolebinding,clusterrolebinding,role,clusterrole,serviceaccount,alertmanager,prometheus,prometheusrule,serviceMonitor -l app=my-release-cockroachdb ~~~ ~~~ pod "my-release-cockroachdb-0" deleted pod "my-release-cockroachdb-1" deleted pod "my-release-cockroachdb-2" deleted pod "my-release-cockroachdb-3" deleted service "alertmanager-cockroachdb" deleted service "my-release-cockroachdb" deleted service "my-release-cockroachdb-public" deleted persistentvolumeclaim "datadir-my-release-cockroachdb-0" deleted persistentvolumeclaim "datadir-my-release-cockroachdb-1" deleted persistentvolumeclaim "datadir-my-release-cockroachdb-2" deleted persistentvolumeclaim "datadir-my-release-cockroachdb-3" deleted poddisruptionbudget "cockroachdb-budget" deleted job "cluster-init" deleted clusterrolebinding "prometheus" deleted clusterrole "prometheus" deleted serviceaccount "prometheus" deleted alertmanager "cockroachdb" deleted prometheus "cockroachdb" deleted prometheusrule "prometheus-cockroachdb-rules" deleted servicemonitor "cockroachdb" deleted ~~~
  2. Stop Kubernetes:
    • Hosted GKE:

      $ gcloud container clusters delete cockroachdb
      
    • Manual GCE:

      $ cluster/kube-down.sh
      
    • Manual AWS:

      $ cluster/kube-down.sh
      

    {{site.data.alerts.callout_danger}} If you stop Kubernetes without first deleting the persistent volumes, they will still exist in your cloud project. {{site.data.alerts.end}}

See also