GitLab无法连接数据库

我正在尝试在Gubter中为Kubernetes使用单独的容器,用于GitLab,Redis和PostgreSQL。 我按照PostgreSQL,Redis和GitLab的顺序启动这三个容器。 前两个工作正常,但是当我尝试启动GitLab时,它以某种方式没有find数据库configuration。

[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... 

我确认我能够从GitLab窗格内telnet到5432端口上的PostgreSQL窗格。

 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的部署和服务configuration:

 [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)使用卷装path作为/srv/docker/gitlab/

在目前的情况下,你可以在上面的部署和服务YAML中看到,我使用Gluster卷来映射容器path。 这与这个问题有什么关系,或者某个地方有什么不对吗?

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

 [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 

但是,如果我尝试从数据库荚内连接到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 | {} 

有一件事,我很困惑的是,在应用程序和数据库荚,当我尝试访问数据库,不知道为什么Postgres对待gitlab作为数据库,虽然我明确提供-U之前。

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

那实际上是错误的; 它连接的很好,它没有做的是validation 。 我希望重新运行该命令为psql --host postgresql.default.svc.cluster.local -d gitlabhq_production -U gitlab会做你的意思。

我假定10.42.20.99Pod IP,因为第二个片段显示10.42.154.36作为服务IP。 我提到这一点,因为你当然欢迎使用PG的Pod IP进行testing,但是我强烈build议不要使用除Service [主机名或IP]以外的任何东西, 偏好转到主机名,因为它使得有关连接string的推理,更容易。


话虽如此,完全根据您发布的代码片段,似乎在gitlab部署描述符中缺less4个DB_环境variables, 如此处所示


虽然你没有问,保持postgres的环境与gitlab的环境同步部署对于Kubernetes Secrets是一个完美的例子,与valueFrom:secretKeyRef:机制相结合。 正如您可能会怀疑的那样,还可以方便地存储GITLAB_SECRETS_DB_KEY_BASE和朋友的值