Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/docker/10.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Postgresql GitLab无法连接到数据库_Postgresql_Docker_Kubernetes_Docker Compose_Gitlab - Fatal编程技术网

Postgresql GitLab无法连接到数据库

Postgresql GitLab无法连接到数据库,postgresql,docker,kubernetes,docker-compose,gitlab,Postgresql,Docker,Kubernetes,Docker Compose,Gitlab,我试图在Kubernetes和Gluster中为GitLab、Redis和PostgreSQL使用单独的容器。我将以PostgreSQL、Redis和GitLab的顺序启动这三个容器。前两个很好,但当我尝试启动GitLab时,它不知何故找不到数据库配置 [root@cent-gluster-workstation ~]# kubectl logs gitlab-3743104516-plk3x -p Initializing logdir... Initializing datadir... I

我试图在Kubernetes和Gluster中为GitLab、Redis和PostgreSQL使用单独的容器。我将以PostgreSQL、Redis和GitLab的顺序启动这三个容器。前两个很好,但当我尝试启动GitLab时,它不知何故找不到数据库配置

[root@cent-gluster-workstation ~]# kubectl logs gitlab-3743104516-plk3x -p
Initializing logdir...
Initializing datadir...
Installing configuration templates...
Configuring gitlab...
Configuring gitlab::database
ERROR:
  Please configure the database connection.
  Refer http://git.io/wkYhyA for more information.
  Cannot continue without a database. Aborting...
我确认我能够在端口5432上从GitLab pod内部远程登录到PostgreSQL pod

root@gitlab-1182173148-t47fj:/home/git/gitlab# telnet postgresql 5432
Trying 10.42.154.36...
Connected to postgresql.default.svc.cluster.local.
Escape character is '^]'. 
GitLab和PostgreSQL的部署和服务配置:

[root@cent-gluster-workstation ~]# cat postgresql-deployment.yaml
apiVersion: extensions/v1beta1
kind: Deployment
metadata:
  creationTimestamp: null
  labels:
    io.kompose.service: postgresql
  name: postgresql
spec:
  replicas: 1
  strategy: {}
  template:
    metadata:
      creationTimestamp: null
      labels:
        io.kompose.service: postgresql
    spec:
      containers:
      - env:
        - name: POSTGRES_DB
          value: gitlabhq_production
        - name: POSTGRES_PASSWORD
          value: password
        - name: POSTGRES_USER
          value: gitlab
        image: postgres:9.6.3
        name: postgresql
        volumeMounts:
        - name: gluster-vol1
          mountPath: /var/lib/postgresql
        resources: {}
      volumes:
      - name: gluster-vol1
        persistentVolumeClaim:
          claimName: gluster-dyn-pvc
status: {}


[root@cent-gluster-workstation ~]# cat postgresql-service.yaml
apiVersion: v1
kind: Service
metadata:
  creationTimestamp: null
  labels:
    io.kompose.service: postgresql
  name: postgresql
spec:
  clusterIP: None
  ports:
  - name: postgres
    port: 5432
    targetPort: 5432
  selector:
    io.kompose.service: postgresql
status:
  loadBalancer: {}


[root@cent-gluster-workstation ~]# cat gitlab-deployment.yaml
apiVersion: extensions/v1beta1
kind: Deployment
metadata:
  creationTimestamp: null
  labels:
    io.kompose.service: gitlab
  name: gitlab
spec:
  replicas: 1
  strategy: {}
  template:
    metadata:
      creationTimestamp: null
      labels:
        io.kompose.service: gitlab
    spec:
      containers:
      - env:
        - name: GITLAB_PORT
          value: "80"
        - name: GITLAB_SECRETS_DB_KEY_BASE
          value: 110Ect4ClClGBH06RSEQm4uKCxbpCyPzxfdLORkkssrStDnrQgpSSV
        - name: GITLAB_SECRETS_OTP_KEY_BASE
          value: MWxqmqqQkG1EXz9iz7Up4tEGBIEtFjxr1rL1Ry1rWCTWBjw3qxtvOM
        - name: GITLAB_SECRETS_SECRET_KEY_BASE
          value: 2KOeHYHNXB4r2XDZzy3XVrH2r0t6j71MBDUmfx4FxRPqjI5KZ9j4Md
        - name: GITLAB_SSH_PORT
          value: "10022"
        image: sameersbn/gitlab:9.3.9
        name: gitlab
        volumeMounts:
        - name: gluster-vol1
          mountPath: /home/git/data
        ports:
        - containerPort: 443
        - containerPort: 80
        - containerPort: 22
        resources: {}
      volumes:
      - name: gluster-vol1
        persistentVolumeClaim:
          claimName: gluster-dyn-pvc
status: {}
当我在没有Kubernetes和Gluster的情况下使用这三个容器时,我能够按照链接的快速入门部分中的步骤启动并运行GitLab。在本例中,我将卷装载路径用作所有三个容器(gitlab、Redis和PostgreSQL)的
/srv/docker/gitlab/

在当前情况下,正如您在上面的部署和服务YAML中所看到的,我使用Gluster volume映射容器路径。这是否与问题有关,或者其他地方出了问题

