首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >postgres-运算符连接数据库失败

postgres-运算符连接数据库失败
EN

Stack Overflow用户
提问于 2020-05-17 10:05:12
回答 1查看 1.1K关注 0票数 0

我已经在命名空间https://github.com/zalando/postgres-operator postgres上的K8S集群上安装了

代码语言:javascript
复制
helm install postgres-operator -n postgres ./charts/postgres-operator 
helm install postgres-operator-ui -n postgres ./charts/postgres-operator-ui

并创建了如下数据库:

代码语言:javascript
复制
kind: "postgresql"
apiVersion: "acid.zalan.do/v1"

metadata:
  name: "acid-databaker-db"
  namespace: "dev"
  labels:
    team: acid

spec:
  teamId: "acid"
  postgresql:
    version: "12"
  numberOfInstances: 2
  volume:
    size: "5Gi"
  users:
    admin: []
  databases:
    keycloak: admin
  allowedSourceRanges:
    # IP ranges to access your cluster go here

  resources:
    requests:
      cpu: 100m
      memory: 100Mi
    limits:
      cpu: 500m
      memory: 500Mi 

数据库实例已在命名空间dev上启动并运行。

代码语言:javascript
复制
NAME                       TYPE        CLUSTER-IP       EXTERNAL-IP   PORT(S)    AGE
acid-databaker-db          ClusterIP   10.245.205.143   <none>        5432/TCP   10h
acid-databaker-db-config   ClusterIP   None             <none>        <none>     10h
acid-databaker-db-repl     ClusterIP   10.245.152.182   <none>        5432/TCP   10h 

以及邮政服务的产出:

代码语言:javascript
复制
Name:              acid-databaker-db
Namespace:         dev
Labels:            application=spilo
                   cluster-name=acid-databaker-db
                   spilo-role=master
                   team=acid
Annotations:       <none>
Selector:          <none>
Type:              ClusterIP
IP:                10.245.205.143
Port:              postgresql  5432/TCP
TargetPort:        5432/TCP
Endpoints:         10.244.1.49:5432
Session Affinity:  None
Events:            <none>

我还试图通过本地计算机上的PSQL客户端连接创建的数据库,如下所示:

代码语言:javascript
复制
export PGMASTER=$(kubectl get pods -o jsonpath={.items..metadata.name} -l application=spilo,cluster-name=acid-databaker-db,spilo-role=master)
export PGPASSWORD=$(kubectl get secret  postgres.acid-databaker-db.credentials.postgresql.acid.zalan.do -o 'jsonpath={.data.password}' | base64 -d)

kubectl port-forward $PGMASTER 5432:5432
Forwarding from 127.0.0.1:5432 -> 5432
Forwarding from [::1]:5432 -> 5432

我试图连接到db并列出所有创建的db:

代码语言:javascript
复制
psql (12.2 (Ubuntu 12.2-4))
SSL connection (protocol: TLSv1.3, cipher: TLS_AES_256_GCM_SHA384, bits: 256, compression: off)
Type "help" for help.

postgres=# \dt
            List of relations
 Schema |     Name     | Type  |  Owner   
--------+--------------+-------+----------
 public | postgres_log | table | postgres
(1 row)         

为什么钥匙斗篷不存在,我创造了上面?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2020-05-17 11:29:19

您似乎遗漏了数据库所有者的权限和应用程序的角色,下面是正确的清单:

代码语言:javascript
复制
kind: "postgresql"
apiVersion: "acid.zalan.do/v1"

metadata:
  name: "acid-databaker-db"
  namespace: "postgres"
  labels:
    team: acid

spec:
  teamId: "acid"
  postgresql:
    version: "12"
  numberOfInstances: 2
  volume:
    size: "5Gi"
  users:
    admin: # database owner
      - superuser
      - createdb
    keycloak: [] # role for application
  databases:
    keycloakDB: keycloak # dbname: owner

  allowedSourceRanges:
    # IP ranges to access your cluster go here

  resources:
    requests:
      cpu: 100m
      memory: 100Mi
    limits:
      cpu: 500m
      memory: 500Mi
票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/61850049

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档