无法在kubernetes中的一个Pod中的容器之间连接 [英] Can not connect between containers within one pod in kubernetes

查看:158
本文介绍了无法在kubernetes中的一个Pod中的容器之间连接的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我客户的bootstrap.yml

Here's my bootstrap.yml of my client

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

spring.application:
    name: microservices-client

spring.profiles:
    active: dev

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

Here's my spring config server bootstrap.yml

spring:
  application:
    name: microservices-client

  profiles:
    active: dev

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

这是我的spring config application.yml

And here's my spring config 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 Boot客户端无法连接到Kubernetes上的Spring Cloud Config时.我从Kubernetes上的日志客户端收到此错误.但是当我直接登录到客户端容器时,我没有收到此错误.

When spring boot client can not connect to spring cloud config on kubernetes. I'm getting this error from the log client on Kubernetes. But I'm not getting this error when I login directly into the client container.

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上为服务器定义的服务.但是,它仍然给我同样的错误.

Here's the log of the client. This time I've pointed it using the hostname with a service the I've defined for the server on port 32752. But it's still giving me the same error.

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$$9b0dbd2c] 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来解决了这个问题.客户端无法通过Bootstrap连接到同一Pod内的原因是因为服务器尚未准备就绪.

I solved this problem by deploying the config serve to another pod. The reason the client couldn't connect within the same pod (via bootstrap) is because the server wasn't ready.

这篇关于无法在kubernetes中的一个Pod中的容器之间连接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