簡體   English   中英

如何在 Kube.netes 中將 PostgresSQL pod 連接到 Ruby on Rails pod

[英]How to connect PostgresSQL pod to Ruby on Rails pod in Kubernetes

我總共有 3 個豆莢。

  1. Ruby on Rails APP-1
  2. Ruby on Rails APP-2
  3. PostgreSQL 數據庫

APP-1 和 postgreSQL 數據庫在同一個命名空間但不同節點 APP-2 在自己的命名空間和 APP-1 在同一個節點

我總共有 3 個節點。 我希望我的 Ruby on Rails 應用程序連接到 PostgreSQL 數據庫。

但目前這是失敗的錯誤消息:

ActiveRecord::ConnectionNotEstablished (could not translate host name "myteam-demodb-0" to address: Name or service not known
):

數據庫.yml:

development:
  adapter: postgresql
  encoding: utf8
  database: demodb
  username: myowner
  password: <%= ENV["db_secret"] %>
  host: myteam-demodb
  port: 5432

這是我的kubectl get services output -

命名空間 1:

NAME                     TYPE       CLUSTER-IP     EXTERNAL-IP       PORT(S) 
APP-1                  ClusterIP   172.20.19.234    <none>          80/TCP    126m
myteam-demodb          ClusterIP   172.20.147.0     <none>        5432/TCP   126m

命名空間 2:

> NAME     TYPE        CLUSTER-IP       EXTERNAL-IP   PORT(S) 
> APP-2   ClusterIP   172.20.234.194        <none>    80/TCP    94m

kubectl describe service myteam-demodb output:

Name:              myteam-demodb
Namespace:         jx-staging
Labels:            application=spilo
                   cluster-name=myteam-demodb
                   spilo-role=master
                   team=myteam
Annotations:       <none>
Selector:          <none>
Type:              ClusterIP
IP Family Policy:  SingleStack
IP Families:       IPv4
IP:                172.20.147.0
IPs:               172.20.147.0
Port:              postgresql  5432/TCP
TargetPort:        5432/TCP
Endpoints:         10.0.3.194:5432
Session Affinity:  None
Events:            <none>

postgreSQL.yaml:

apiVersion: "acid.zalan.do/v1"
kind: postgresql
metadata:
  name: "myteam-demodb"
  annotations:
    meta.helm.sh/release-name: 'election-web-app'
  namespace: jx-staging
  labels:
    gitops.jenkins-x.io/pipeline: 'namespaces'
spec:
  teamId: "myteam"
  volume:
    size: 1Gi
  numberOfInstances: 2
  users:
    myowner: # database owner
      - superuser
      - createdb
    foo_user: [] # role for application foo
  databases:
    demodb: myowner # dbname: owner
  preparedDatabases:
    bar: {}
  postgresql:
    version: "13"

編輯: kubectl get service kube-dns -n kube-system output:

NAME     TYPE      CLUSTER-IP    EXTERNAL-IP   PORT(S)        
kube-dns ClusterIP 172.20.0.10   <none>    53/UDP,53/TCP   

嘗試:

development:
  ...
  host: myteam-demodb.jx-staging.svc.cluster.local
  ...

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM