本页面介绍了如何在 Kubernetes 集群中将数据库置于维护模式。
如果您的数据库在 Kubernetes 集群中运行,您可以通过停用在容器化应用中运行的活跃性探测和启动探测,将数据库置于维护模式,以确保数据库 Pod 处于健康状况良好状态。在您需要进行维护更新或修复 Pod 时,维护模式可帮助您将 Pod 置于运行状态。
启用维护模式
验证数据库 Pod 上是否存在探测:
活跃性探测:
kubectl get po -n NAMESPACE DATABASE_POD_NAME -o jsonpath='{.spec.containers[?(@.name=="database")].livenessProbe}'
替换以下内容:
NAMESPACE
:用于运行数据库的命名空间的名称,例如db
。DATABASE_POD_NAME
:数据库 Pod 的名称,例如al-4017-dbcluster-sample-0
。
下面显示了具有活跃性探测的示例输出:
{"failureThreshold":3,"httpGet":{"path":"/healthz?","port":8090,"scheme":"HTTP"},"periodSeconds":10,"successThreshold":1,"timeoutSeconds":3}
启动探测:
kubectl get po -n NAMESPACE DATABASE_POD_NAME -o jsonpath='{.spec.containers[?(@.name=="database")].startupProbe}'
下面显示了具有启动探测的示例输出:
{"exec":{"command":["/usr/lib/postgresql/15/bin/psql","-hlocalhost","-Ualloydbadmin","-c","SELECT 1"]},"failureThreshold":180,"periodSeconds":10,"successThreshold":1,"timeoutSeconds":1}
在 DBCluster 清单的
spec
部分中,将mode
设置为maintenance
:apiVersion: alloydbomni.dbadmin.goog/v1 kind: DBCluster metadata: name: DB_CLUSTER_NAME namespace: NAMESPACE spec: allowExternalIncomingTraffic: false isDeleted: false mode: maintenance primarySpec: ...
将
DB_CLUSTER_NAME
替换为此数据库集群的名称,例如my-db-cluster
。应用清单:
kubectl apply -f DB_CLUSTER_YAML
将
DB_CLUSTER_YAML
替换为此数据库集群清单文件的名称,例如alloydb-omni-db-cluster.yaml
。如需验证是否已启用维护模式,请运行以下命令:
活跃性探测:
kubectl get po -n NAMESPACE DATABASE_POD_NAME -o jsonpath='{.spec.containers[?(@.name=="database")].livenessProbe}'
启动探测:
kubectl get po -n NAMESPACE DATABASE_POD_NAME -o jsonpath='{.spec.containers[?(@.name=="database")].startupProbe}'
输出不包含
POD_NAME
Pod 的spec
部分中的Liveness
和Startup
字段。
停用维护模式
如需恢复为运行活跃性探测和启动探测的标准数据库集群行为,请使用以下命令从 DBCluster 清单的 spec
部分中移除 maintenance
:
kubectl patch dbclusters.alloydbomni.dbadmin.goog DB_CLUSTER_NAME -p '{"spec":{"mode":""}}' --type=merge -n DB_CLUSTER_NAMESPACE --type=merge
示例输出:
具有活跃性探测:
{"failureThreshold":3,"httpGet":{"path":"/healthz?","port":8090,"scheme":"HTTP"},"periodSeconds":10,"successThreshold":1,"timeoutSeconds":3}
具有启动探测:
{"exec":{"command":["/usr/lib/postgresql/15/bin/psql","-hlocalhost","-Ualloydbadmin","-c","SELECT 1"]},"failureThreshold":180, "periodSeconds":10,"successThreshold":1,"timeoutSeconds":1}