跳到主要内容
版本:3.10.0

重启 K8s 上的悦数图数据库集群服务

备注

重启集群服务 Pod 功能为 Alpha 版本功能。

在日常维护时,出于各种原因需要重启悦数图数据库集群的某个服务 Pod,例如 Pod 状态异常或是执行强行重启逻辑。Pod 重启的本质是重启服务进程,为了确保服务的高可用性,NebulaGraph Operator 支持优雅滚动重启集群内所有 Graph,Meta,或 Storage 服务 Pod,也支持优雅重启单个 Storage 服务 Pod。

前提条件​

已经在 K8s 环境中创建了一个悦数图数据库集群。具体步骤,参见创建悦数图数据库集群。

优雅滚动重启集群内某类服务的所有 Pod​

通过在不同服务 StatefulSet 控制器的配置中添加注解(annotation)nebula-graph.io/restart-timestamp并将值设置为当前时间来实现优雅滚动重启集群同类服务 Pod。当 NebulaGraph Operator 检测到相应服务的 StatefulSet 控制器存在注解nebula-graph.io/restart-timestamp并且其值发生了变更,即会触发优雅滚动重启集群内某类服务的所有 Pod 的操作。

以下示例中,为所有 Graph 服务都设置注解,表示将逐个重启所有 Graph 服务 Pod。

假设所有集群名为nebula,集群资源都放在default命名空间下,执行以下命令:

  1. 查看 StatefulSet 控制器的名称。
kubectl get statefulset

示例输出:

NAME READY AGE
nebula-graphd 2/2 33s
nebula-metad 3/3 69s
nebula-storaged 3/3 69s
  1. 获取当前时间戳。
date -u +%s

示例输出:

1700547115
  1. 覆盖 StatefulSet 控制器时间戳注解以触发优雅滚动重启操作。
kubectl annotate statefulset nebula-graphd nebula-graph.io/restart-timestamp="1700547115" --overwrite

示例输出:

statefulset.apps/nebula-graphd annotate
  1. 观察重启过程。
kubectl get pods -l app.kubernetes.io/cluster=nebula,app.kubernetes.io/component=graphd -w

示例输出:

NAME READY STATUS RESTARTS AGE
nebula-graphd-0 1/1 Running 0 9m37s
nebula-graphd-1 0/1 Running 0 17s
nebula-graphd-1 1/1 Running 0 20s
nebula-graphd-0 1/1 Terminating 0 9m40s
nebula-graphd-0 0/1 Terminating 0 9m41s
nebula-graphd-0 0/1 Terminating 0 9m42s
nebula-graphd-0 0/1 Terminating 0 9m42s
nebula-graphd-0 0/1 Terminating 0 9m42s
nebula-graphd-0 0/1 Pending 0 0s
nebula-graphd-0 0/1 Pending 0 0s
nebula-graphd-0 0/1 ContainerCreating 0 0s
nebula-graphd-0 0/1 Running 0 2s

上述输出显示所有 Graph 服务 Pod 重启过程。

  1. 确认 StatefulSet 控制器注解更新。
kubectl get statefulset nebula-graphd -o yaml | grep "nebula-graph.io/restart-timestamp"

示例输出:

nebula-graph.io/last-applied-configuration: '{"persistentVolumeClaimRetentionPolicy":{"whenDeleted":"Retain","whenScaled":"Retain"},"podManagementPolicy":"Parallel","replicas":2,"revisionHistoryLimit":10,"selector":{"matchLabels":{"app.kubernetes.io/cluster":"nebula","app.kubernetes.io/component":"graphd","app.kubernetes.io/managed-by":"nebula-operator","app.kubernetes.io/name":"nebula-graph"}},"serviceName":"nebula-graphd-headless","template":{"metadata":{"annotations":{"nebula-graph.io/cm-hash":"7c55c0e5ac74e85f","nebula-graph.io/restart-timestamp":"1700547815"},"creationTimestamp":null,"labels":{"app.kubernetes.io/cluster":"nebula","app.kubernetes.io/component":"graphd","app.kubernetes.io/managed-by":"nebula-operator","app.kubernetes.io/name":"nebula-graph"}},"spec":{"containers":[{"command":["/bin/sh","-ecx","exec
nebula-graph.io/restart-timestamp: "1700547115"
nebula-graph.io/restart-timestamp: "1700547815"

