Postgresql Zalando postgres操作员从k8s外部访问群集

Postgresql Zalando postgres操作员从k8s外部访问群集,postgresql,kubernetes,Postgresql,Kubernetes,我已安装postgres群集Zalando postgres操作员 如何从外部访问postgres数据库? 我试图将群集服务类型从ClusterIP更改为NodePort,但它会自动被覆盖。此处解释了此过程: 你需要两个步骤 打开并将端口转发到本地计算机的脚本 我创建了一个名为set\u dbforwarding.sh的脚本。你需要 将脚本中的名称更改为群集名称和设置! 所以cdf集群应该变成yourclustername #!/usr/bin/env bash se

我已安装postgres群集Zalando postgres操作员 如何从外部访问postgres数据库?
我试图将群集服务类型从ClusterIP更改为NodePort,但它会自动被覆盖。

此处解释了此过程:

你需要两个步骤

  • 打开并将端口转发到本地计算机的脚本
  • 我创建了一个名为
    set\u dbforwarding.sh
    的脚本。你需要 将脚本中的名称更改为群集名称和设置! 所以
    cdf集群
    应该变成
    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 yourclusternamespace
    
  • 使用正确的凭据连接到群集<代码>还原数据库sh脚本

      #!/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 DATABASE=$2  
      export DATABASEDUMP=$3  
    
      export PGMASTER=$(kubectl -n $NAMESPACE get pods -o jsonpath={.items..metadata.name} -l application=spilo,cluster-name=cdf-cluster,spilo-rol
      export PGPASSWORD=$(kubectl -n $NAMESPACE get secret postgres.cdf-cluster.credentials.postgresql.acid.zalan.do -o 'jsonpath={.data.password}
      export PGSSLMODE=require  
    
      # examples you can run now the the above ENV variables set.
    
      # psql -h 127.0.0.1 -U postgres -d cdf -p 6432  
      #cat ~/dumps/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  
      # data only  
      # pg_restore -h 127.0.0.1 -U postgres -p 6432 -d $2 -a $3  
      # everything  
      pg_restore -h 127.0.0.1 -U postgres -p 6432 -d $2 $3  
    
  •      ./restore_db.sh namespace databasename backup.gz
    
  • 提示:如果您正在使用DBbeaver之类的数据库工具,请确保每隔5秒左右选中“保持活动”框。否则将断开连接。 keep alive将使其保持打开状态。但是设置在DBBeaver上相当隐藏

    编辑连接->连接设置->初始化->保持活动状态


  • 这里解释了该过程:

    你需要两个步骤

  • 打开并将端口转发到本地计算机的脚本
  • 我创建了一个名为
    set\u dbforwarding.sh
    的脚本。你需要 将脚本中的名称更改为群集名称和设置! 所以
    cdf集群
    应该变成
    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 yourclusternamespace
    
  • 使用正确的凭据连接到群集<代码>还原数据库sh脚本

      #!/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 DATABASE=$2  
      export DATABASEDUMP=$3  
    
      export PGMASTER=$(kubectl -n $NAMESPACE get pods -o jsonpath={.items..metadata.name} -l application=spilo,cluster-name=cdf-cluster,spilo-rol
      export PGPASSWORD=$(kubectl -n $NAMESPACE get secret postgres.cdf-cluster.credentials.postgresql.acid.zalan.do -o 'jsonpath={.data.password}
      export PGSSLMODE=require  
    
      # examples you can run now the the above ENV variables set.
    
      # psql -h 127.0.0.1 -U postgres -d cdf -p 6432  
      #cat ~/dumps/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  
      # data only  
      # pg_restore -h 127.0.0.1 -U postgres -p 6432 -d $2 -a $3  
      # everything  
      pg_restore -h 127.0.0.1 -U postgres -p 6432 -d $2 $3  
    
  •      ./restore_db.sh namespace databasename backup.gz
    
  • 提示:如果您正在使用DBbeaver之类的数据库工具,请确保每隔5秒左右选中“保持活动”框。否则将断开连接。 keep alive将使其保持打开状态。但是设置在DBBeaver上相当隐藏

    编辑连接->连接设置->初始化->保持活动状态