我已经安装了postgres集群Zalando postgres operator https://github.com/zalando/postgres-operator,如何从外部访问postgres数据库?我尝试将集群服务类型从ClusterIP更改为NodePort,但它被自动覆盖。
发布于 2020-11-19 05:45:39
这里解释了这个过程:https://postgres-operator.readthedocs.io/en/latest/user/
你需要两个步骤。
打开端口并将其转发到本地计算机的
我创建了一个名为set_dbforwarding.sh的脚本。您需要将脚本中的名称更改为您的集群名称和设置!所以cdf-cluster应该成为yourclustername。
#!/usr/bin/env bash
set -u # crash on missing env variables
set -e # stop on any error
set -x # print what we are doing
export NAMESPACE=$1
export PGMASTER=$(kubectl -n cdf-acc get pods -o jsonpath={.items..metadata.name} -l application=spilo,cluster-name=cdf-cluster,spilo-role=m
# PGMASTER should be now the master node. There are cases under failover
# that you should connect to a different node in your cluster.
# If you want to change something you should always connect to the master.
# otherwise you get
# set up port forward
kubectl -n $NAMESPACE port-forward $PGMASTER 6432:5432
# get the password..it is printend in your terminal
# so you can use it in your db tool of choice.
export PGPASSWORD=$(kubectl -n $NAMESPACE get secret cdf.cdf-cluster.credentials.postgresql.acid.zalan.do -o 'jsonpath={.data.password}' | b
export PGSSLMODE=require执行方式如下:
./set_dbforwarding.sh yourclusternamespacerestore_db.sh脚本。#!/usr/bin/env bash set -u #在缺少环境变量时崩溃设置-e #在任何错误时停止设置-x #打印我们正在做的导出NAMESPACE=$1导出DATABASE=$2导出DATABASEDUMP=$3导出群集(kubectl -n $NAMESPACE get pods -o jsonpath={.items..metadata.name} -l application=spilo,cluster-name=cdf-PGMASTER=$,spilo-rol export PGPASSWORD=$(kubectl -n $NAMESPACE get secret PGPASSWORD=$ 'jsonpath={.data.password} export PGSSLMODE=require # examples你现在可以运行上面的ENV变量集了。# psql -h 127.0.0.1 -U postgres -d cdf -p 6432 #cat ~/dump/cbs_schema_wfs.sql| psql -h 127.0.0.1 -U postgres -d cdf -p 6432 # pg_restore -h 127.0.0.1 -U postgres -p 6432 -d $2 -c $3 #仅数据# pg_restore -h 127.0.0.1 -U postgres -p 6432 -d $2 $3 #一切pg_restore -h 127.0.0.1 -U postgres -p 6432 -d $2 $3
使用方式如下
./restore_db.sh namespace databasename backup.gz编辑连接->连接设置-> initialization -> Keep-Alive。
https://stackoverflow.com/questions/64847000
复制相似问题