AVt天堂网 手机版,亚洲va久久久噜噜噜久久4399,天天综合亚洲色在线精品,亚洲一级Av无码毛片久久精品

當前位置:首頁 > 科技  > 知識百科

云原生 PostgreSQL 集群 - PGO:五分鐘快速上手

來源: 責編: 時間:2023-08-07 16:29:56 264觀看
導讀 前提條件請確保您的主機上安裝了以下實用程序:kubectlgit安裝第 1 步:下載示例首先,轉到 GitHub 并 fork Postgres Operator 示例存儲庫:https://github.com/CrunchyData/postg

 KVi28資訊網——每日最新資訊28at.com

前提條件KVi28資訊網——每日最新資訊28at.com

請確保您的主機上安裝了以下實用程序:KVi28資訊網——每日最新資訊28at.com

kubectlgit安裝第 1 步:下載示例KVi28資訊網——每日最新資訊28at.com

首先,轉到 GitHub 并 fork Postgres Operator 示例存儲庫:KVi28資訊網——每日最新資訊28at.com

https://github.com/CrunchyData/postgres-operator-examples/forkKVi28資訊網——每日最新資訊28at.com

一旦你分叉了這個 repo,你可以使用類似下面的命令將它下載到你的工作環境中:KVi28資訊網——每日最新資訊28at.com

YOUR_GITHUB_UN=""KVi28資訊網——每日最新資訊28at.com
git clone --depth 1 "git@github.com:${YOUR_GITHUB_UN}/postgres-operator-examples.git"KVi28資訊網——每日最新資訊28at.com
cd postgres-operator-examplesKVi28資訊網——每日最新資訊28at.com

第 2 步:安裝 PGO,即 Postgres OperatorKVi28資訊網——每日最新資訊28at.com

您可以使用以下命令安裝 PGO,即來自 Crunchy Data 的 Postgres Operator:KVi28資訊網——每日最新資訊28at.com

kubectl apply -k kustomize/installKVi28資訊網——每日最新資訊28at.com

這將創建一個名為 postgres-operator 的命名空間,并創建部署 PGO 所需的所有對象。KVi28資訊網——每日最新資訊28at.com

要檢查安裝狀態,可以運行以下命令:KVi28資訊網——每日最新資訊28at.com

kubectl -n postgres-operator get pods KVi28資訊網——每日最新資訊28at.com
--selector=postgres-operator.crunchydata.com/control-plane=postgres-operator KVi28資訊網——每日最新資訊28at.com
--field-selector=status.phase=RunningKVi28資訊網——每日最新資訊28at.com

如果 PGO Pod 運行良好,您應該會看到類似于以下內容的輸出:KVi28資訊網——每日最新資訊28at.com

NAME READY STATUS RESTARTS AGEKVi28資訊網——每日最新資訊28at.com
postgres-operator-9dd545d64-t4h8d 1/1 Running 0 3s創建 Postgres 集群KVi28資訊網——每日最新資訊28at.com

讓我們創建一個簡單的 Postgres 集群。您可以通過執行以下命令來執行此操作:KVi28資訊網——每日最新資訊28at.com

kubectl apply -k kustomize/postgresKVi28資訊網——每日最新資訊28at.com

注意:KVi28資訊網——每日最新資訊28at.com

注意,你的集群已經有一個默認的 Storage ClassKVi28資訊網——每日最新資訊28at.com

這將在 postgres-operator 命名空間中創建一個名為 hippo 的 Postgres 集群。您可以使用以下命令跟蹤集群的進度:KVi28資訊網——每日最新資訊28at.com

kubectl -n postgres-operator describe postgresclusters.postgres-operator.crunchydata.com hippo連接到 Postgres 集群KVi28資訊網——每日最新資訊28at.com

作為創建 Postgres 集群的一部分,Postgres Operator 創建一個 PostgreSQL 用戶帳戶。此帳戶的憑據存儲在名為 -pguser- 的 Secret 中。KVi28資訊網——每日最新資訊28at.com

此 Secret 中的屬性提供了讓您登錄 PostgreSQL 集群的信息。這些包括:KVi28資訊網——每日最新資訊28at.com

user: 用戶帳戶的名稱。password: 用戶帳戶的密碼。dbname: 默認情況下用戶有權訪問的數據庫的名稱。host: 數據庫主機的名稱。這引用了主 Postgres 實例的 Service。port: 數據庫正在偵聽的端口。uri: 一個 PostgreSQL 連接 URI,它提供了登錄 Postgres 數據庫的所有信息。jdbc-uri: 一個 PostgreSQL JDBC 連接 URI,它提供了通過 JDBC driver 登錄到 Postgres 數據庫的所有信息。KVi28資訊網——每日最新資訊28at.com