更新1:我已在上面的
postgresql service.yaml
中将服务端口名从“headless”更改为“postgres”。当我尝试使用
psql
从应用程序pod访问数据库时,它无法连接:

[rancher@node-c ~]$ docker exec -it 07a05cef7378 /bin/bash
groups: cannot find name for group ID 2000
root@gitlab-1182173148-b33z2:/home/git/gitlab# psql -U postgres -h 10.42.20.99
Password for user postgres:
root@gitlab-1182173148-b33z2:/home/git/gitlab# psql -U gitlab -h 10.42.20.99
Password for user gitlab:
psql: FATAL:  database "gitlab" does not exist
但是,如果我尝试从数据库pod内连接到
psql
,我就可以这样做

[root@node-c ~]# docker exec -it 4c968c09bccf /bin/bash
root@postgresql-1124339636-4377k:/# psql -U gitlab
psql: FATAL:  database "gitlab" does not exist
root@postgresql-1124339636-4377k:/# psql -U postgres
psql (9.6.3)
Type "help" for help.

postgres=# \l
                                      List of databases
        Name         |  Owner   | Encoding |  Collate   |   Ctype    |   Access privileges
---------------------+----------+----------+------------+------------+-----------------------
 gitlabhq_production | postgres | UTF8     | en_US.utf8 | en_US.utf8 |
 postgres            | postgres | UTF8     | en_US.utf8 | en_US.utf8 |
 template0           | postgres | UTF8     | en_US.utf8 | en_US.utf8 | =c/postgres          +
                     |          |          |            |            | postgres=CTc/postgres
 template1           | postgres | UTF8     | en_US.utf8 | en_US.utf8 | =c/postgres          +
                     |          |          |            |            | postgres=CTc/postgres
(4 rows)

postgres=# \du
                                   List of roles
 Role name |                         Attributes                         | Member of
-----------+------------------------------------------------------------+-----------
 gitlab    | Superuser                                                  | {}
 postgres  | Superuser, Create role, Create DB, Replication, Bypass RLS | {}
我感到困惑的一件事是,在app和db pod上,当我尝试访问数据库时,我不知道为什么Postgres将
gitlab
视为数据库,尽管我在它之前明确提供了
-U

当我尝试使用psql从应用程序pod访问数据库时,它无法连接

这实际上是错误的;它连接很好,但它没有做的是验证。我希望以psql--host postgresql.default.svc.cluster.local-d gitlabhq_production-U gitlab的形式重新运行该命令可以达到您的目的

我假设
10.42.20.99
PodIP,因为第二个片段显示
10.42.154.36
作为服务IP。我之所以提到这一点,是因为您当然欢迎使用PG的Pod IP进行测试,但我强烈建议不要使用除服务[hostname或IP]之外的任何东西,我更喜欢使用hostname,因为它使连接字符串的推理变得更加容易


话虽如此,仅根据您发布的代码片段来看,
gitlab
部署描述符中似乎缺少4
DB
环境变量



尽管您没有要求,但是将
gitlab
部署与环境保持同步是一个很好的例子,它与机制相结合。正如您可能怀疑的那样,它还可以方便地存储
GITLAB\u SECRETS\u DB\u KEY\u BASE
和friends

的值postgres日志中有什么有趣的内容吗?另外,虽然我很欣赏telnet测试,但尝试与实际的postgres客户机(psql、jdbc、pyscopg2,ruby使用的任何东西)连接会更有价值。您可能也会感兴趣,除非您已经在GlusterFS挂载中成功运行了
initdb
,您当然可以随意调用您的服务端口名,但“headless”在k8s服务中的含义是特定的,并且可能会混淆看到该名称的其他人。再说一遍:这只是为了你的体贴,谢谢。如果我可以将其安装在app pod上,请让我使用
psql
检查连接。对于无头文件,实际上这些文件是由
kompose
生成的。我将更改服务名称。顺便问一下,执行顺序是什么:
服务创建
然后
部署
或者反之亦然?顺便问一下,执行顺序是什么:服务创建然后部署,或者反之亦然?出于习惯,我通常首先进行部署,但我认为这是玩家的选择。我可以想象,首先提供服务的强大优势是,如果您有其他团队/容器等依赖于Dep,并且在所有事情都解决之前无法容忍对服务的任何响应(伙计,我希望有线程),我不知道为什么Postgres将gitlab视为数据库,尽管我在它之前明确提供了-U。因为您没有指定
-d
来选择数据库,PG将尝试连接到与用户同名的数据库;这可能就是为什么
psql-U postgres
的工作方式,就像你猜对了一样。:)非常感谢这4个变量!我从不怀疑这是原因,因为当我在Kubernetes的外部设置这三个容器时,我不必在GitLab容器启动脚本中声明它们。在这种情况下,我在gitlab脚本中使用了
--link gitlab postgresql:postgresql--link gitlab redis:redisio
,与“快速启动”下的设置相同。谢谢库伯内特家的秘密。必须将敏感数据保存在外部。当我在
办理登机手续时,我会想起