如果資料庫在 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}