如果您使用 PgBouncer 連接池部署 Postgres 集群,則用戶 Secret 中會填充其他值,包括:KVi28資訊網——每日最新資訊28at.com

pgbouncer-host: PgBouncer 連接池的主機名。這引用了 PgBouncer 連接池的 Service。pgbouncer-port: PgBouncer 連接池正在偵聽的端口。pgbouncer-uri: 一個 PostgreSQL 連接 URI,它提供了通過 PgBouncer 連接池登錄到 Postgres 數據庫的所有信息。pgbouncer-jdbc-uri: 一個 PostgreSQL JDBC 連接 URI,它提供了使用 JDBC driver 通過 PgBouncer 連接池登錄到 Postgres 數據庫的所有信息。KVi28資訊網——每日最新資訊28at.com

請注意,所有連接都使用 TLS。PGO 為您的 Postgres 集群設置 PKI。您也可以選擇自帶 PKI / certificate authority;這將在文檔后面介紹。KVi28資訊網——每日最新資訊28at.com

PgBouncerKVi28資訊網——每日最新資訊28at.com

https://www.pgbouncer.org/KVi28資訊網——每日最新資訊28at.com

通過終端中的 psql 連接KVi28資訊網——每日最新資訊28at.com

直接連接KVi28資訊網——每日最新資訊28at.com

如果您與 PostgreSQL 集群位于同一網絡上,則可以使用以下命令直接連接到它:KVi28資訊網——每日最新資訊28at.com

psql $(kubectl -n postgres-operator get secrets hippo-pguser-hippo -o go-template='{{.data.uri | base64decode}}')KVi28資訊網——每日最新資訊28at.com

使用端口轉發連接KVi28資訊網——每日最新資訊28at.com

在新終端中,創建一個端口轉發:KVi28資訊網——每日最新資訊28at.com

PG_CLUSTER_PRIMARY_POD=$(kubectl get pod -n postgres-operator -o name KVi28資訊網——每日最新資訊28at.com
-l postgres-operator.crunchydata.com/cluster=hippo,postgres-operator.crunchydata.com/role=master)KVi28資訊網——每日最新資訊28at.com
kubectl -n postgres-operator port-forward "${PG_CLUSTER_PRIMARY_POD}" 5432:5432KVi28資訊網——每日最新資訊28at.com

建立與 PostgreSQL 集群的連接。KVi28資訊網——每日最新資訊28at.com

PG_CLUSTER_USER_SECRET_NAME=hippo-pguser-hippoKVi28資訊網——每日最新資訊28at.com
KVi28資訊網——每日最新資訊28at.com
PGPASSWORD=$(kubectl get secrets -n postgres-operator "${PG_CLUSTER_USER_SECRET_NAME}" -o go-template='{{.data.password | base64decode}}') KVi28資訊網——每日最新資訊28at.com
PGUSER=$(kubectl get secrets -n postgres-operator "${PG_CLUSTER_USER_SECRET_NAME}" -o go-template='{{.data.user | base64decode}}') KVi28資訊網——每日最新資訊28at.com
PGDATABASE=$(kubectl get secrets -n postgres-operator "${PG_CLUSTER_USER_SECRET_NAME}" -o go-template='{{.data.dbname | base64decode}}') KVi28資訊網——每日最新資訊28at.com
psql -h localhost實戰 Keycloak 連接 PostgreSQL 集群KVi28資訊網——每日最新資訊28at.com

用戶 Secret 中提供的信息將允許您將應用程序直接連接到您的 PostgreSQL 數據庫。KVi28資訊網——每日最新資訊28at.com

例如,讓我們連接 Keycloak。Keycloak 是一種流行的開源身份管理工具,由 PostgreSQL 數據庫支持。使用我們創建的 hippo 集群,我們可以部署以下清單文件:KVi28資訊網——每日最新資訊28at.com

KeycloakKVi28資訊網——每日最新資訊28at.com

