VerticaAutoscaler 自定义资源
VerticaAutoscaler 自定义资源 (CR) 是一个 HorizontalPodAutoscaler,它使用以下策略之一自动扩展现有子群集的资源:
-
运行时间较短的仪表板查询的子群集扩展。
-
用于运行时间较长的分析查询的 Pod 扩展。
VerticaAutoscaler CR 使用资源或自定义指标进行扩展。Vertica 按工作负载管理子群集,这有助于您确定最佳指标以触发扩展事件。为了保持数据完整性,除非与 pod 的所有连接都已耗尽且会话已关闭,否则运算符不会缩减规模。
有关确定 VerticaAutoscaler 何时扩展的算法的详细信息,请参阅 Kubernetes 文档。
此外,VerticaAutoscaler 提供了一个 webhook 来验证状态更改。默认情况下,此 webhook 已启用。您可以使用 webhook.enableHelm 图表参数配置此 webhook。
参数
示例
此部分中的示例使用以下 VerticaDB 自定义资源。每个示例都使用 CPU 来触发扩展:
apiVersion: vertica.com/v1beta1
kind: VerticaDB
metadata:
name: dbname
spec:
communal:
path: "path/to/communal-storage"
endpoint: "path/to/communal-endpoint"
credentialSecret: credentials-secret
subclusters:
- name: primary1
size: 3
isPrimary: true
serviceName: primary1
resources:
limits:
cpu: "8"
requests:
cpu: "4"
先决条件
- 为触发扩展的指标设置一个值。例如,如果要按 CPU 利用率进行扩展,则必须设置 CPU 限制和请求。
子群集扩展
自动调整自定义资源中的子群集数量,以针对运行时间较短的仪表板查询优化资源。例如,增加子群集的数量以提高吞吐量。有关详细信息,请参阅使用子群集提高查询吞吐量。
所有子群集共享相同的服务对象,因此无需更改外部服务对象。新子群集中的 Pod 由现有服务对象进行负载均衡。
以下示例创建了一个 VerticaAutoscaler 自定义资源,当 VerticaDB 使用 50% 的节点可用 CPU 时,该资源将按子群集进行扩展:
-
在 YAML 格式的清单中定义 VerticaAutoscaler 自定义资源:
apiVersion: vertica.com/v1beta1 kind: VerticaAutoscaler metadata: name: autoscaler-name spec: verticaDBName: dbname scalingGranularity: Subcluster serviceName: primary1 -
使用 kubectl autoscale 命令创建 VerticaAutoscaler:
$ kubectl autoscale verticaautoscaler autoscaler-name --cpu-percent=50 --min=3 --max=12上一命令创建了一个 HorizontalPodAutoscaler 对象:
-
将目标 CPU 利用率设置为 50%。
-
扩展到一个子群集中至少有三个 pod,四个子群集中至少有 12 个 pod。
-
Pod 扩展
对于长时间运行的分析查询,增加子群集的 pod 计数。有关 Vertica 和分析查询的其他信息,请参阅使用 Elastic Crunch Scaling 提高查询性能。
在 Eon 模式数据库中扩展 pod 时,必须考虑对数据库分片的影响。有关详细信息,请参阅分片和订阅。
以下示例创建了一个 VerticaAutoscaler 自定义资源,当 VerticaDB 占用 50% 的节点可用 CPU 时,该资源将按 pod 进行扩展:
-
在 YAML 格式的清单中定义 VerticaAutoScaler 自定义资源:
apiVersion: vertica.com/v1beta1 kind: VerticaAutoscaler metadata: name: autoscaler-name spec: verticaDBName: dbname scalingGranularity: Pod serviceName: primary1 -
使用 kubectl autoscale 命令创建 autoscaler 实例:
$ kubectl autoscale verticaautoscaler autoscaler-name --cpu-percent=50 --min=3 --max=12上一命令创建了一个 HorizontalPodAutoscaler 对象:
-
将目标 CPU 利用率设置为 50%。
-
扩展到一个子群集中至少有三个 pod,四个子群集中至少有 12 个 pod。
-
事件监控
要查看 VerticaAutoscaler 对象,请使用 kubectl describe hpa 命令:
$ kubectl describe hpa autoscaler-name
Name: as
Namespace: vertica
Labels: <none>
Annotations: <none>
CreationTimestamp: Tue, 12 Apr 2022 15:11:28 -0300
Reference: VerticaAutoscaler/as
Metrics: ( current / target )
resource cpu on pods (as a percentage of request): 0% (9m) / 50%
Min replicas: 3
Max replicas: 12
VerticaAutoscaler pods: 3 current / 3 desired
Conditions:
Type Status Reason Message
---- ------ ------ -------
AbleToScale True ReadyForNewScale recommended size matches current size
ScalingActive True ValidMetricFound the HPA was able to successfully calculate a replica count from cpu resource utilization (percentage of request)
ScalingLimited False DesiredWithinRange the desired count is within the acceptable range
当发生扩展事件时,您可以查看 admintools 命令来扩展群集。使用 kubectl 查看 StatefulSets:
$ kubectl get statefulsets
NAME READY AGE
db-name-as-instance-name-0 0/3 71s
db-name-primary1 3/3 39m
使用 kubectl describe 查看正在执行的命令:
$ kubectl describe vdb dbname | tail
Upgrade Status:
Events:
Type Reason Age From Message
---- ------ ---- ---- -------
Normal ReviveDBStart 41m verticadb-operator Calling 'admintools -t revive_db'
Normal ReviveDBSucceeded 40m verticadb-operator Successfully revived database. It took 25.255683916s
Normal ClusterRestartStarted 40m verticadb-operator Calling 'admintools -t start_db' to restart the cluster
Normal ClusterRestartSucceeded 39m verticadb-operator Successfully called 'admintools -t start_db' and it took 44.713787718s
Normal SubclusterAdded 10s verticadb-operator Added new subcluster 'as-0'
Normal AddNodeStart 9s verticadb-operator Calling 'admintools -t db_add_node' for pod(s) 'db-name-as-instance-name-0-0, db-name-as-instance-name-0-1, db-name-as-instance-name-0-2'