如果您的数据库在 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_NAMEPod 的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}