|
| 1 | +--- |
| 2 | +title: Resource Management with the Kubernetes Operator |
| 3 | +summary: Allocate CPU, memory, and storage resources for a cluster deployed with the Kubernetes Operator. |
| 4 | +toc: true |
| 5 | +toc_not_nested: true |
| 6 | +secure: true |
| 7 | +docs_area: deploy |
| 8 | +--- |
| 9 | + |
| 10 | +This page explains how to configure Kubernetes cluster resources such as memory, CPU, and storage. |
| 11 | + |
| 12 | +On a production cluster, the resources you allocate to CockroachDB should be proportionate to your machine types and workload. We recommend that you determine and set these values before deploying the cluster, but you can also update the values on a running cluster. |
| 13 | + |
| 14 | +{{site.data.alerts.callout_info}} |
| 15 | +Run `kubectl describe nodes` to see the available resources on the instances that you have provisioned. |
| 16 | +{{site.data.alerts.end}} |
| 17 | + |
| 18 | +## Memory and CPU |
| 19 | + |
| 20 | +You can set the CPU and memory resources allocated to the CockroachDB container on each pod. |
| 21 | + |
| 22 | +{{site.data.alerts.callout_info}} |
| 23 | +1 CPU in Kubernetes is equivalent to 1 vCPU or 1 hyperthread. For best practices on provisioning CPU and memory for CockroachDB, see the [Production Checklist](recommended-production-settings.html#hardware). |
| 24 | +{{site.data.alerts.end}} |
| 25 | + |
| 26 | +Specify CPU and memory values in `cockroachdb.crdbCluster.resources.limits` and `cockroachdb.crdbCluster.resources.requests` in the values file used to [deploy the cluster](deploy-cockroachdb-with-kubernetes-operator.html#initialize-the-cluster): |
| 27 | + |
| 28 | +```yaml |
| 29 | +cockroachdb: |
| 30 | + crdbCluster: |
| 31 | + resources: |
| 32 | + limits: |
| 33 | + cpu: 4000m |
| 34 | + memory: 16Gi |
| 35 | + requests: |
| 36 | + cpu: 4000m |
| 37 | + memory: 16Gi |
| 38 | +``` |
| 39 | +
|
| 40 | +Apply the new settings to the cluster: |
| 41 | +
|
| 42 | +```shell |
| 43 | +$ helm upgrade --reuse-values $CRDBCLUSTER ./cockroachdb-parent/charts/cockroachdb --values ./cockroachdb-parent/charts/cockroachdb/values.yaml -n $NAMESPACE |
| 44 | +``` |
| 45 | + |
| 46 | +We recommend using identical values for `resources.requests` and `resources.limits`. When setting the new values, note that not all of a pod's resources will be available to the CockroachDB container. This is because a fraction of the CPU and memory is reserved for Kubernetes. |
| 47 | + |
| 48 | +{{site.data.alerts.callout_info}} |
| 49 | +If no resource limits are specified, the pods will be able to consume the maximum available CPUs and memory. However, to avoid overallocating resources when another memory-intensive workload is on the same instance, always set resource requests and limits explicitly. |
| 50 | +{{site.data.alerts.end}} |
| 51 | + |
| 52 | +For more information on how Kubernetes handles resources, see the [Kubernetes documentation](https://kubernetes.io/docs/concepts/configuration/manage-compute-resources-container/). |
| 53 | + |
| 54 | +### Cache and SQL memory size |
| 55 | + |
| 56 | +Each CockroachDB node reserves a portion of its available memory for its cache and for storing temporary data for SQL queries. For more information on these settings, see the [Production Checklist](recommended-production-settings.html#cache-and-sql-memory-size). |
| 57 | + |
| 58 | +The Kubernetes operator dynamically sets cache size and SQL memory size each to 25% (the recommended percent) of the available memory, which depends on the memory request and limit you [specified](#memory-and-cpu) for your configuration. These values can be modified by adding the `cache` or `max-sql-memory` fields to `cockroachdb.crdbCluster.flags`, which is equivalent to appending `--cache` or `--max-sql-memory` as [cockroach start flags](cockroach-start.html#flags). |
| 59 | + |
| 60 | +## Persistent storage |
| 61 | + |
| 62 | +When you start your cluster, Kubernetes dynamically provisions and mounts a persistent volume into each pod. For more information on persistent volumes, see the [Kubernetes documentation](https://kubernetes.io/docs/concepts/storage/persistent-volumes/). |
| 63 | + |
| 64 | +The storage capacity of each volume is set in `cockroachdb.crdbCluster.dataStore.volumeClaimTemplate.spec.resources` in the values file used to [deploy the cluster](deploy-cockroachdb-with-kubernetes-operator.html#initialize-the-cluster): |
| 65 | + |
| 66 | +```yaml |
| 67 | +cockroachdb: |
| 68 | + crdbCluster: |
| 69 | + dataStore: |
| 70 | + volumeClaimTemplate: |
| 71 | + spec: |
| 72 | + resources: |
| 73 | + requests: |
| 74 | + storage: "10Gi" |
| 75 | +``` |
| 76 | +
|
| 77 | +You should provision an appropriate amount of disk storage for your workload. For recommendations on this, see the [Production Checklist](recommended-production-settings.html#storage). |
| 78 | +
|
| 79 | +### Expand disk size |
| 80 | +
|
| 81 | +If you discover that you need more capacity, you can expand the persistent volumes on a running cluster. Increasing disk size is often [beneficial for CockroachDB performance](kubernetes-operator-performance.html). |
| 82 | +
|
| 83 | +Specify a new volume size in the values file used to [deploy the cluster](deploy-cockroachdb-with-kubernetes-operator.html#initialize-the-cluster): |
| 84 | +
|
| 85 | +```yaml |
| 86 | +cockroachdb: |
| 87 | + crdbCluster: |
| 88 | + dataStore: |
| 89 | + volumeClaimTemplate: |
| 90 | + spec: |
| 91 | + resources: |
| 92 | + requests: |
| 93 | + storage: "100Gi" |
| 94 | +``` |
| 95 | +
|
| 96 | +Apply the new settings to the cluster: |
| 97 | +
|
| 98 | +```shell |
| 99 | +$ helm upgrade --reuse-values $CRDBCLUSTER ./cockroachdb-parent/charts/cockroachdb --values ./cockroachdb-parent/charts/cockroachdb/values.yaml -n $NAMESPACE |
| 100 | +``` |
| 101 | + |
| 102 | +The Operator updates all nodes and triggers a rolling restart of the pods with the new storage capacity. |
| 103 | + |
| 104 | +To verify that the storage capacity has been updated, run `kubectl get pvc` to view the persistent volume claims (PVCs). It will take a few minutes before the PVCs are completely updated. |
| 105 | + |
| 106 | +## Network ports |
| 107 | + |
| 108 | +The Operator separates network traffic into three ports: |
| 109 | + |
| 110 | +<table> |
| 111 | + <tr> |
| 112 | + <td><strong>Protocol</strong> |
| 113 | + </td> |
| 114 | + <td><strong>Default</strong> |
| 115 | + </td> |
| 116 | + <td><strong>Description</strong> |
| 117 | + </td> |
| 118 | + <td><strong>Custom Resource Field</strong> |
| 119 | + </td> |
| 120 | + </tr> |
| 121 | + <tr> |
| 122 | + <td>gRPC |
| 123 | + </td> |
| 124 | + <td>26258 |
| 125 | + </td> |
| 126 | + <td>Used for node connections |
| 127 | + </td> |
| 128 | + <td><code>service.ports.grpc</code> |
| 129 | + </td> |
| 130 | + </tr> |
| 131 | + <tr> |
| 132 | + <td>HTTP |
| 133 | + </td> |
| 134 | + <td>8080 |
| 135 | + </td> |
| 136 | + <td>Used to <a href="ui-overview.html#db-console-access">access the DB Console</a> |
| 137 | + </td> |
| 138 | + <td><code>service.ports.http</code> |
| 139 | + </td> |
| 140 | + </tr> |
| 141 | + <tr> |
| 142 | + <td>SQL |
| 143 | + </td> |
| 144 | + <td>26257 |
| 145 | + </td> |
| 146 | + <td>Used for SQL shell access |
| 147 | + </td> |
| 148 | + <td><code>service.ports.sql</code> |
| 149 | + </td> |
| 150 | + </tr> |
| 151 | +</table> |
| 152 | + |
| 153 | +Specify alternate port numbers in `cockroachdb.crdbCluster.service.ports` of the Operator's [custom resource](deploy-cockroachdb-with-kubernetes-operator.html#initialize-the-cluster) (for example, to match the default port `5432` on PostgreSQL): |
| 154 | + |
| 155 | +```yaml |
| 156 | +cockroachdb: |
| 157 | + crdbCluster: |
| 158 | + service: |
| 159 | + ports: |
| 160 | + sql: 5432 |
| 161 | +``` |
| 162 | +
|
| 163 | +Apply the new settings to the cluster: |
| 164 | +
|
| 165 | +```shell |
| 166 | +$ helm upgrade --reuse-values $CRDBCLUSTER ./cockroachdb-parent/charts/cockroachdb --values ./cockroachdb-parent/charts/cockroachdb/values.yaml -n $NAMESPACE |
| 167 | +``` |
| 168 | + |
| 169 | +The Operator updates all nodes and triggers a rolling restart of the pods with the new port settings. |
0 commit comments