https://www.keycloak.org/cat <> keycloak.yamlKVi28資訊網——每日最新資訊28at.com
apiVersion: apps/v1KVi28資訊網——每日最新資訊28at.com
kind: DeploymentKVi28資訊網——每日最新資訊28at.com
metadata:KVi28資訊網——每日最新資訊28at.com
name: keycloakKVi28資訊網——每日最新資訊28at.com
namespace: postgres-operatorKVi28資訊網——每日最新資訊28at.com
labels:KVi28資訊網——每日最新資訊28at.com
app.kubernetes.io/name: keycloakKVi28資訊網——每日最新資訊28at.com
spec:KVi28資訊網——每日最新資訊28at.com
selector:KVi28資訊網——每日最新資訊28at.com
matchLabels:KVi28資訊網——每日最新資訊28at.com
app.kubernetes.io/name: keycloakKVi28資訊網——每日最新資訊28at.com
template:KVi28資訊網——每日最新資訊28at.com
metadata:KVi28資訊網——每日最新資訊28at.com
labels:KVi28資訊網——每日最新資訊28at.com
app.kubernetes.io/name: keycloakKVi28資訊網——每日最新資訊28at.com
spec:KVi28資訊網——每日最新資訊28at.com
containers:KVi28資訊網——每日最新資訊28at.com
- image: quay.io/keycloak/keycloak:latestKVi28資訊網——每日最新資訊28at.com
name: keycloakKVi28資訊網——每日最新資訊28at.com
args: ["start-dev"]KVi28資訊網——每日最新資訊28at.com
env:KVi28資訊網——每日最新資訊28at.com
- name: DB_VENDORKVi28資訊網——每日最新資訊28at.com
value: "postgres"KVi28資訊網——每日最新資訊28at.com
- name: DB_ADDRKVi28資訊網——每日最新資訊28at.com
valueFrom: { secretKeyRef: { name: hippo-pguser-hippo, key: host } }KVi28資訊網——每日最新資訊28at.com
- name: DB_PORTKVi28資訊網——每日最新資訊28at.com
valueFrom: { secretKeyRef: { name: hippo-pguser-hippo, key: port } }KVi28資訊網——每日最新資訊28at.com
- name: DB_DATABASEKVi28資訊網——每日最新資訊28at.com
valueFrom: { secretKeyRef: { name: hippo-pguser-hippo, key: dbname } }KVi28資訊網——每日最新資訊28at.com
- name: DB_USERKVi28資訊網——每日最新資訊28at.com
valueFrom: { secretKeyRef: { name: hippo-pguser-hippo, key: user } }KVi28資訊網——每日最新資訊28at.com
- name: DB_PASSWORDKVi28資訊網——每日最新資訊28at.com
valueFrom: { secretKeyRef: { name: hippo-pguser-hippo, key: password } }KVi28資訊網——每日最新資訊28at.com
- name: KEYCLOAK_ADMINKVi28資訊網——每日最新資訊28at.com
value: "admin"KVi28資訊網——每日最新資訊28at.com
- name: KEYCLOAK_ADMIN_PASSWORDKVi28資訊網——每日最新資訊28at.com
value: "admin"KVi28資訊網——每日最新資訊28at.com
- name: PROXY_ADDRESS_FORWARDINGKVi28資訊網——每日最新資訊28at.com
value: "true"KVi28資訊網——每日最新資訊28at.com
ports:KVi28資訊網——每日最新資訊28at.com
- name: httpKVi28資訊網——每日最新資訊28at.com
containerPort: 8080KVi28資訊網——每日最新資訊28at.com
- name: httpsKVi28資訊網——每日最新資訊28at.com
containerPort: 8443KVi28資訊網——每日最新資訊28at.com
restartPolicy: AlwaysKVi28資訊網——每日最新資訊28at.com
EOFKVi28資訊網——每日最新資訊28at.com
kubectl apply -f keycloak.yamlKVi28資訊網——每日最新資訊28at.com
kubectl -n postgres-operator port-forward ${KEYCLOAK_POD} 8086:8080 --address='0.0.0.0'KVi28資訊網——每日最新資訊28at.com
# Forwarding from 0.0.0.0:8086 -> 8080KVi28資訊網——每日最新資訊28at.com

轉到 http://127.0.0.1:8086KVi28資訊網——每日最新資訊28at.com

KVi28資訊網——每日最新資訊28at.com

在 kustomize/keycloak 文件夾中有一個關于如何使用 Postgres Operator 部署 Keycloak 的完整示例。KVi28資訊網——每日最新資訊28at.com

注意:KVi28資訊網——每日最新資訊28at.com

quay.io/keycloak/keycloak:latest,科學拉取鏡像對 keycloak.yaml 進行了上述修改KVi28資訊網——每日最新資訊28at.com

恭喜,您的 Postgres 集群已啟動并運行,還連接了一個應用程序!KVi28資訊網——每日最新資訊28at.com

本文鏈接:http://www.tebozhan.com/showinfo-119-2177-0.html云原生 PostgreSQL 集群 - PGO:五分鐘快速上手

聲明:本網頁內容旨在傳播知識,若有侵權等問題請及時與本網聯系,我們將在第一時間刪除處理。郵件:2376512515@qq.com

上一篇: 混合云:如何讓「混亂」回歸秩序 譯文

下一篇: 容器云架構 | 了解 Kubernetes 網絡模型

標簽:
  • 熱門焦點
Top