无法在 kubernetes 中的一个 pod 中的容器之间进行连接

Can not connect between containers within one pod in kubernetes

这是我的 bootstrap.yml 我的客户

spring:
  cloud:
    config:
      enabled: true
      uri: http://localhost:8888
      label: master

spring.application:
    name: microservices-client

spring.profiles:
    active: dev

这是我的 spring 配置服务器 bootstrap.yml

spring:
  application:
    name: microservices-client

  profiles:
    active: dev

  cloud:
    config:
      uri: http://localhost:8888

这是我的 spring 配置 application.yml

server:
  port: 8888

spring:
  cloud:
    config:
      server:
        git:
          uri: ssh://git@riscm.company.com/sem/some_repo.git
          ignoreLocalSshSettings: true
          privateKey:        | 
                             -----BEGIN RSA PRIVATE KEY-----
                             MIIJKgIBAAKCAgEA3iOtvDLAez5Azk6fYt2ApS8smK3mGZVt9Uu/mqsZxijx9hEG
                             Q4oPHhebR1sX/AstBZAWvcx7O9fb7CfA1/Zsy3x520FbGAEH+rQtiVfafJ27ZfDm

                             xtiAKzX1bGWVV51WcgCF8A9NcXOqoIF6yXeyGgBmMwHG3vi/Yc0JzqLsqcqLdQ==
                             -----END RSA PRIVATE KEY-----


endpoints:
  health:
    sensitive: true

management:
  security:
    enabled: false
  health:
    solr:
      enabled: false

当 spring 启动客户端无法连接到 spring kubernetes 上的云配置。我从 Kubernetes 上的日志客户端收到此错误。但是当我直接登录到客户端容器时,我没有收到这个错误。

2018-07-11 19:20:02.455  INFO 1 --- [           main] c.c.c.ConfigServicePropertySourceLocator : Fetching config from server at : http://localhost:8888 
2018-07-11 19:20:02.545  INFO 1 --- [           main] c.c.c.ConfigServicePropertySourceLocator : Connect Timeout Exception on Url - http://localhost:8888 . Will be trying the next url if available
2018-07-11 19:20:02.545  WARN 1 --- [           main] c.c.c.ConfigServicePropertySourceLocator : Could not locate PropertySource: I/O error on GET request for "http://localhost:8888/microservices-client/dev/master":  Connection refused (Connection refused); nested exception is java.net.ConnectException: Connection refused (Connection refused)
2018-07-11 19:20:02.547  INFO 1 --- [           main] com.regen.rest.Application               : The following profiles are active: dev

.

PodSpec:

apiVersion: apps/v1beta1
kind: Deployment
metadata:
  name: my-deploy
spec:
  replicas: 1
  selector:
    matchLabels:
      app:  myapp
  template:
    metadata:
      labels:
        app: myapplbl
    spec:
      containers:
      - name: config-svr
        image: on-amazonaws.com:latest
        imagePullPolicy: Always
        ports:
        - containerPort: 8888
          name: configsvr     
      - name: client-dev
        image: on-amazonawimage:latest
        imagePullPolicy: Always
        ports:
        - containerPort: 8098
          name: server

这是客户端的日志。这次我使用主机名和我为端口 32752 上的服务器定义的服务指向它。但它仍然给我同样的错误。