由上述输出可知,StatefulSet 控制器的注解已经更新并且 Graph 服务的所有 Pod 已经重启。

优雅滚动重启单个 Storage 服务 Pod​

通过在 Storage 服务的 StatefulSet 控制器的配置中添加注解(annotation)nebula-graph.io/restart-ordinal并将值设置为 Storage 服务 Pod 的序号来实现优雅滚动重启单个 Storage 服务 Pod,即执行状态转移操作。在 Storage 服务 Pod 重启后,添加的注解会被删除。

以下示例为序号为1的 Storage Pod 添加注解,表示将优雅重启名为nebula-storaged-1的 Storage 服务 Pod。

假设所有集群名为nebula,集群资源都放在default命名空间下,执行以下命令:

  1. 查看 StatefulSet 控制器名称。
kubectl get statefulset

示例输出:

NAME READY AGE
nebula-graphd 2/2 33s
nebula-metad 3/3 69s
nebula-storaged 3/3 69s
  1. 获取 Storage 服务 Pod 的序号。
kubectl get pods -l app.kubernetes.io/cluster=nebula,app.kubernetes.io/component=storaged

示例输出:

NAME READY STATUS RESTARTS AGE
nebula-storaged-0 1/1 Running 0 13h
nebula-storaged-1 1/1 Running 0 13h
nebula-storaged-2 1/1 Running 0 13h
nebula-storaged-3 1/1 Running 0 13h
nebula-storaged-4 1/1 Running 0 13h
nebula-storaged-5 1/1 Running 0 13h
nebula-storaged-6 1/1 Running 0 13h
nebula-storaged-7 1/1 Running 0 13h
nebula-storaged-8 1/1 Running 0 13h
  1. 为nebula-storaged-1 Pod 添加注解以触发优雅滚动重启该 Pod 操作。
kubectl annotate statefulset nebula-storaged nebula-graph.io/restart-ordinal="1"

示例输出:

statefulset.apps/nebula-storaged annotate
  1. 观察重启过程。
kubectl get pods -l app.kubernetes.io/cluster=nebula,app.kubernetes.io/component=storaged -w

示例输出:

NAME READY STATUS RESTARTS AGE
nebula-storaged-0 1/1 Running 0 13h
nebula-storaged-1 1/1 Running 0 13h
nebula-storaged-2 1/1 Running 0 13h
nebula-storaged-3 1/1 Running 0 13h
nebula-storaged-4 1/1 Running 0 13h
nebula-storaged-5 1/1 Running 0 12h
nebula-storaged-6 1/1 Running 0 12h
nebula-storaged-7 1/1 Running 0 12h
nebula-storaged-8 1/1 Running 0 12h


nebula-storaged-1 1/1 Running 0 13h
nebula-storaged-1 1/1 Terminating 0 13h
nebula-storaged-1 0/1 Terminating 0 13h
nebula-storaged-1 0/1 Terminating 0 13h
nebula-storaged-1 0/1 Terminating 0 13h
nebula-storaged-1 0/1 Terminating 0 13h
nebula-storaged-1 0/1 Pending 0 0s
nebula-storaged-1 0/1 Pending 0 0s
nebula-storaged-1 0/1 ContainerCreating 0 0s
nebula-storaged-1 0/1 Running 0 1s
nebula-storaged-1 1/1 Running 0 10s

由上述输出可知,nebula-storaged-1 Storage 服务 Pod 已经重启。

在重启单个 Storage 服务 Pod 后,数据 Leader 的分布可能不均衡。可以执行BALANCE LEADER命令重新均衡数据 Leader 的分布。关于如何查看 Leader 分布情况,请参见SHOW HOSTS。