【问题标题】:Services not able to connect to Postgresql when Istio Sidecar is enabled in Kubernetes在 Kubernetes 中启用 Istio Sidecar 时服务无法连接到 Postgresql
【发布时间】:2020-10-22 12:01:31
【问题描述】:

我正在尝试通过在 kubernetes 上运行的容器启用 istio sidecar 注入。 istio init 容器的版本是proxy_init:1.0.3-gke.0,istio 代理的版本是istio/proxyv2:1.0.3

当我在我的命名空间之一中启用自动注入时,我的容器不会创建并出现错误

decurtis.dxp.core.common.api.hibernate.config.PersistenceConfig$$EnhancerBySpringCGLIB$$cb4e7fa5.dataSource(<generated>)
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.base/java.lang.reflect.Method.invoke(Method.java:564)
    at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:162)
    ... 49 more
Caused by: org.postgresql.util.PSQLException: The connection attempt failed.
    at org.postgresql.core.v3.ConnectionFactoryImpl.openConnectionImpl(ConnectionFactoryImpl.java:262)
    at org.postgresql.core.ConnectionFactory.openConnection(ConnectionFactory.java:67)
    at org.postgresql.jdbc.PgConnection.<init>(PgConnection.java:216)
    at org.postgresql.Driver.makeConnection(Driver.java:406)
    at org.postgresql.Driver.connect(Driver.java:274)
    at com.zaxxer.hikari.util.DriverDataSource.getConnection(DriverDataSource.java:95)
    at com.zaxxer.hikari.util.DriverDataSource.getConnection(DriverDataSource.java:101

【问题讨论】:

  • 能否提供Pod配置?
  • @mk_sta 我无法附加 pod 配置,评论太长了。有没有其他方法可以附加配置文件。

标签: istio


【解决方案1】:

问题是你的 Postgresql 在哪里。如果它在集群之外,您必须配置从集群对其的访问,请参阅this blog post关于连接到外部 MongoDB 实例。

如果它在集群内部,但没有注入 sidecar,你可能应该disable mutual TLS to it

【讨论】:

    【解决方案2】:

    还有两种可能。

    1- 您的应用程序启动速度比 Sidecar 启动速度快。换句话说,您的应用程序在 sidecar 准备好之前启动。你可以在哪里检查(http://localhost:15000 是否启动)所以它是(2/2)

    2- 如前所述,您可能需要将 ServiceEntry 作为@Vadim 引入。

    export "PG_HOST" = pg.exmaple.com
    export "PG_IP"=$(host $PG_HOST | grep " has address " | cut -d" " -f4)
    
    kubectl apply -f - <<EOF
    apiVersion: networking.istio.io/v1alpha3
    kind: ServiceEntry
    metadata:
       name: external-pg-service-entry
    spec:
       hosts:
         - $PG_HOST
       addresses:
         - $PG_IP/32
       ports:
         - number: 5432
          name: tcp
          protocol: TCP
       location: MESH_EXTERNAL
       resolution: STATIC
       endpoints:
         - address: $PG_IP
    EOF
    

    【讨论】:

      猜你喜欢
      • 2020-07-10
      • 1970-01-01
      • 2018-09-03
      • 1970-01-01
      • 2020-01-24
      • 1970-01-01
      • 1970-01-01
      • 2020-10-23
      • 1970-01-01
      相关资源
      最近更新 更多