2018-07-12 13:31:36.731  INFO 1 --- [           main] c.c.c.ConfigServicePropertySourceLocator : Fetching config from server at : http://ccvocab-server-service.ccv.svc:32752 
2018-07-12 13:31:36.851  INFO 1 --- [           main] c.c.c.ConfigServicePropertySourceLocator : Connect Timeout Exception on Url - http://ccvocab-server-service.ccv.svc:32752 . Will be trying the next url if available
2018-07-12 13:31:36.851  WARN 1 --- [           main] c.c.c.ConfigServicePropertySourceLocator : Could not locate PropertySource: I/O error on GET request for "http://ccvocab-server-service.ccv.svc:32752/microservices-client/dev/master":  Connection refused (Connection refused); nested exception is java.net.ConnectException: Connection refused (Connection refused)
2018-07-12 13:31:36.853  INFO 1 --- [           main] com.regen.rest.Application               : The following profiles are active: dev
2018-07-12 13:31:36.866  INFO 1 --- [           main] ConfigServletWebServerApplicationContext : Refreshing org.springframework.boot.web.servlet.context.AnnotationConfigServletWebServerApplicationContext@31dc339b: startup date [Thu Jul 12 13:31:36 UTC 2018]; parent: org.springframework.context.annotation.AnnotationConfigApplicationContext@48140564
2018-07-12 13:31:38.240  INFO 1 --- [           main] o.s.b.f.s.DefaultListableBeanFactory     : Overriding bean definition for bean 'httpRequestHandlerAdapter' with a different definition: replacing [Root bean: class [null]; scope=; abstract=false; lazyInit=false; autowireMode=3; dependencyCheck=0; autowireCandidate=true; primary=false; factoryBeanName=org.springframework.boot.autoconfigure.web.servlet.WebMvcAutoConfiguration$EnableWebMvcConfiguration; factoryMethodName=httpRequestHandlerAdapter; initMethodName=null; destroyMethodName=(inferred); defined in class path resource [org/springframework/boot/autoconfigure/web/servlet/WebMvcAutoConfiguration$EnableWebMvcConfiguration.class]] with [Root bean: class [null]; scope=; abstract=false; lazyInit=false; autowireMode=3; dependencyCheck=0; autowireCandidate=true; primary=false; factoryBeanName=org.springframework.data.rest.webmvc.config.RepositoryRestMvcConfiguration; factoryMethodName=httpRequestHandlerAdapter; initMethodName=null; destroyMethodName=(inferred); defined in class path resource [org/springframework/data/rest/webmvc/config/RepositoryRestMvcConfiguration.class]]
2018-07-12 13:31:38.723  INFO 1 --- [           main] o.s.cloud.context.scope.GenericScope     : BeanFactory id=fedabff9-2282-310c-8521-2dcdb31a9300
2018-07-12 13:31:39.110  INFO 1 --- [           main] trationDelegate$BeanPostProcessorChecker : Bean 'org.springframework.cloud.autoconfigure.ConfigurationPropertiesRebinderAutoConfiguration' of type [org.springframework.cloud.autoconfigure.ConfigurationPropertiesRebinderAutoConfiguration$$EnhancerBySpringCGLIB$b0dbd2c] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
2018-07-12 13:31:39.373  INFO 1 --- [           main] o.s.b.w.embedded.tomcat.TomcatWebServer  : Tomcat initialized with port(s): 8098 (http)
2018-07-12 13:31:39.398  INFO 1 --- [           main] o.apache.catalina.core.StandardService   : Starting service [Tomcat]
2018-07-12 13:31:39.399  INFO 1 --- [           main] org.apache.catalina.core.StandardEngine  : Starting Servlet Engine: Apache Tomcat/8.5.31
2018-07-12 13:31:39.409  INFO 1 --- [ost-startStop-1] o.a.catalina.core.AprLifecycleListener   : The APR based Apache Tomcat Native library which allows optimal performance in production environments was not found on the java.library.path: [/usr/java/packages/lib/amd64:/usr/lib/x86_64-linux-gnu/jni:/lib/x86_64-linux-gnu:/usr/lib/x86_64-linux-gnu:/usr/lib/jni:/lib:/usr/lib]
2018-07-12 13:31:39.506  INFO 1 --- [ost-startStop-1] o.a.c.c.C.[Tomcat].[localhost].[/]       : Initializing Spring embedded WebApplicationContext
2018-07-12 13:31:39.506  INFO 1 --- [ost-startStop-1] o.s.web.context.ContextLoader            : Root WebApplicationContext: initialization completed in 2640 ms
2018-07-12 13:31:40.247  INFO 1 --- [ost-startStop-1] o.s.b.w.servlet.ServletRegistrationBean  : Servlet dispatcherServlet mapped to [/]
2018-07-12 13:31:40.250  INFO 1 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean   : Mapping filter: 'characterEncodingFilter' to: [/*]
2018-07-12 13:31:40.251  INFO 1 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean   : Mapping filter: 'hiddenHttpMethodFilter' to: [/*]
2018-07-12 13:31:40.251  INFO 1 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean   : Mapping filter: 'httpPutFormContentFilter' to: [/*]

我通过将配置服务部署到另一个 pod 解决了这个问题。客户端无法在同一个 pod 中连接(通过 bootstrap)的原因是服务器尚未准备好。