在Kubernetes中启用Istio Sidecar时,服务无法连接到Postgresql

时间:2019-01-31 12:48:24

标签: istio

我正在尝试使用在kubernetes上运行的容器启用istio sidecar注入。 istio初始化容器的版本为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

2 个答案:

答案 0 :(得分:1)

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

如果它在集群内部,但是没有注入辅助工具,则可能应该disable mutual TLS to it

答案 1 :(得分:0)

还有两种可能性。

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
相关问题