在Kubernetes集群上,Spring Boot应用无法工作。

问题描述 投票:0回答:1

我正在使用jhipster开发一个微服务架构的应用程序。我可以在开发模式下运行我的服务,即使我收到这个警告,但是当我在kubernetes集群上运行它时,当我收到这个警告后,pod会一次又一次地循环重启自己。我有4个microservies和一个网关。所有的都是一样的。先谢谢你。

这就是警告。

2020-05-06 06:06:51.415 WARN 1 --- [scoveryClient-1] c.netflix.discovery.TimedSupervisorTask : task supervisor timed out 
java.util.concurrent.TimeoutException: null 
at java.base/java.util.concurrent.FutureTask.get(Unknown Source) 
at com.netflix.discovery.TimedSupervisorTask.run(TimedSupervisorTask.java:68) 
at java.base/java.util.concurrent.Executors$RunnableAdapter.call(Unknown Source) 
at java.base/java.util.concurrent.FutureTask.run(Unknown Source) 
at java.base/java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(Unknown Source) 
at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source) 
at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source) 
at java.base/java.lang.Thread.run(Unknown Source)

application.yml文件:

# ===================================================================
# Spring Boot configuration.
#
# This configuration will be overridden by the Spring profile you use,
# for example application-dev.yml if you use the "dev" profile.
#
# More information on profiles: https://www.jhipster.tech/profiles/
# More information on configuration properties: https://www.jhipster.tech/common-application-properties/
# ===================================================================

# ===================================================================
# Standard Spring Boot properties.
# Full reference is available at:
# http://docs.spring.io/spring-boot/docs/current/reference/html/common-application-properties.html
# ===================================================================

eureka:
  client:
    enabled: true
    healthcheck:
      enabled: true
    fetch-registry: true
    register-with-eureka: true
    instance-info-replication-interval-seconds: 10
    registry-fetch-interval-seconds: 10
  instance:
    appname: derinconfiguration
    instanceId: derinconfiguration:${spring.application.instance-id:${random.value}}
    lease-renewal-interval-in-seconds: 5
    lease-expiration-duration-in-seconds: 10
    status-page-url-path: ${management.endpoints.web.base-path}/info
    health-check-url-path: ${management.endpoints.web.base-path}/health
    metadata-map:
      zone: primary # This is needed for the load balancer
      profile: ${spring.profiles.active}
      version: #project.version#
      git-version: ${git.commit.id.describe:}
      git-commit: ${git.commit.id.abbrev:}
      git-branch: ${git.branch:}


# See https://github.com/Netflix/Hystrix/wiki/Configuration
hystrix:
  command:
    default:
      execution:
        isolation:
          thread:
            timeoutInMilliseconds: 30000
ribbon:
  ReadTimeout: 60000
  connection-timeout: 3000
  eureka:
    enabled: true
zuul:
  ignoredServices: '*'
  host:
    time-to-live: -1
    connect-timeout-millis: 5000
    max-per-route-connections: 10000
    max-total-connections: 5000
    socket-timeout-millis: 60000
  semaphore:
    max-semaphores: 500

management:
  endpoints:
    web:
      base-path: /management
      exposure:
        include: ['configprops', 'env', 'health', 'info', 'jhimetrics', 'logfile', 'loggers', 'prometheus', 'threaddump']
  endpoint:
    health:
      show-details: when_authorized
      roles: 'ROLE_ADMIN'
    jhimetrics:
      enabled: true
  info:
    git:
      mode: full
  health:
    mail:
      enabled: false # When using the MailService, configure an SMTP server and set this to true
  metrics:
    export:
      # Prometheus is the default metrics backend
      prometheus:
        enabled: true
        step: 60
    enable:
      http: true
      jvm: true
      logback: true
      process: true
      system: true
    distribution:
      percentiles-histogram:
        all: true
      percentiles:
        all: 0, 0.5, 0.75, 0.95, 0.99, 1.0
    tags:
      application: ${spring.application.name}
    web:
      server:
        request:
          autotime:
            enabled: true

spring:
  autoconfigure:
    exclude: org.springframework.boot.actuate.autoconfigure.metrics.jdbc.DataSourcePoolMetricsAutoConfiguration
  application:
    name: derinconfiguration
  jmx:
    enabled: false
  data:
    jpa:
      repositories:
        bootstrap-mode: deferred
  jpa:
    open-in-view: false
    properties:
      hibernate.jdbc.time_zone: UTC
      hibernate.id.new_generator_mappings: true
      hibernate.connection.provider_disables_autocommit: true
      hibernate.cache.use_second_level_cache: true
      hibernate.cache.use_query_cache: false
      hibernate.generate_statistics: false
      # modify batch size as necessary
      hibernate.jdbc.batch_size: 25
      hibernate.order_inserts: true
      hibernate.order_updates: true
      hibernate.query.fail_on_pagination_over_collection_fetch: true
      hibernate.query.in_clause_parameter_padding: true
      hibernate.cache.region.factory_class: com.hazelcast.hibernate.HazelcastCacheRegionFactory
      hibernate.cache.use_minimal_puts: true
      hibernate.cache.hazelcast.instance_name: derinconfiguration
      hibernate.cache.hazelcast.use_lite_member: true
    hibernate:
      ddl-auto: none
      naming:
        physical-strategy: org.springframework.boot.orm.jpa.hibernate.SpringPhysicalNamingStrategy
        implicit-strategy: org.springframework.boot.orm.jpa.hibernate.SpringImplicitNamingStrategy
  messages:
    basename: i18n/messages
  main:
    allow-bean-definition-overriding: true
  mvc:
    favicon:
      enabled: false
  task:
    execution:
      thread-name-prefix: derinconfiguration-task-
      pool:
        core-size: 2
        max-size: 50
        queue-capacity: 10000
    scheduling:
      thread-name-prefix: derinconfiguration-scheduling-
      pool:
        size: 2
  thymeleaf:
    mode: HTML
  output:
    ansi:
      console-available: true
security:
  oauth2:
    client:
      access-token-uri: http://localhost:9080/auth/realms/jhipster/protocol/openid-connect/token
      user-authorization-uri: http://localhost:9080/auth/realms/jhipster/protocol/openid-connect/auth
      client-id: web_app
      client-secret: web_app
      scope: openid profile email
    resource:
      filter-order: 3
      user-info-uri: http://localhost:9080/auth/realms/jhipster/protocol/openid-connect/userinfo

server:
  servlet:
    session:
      cookie:
        http-only: true

# Properties to be exposed on the /info management endpoint
info:
  # Comma separated list of profiles that will trigger the ribbon to show
  display-ribbon-on-profiles: 'dev'

# ===================================================================
# JHipster specific properties
#
# Full reference is available at: https://www.jhipster.tech/common-application-properties/
# ===================================================================

jhipster:
  clientApp:
    name: 'derinconfigurationApp'
  # By default CORS is disabled. Uncomment to enable.
  # cors:
  #     allowed-origins: "*"
  #     allowed-methods: "*"
  #     allowed-headers: "*"
  #     exposed-headers: "Authorization,Link,X-Total-Count"
  #     allow-credentials: true
  #     max-age: 1800
  mail:
    from: derinconfiguration@localhost
  swagger:
    default-include-pattern: /api/.*
    title: derinconfiguration API
    description: derinconfiguration API documentation
    version: 0.0.1
    terms-of-service-url:
    contact-name:
    contact-url:
    contact-email:
    license:
    license-url:
kafka:
  bootstrap-servers: localhost:9092
  consumer:
    key.deserializer: org.apache.kafka.common.serialization.StringDeserializer
    value.deserializer: org.apache.kafka.common.serialization.StringDeserializer
    group.id: derinconfiguration
    auto.offset.reset: earliest
  producer:
    key.serializer: org.apache.kafka.common.serialization.StringSerializer
    value.serializer: org.apache.kafka.common.serialization.StringSerializer
# ===================================================================
# Application specific properties
# Add your own application properties here, see the ApplicationProperties class
# to have type-safe configuration, like in the JHipsterProperties above
#
# More documentation is available at:
# https://www.jhipster.tech/common-application-properties/
# ===================================================================

# application:

Kubernetes配置。

apiVersion: apps/v1
kind: Deployment
metadata:
  name: derinconfiguration
  namespace: default
spec:
  replicas: 1
  selector:
    matchLabels:
      app: derinconfiguration
      version: 'v1'
  template:
    metadata:
      labels:
        app: derinconfiguration
        version: 'v1'
    spec:
      affinity:
        podAntiAffinity:
          preferredDuringSchedulingIgnoredDuringExecution:
            - podAffinityTerm:
                labelSelector:
                  matchExpressions:
                    - key: app
                      operator: In
                      values:
                        - derinconfiguration
                topologyKey: kubernetes.io/hostname
              weight: 100
      initContainers:
        - name: init-ds
          image: busybox:latest
          command:
            - '/bin/sh'
            - '-c'
            - |
              while true
              do
                rt=$(nc -z -w 1 192.168.1.156 5432)
                if [ $? -eq 0 ]; then
                  echo "DB is UP"
                  break
                fi
                echo "DB is not yet reachable;sleep for 10s before retry"
                sleep 10
              done
      containers:
        - name: derinconfiguration-app
          image: 192.168.1.150:5000/derin/derinconfiguration
          env:
            - name: SPRING_PROFILES_ACTIVE
              value: prod
            - name: SPRING_CLOUD_CONFIG_URI
              value: http://admin:${jhipster.registry.password}@jhipster-registry.default.svc.cluster.local:8761/config
            - name: JHIPSTER_REGISTRY_PASSWORD
              valueFrom:
                secretKeyRef:
                  name: registry-secret
                  key: registry-admin-password
            - name: EUREKA_CLIENT_SERVICE_URL_DEFAULTZONE
              value: http://admin:${jhipster.registry.password}@jhipster-registry.default.svc.cluster.local:8761/eureka/
            - name: SPRING_DATASOURCE_URL
              value: jdbc:postgresql://192.168.1.156:5432/derinfw
            - name: SPRING_DATASOURCE_USERNAME
              value: admin
            - name: SPRING_DATASOURCE_PASSWORD
              valueFrom:
                secretKeyRef:
                  name: postgresql-secret
                  key: postgresql-admin-password
            - name: KAFKA_CONSUMER_KEY_DESERIALIZER
              value: 'org.apache.kafka.common.serialization.StringDeserializer'
            - name: KAFKA_CONSUMER_VALUE_DESERIALIZER
              value: 'org.apache.kafka.common.serialization.StringDeserializer'
            - name: KAFKA_CONSUMER_BOOTSTRAP_SERVERS
              value: 'jhipster-kafka.default.svc.cluster.local:9092'
            - name: KAFKA_CONSUMER_GROUP_ID
              value: 'derinconfiguration'
            - name: KAFKA_CONSUMER_AUTO_OFFSET_RESET
              value: 'earliest'
            - name: KAFKA_PRODUCER_BOOTSTRAP_SERVERS
              value: 'jhipster-kafka.default.svc.cluster.local:9092'
            - name: KAFKA_PRODUCER_KEY_DESERIALIZER
              value: 'org.apache.kafka.common.serialization.StringDeserializer'
            - name: KAFKA_PRODUCER_VALUE_DESERIALIZER
              value: 'org.apache.kafka.common.serialization.StringDeserializer'
            - name: JHIPSTER_METRICS_LOGS_ENABLED
              value: 'true'
            - name: JHIPSTER_LOGGING_LOGSTASH_ENABLED
              value: 'true'
            - name: JHIPSTER_LOGGING_LOGSTASH_HOST
              value: jhipster-logstash
            - name: SPRING_ZIPKIN_ENABLED
              value: 'true'
            - name: SPRING_ZIPKIN_BASE_URL
              value: http://jhipster-zipkin
            - name: SPRING_SLEUTH_PROPAGATION_KEYS
              value: 'x-request-id,x-ot-span-context'
            - name: JAVA_OPTS
              value: ' -Xmx256m -Xms256m'
          resources:
            requests:
              memory: '512Mi'
              cpu: '500m'
            limits:
              memory: '1Gi'
              cpu: '1'
          ports:
            - name: http
              containerPort: 8084
          readinessProbe:
            httpGet:
              path: /management/health
              port: http
            initialDelaySeconds: 20
            periodSeconds: 15
            failureThreshold: 6
          livenessProbe:
            httpGet:
              path: /management/health
              port: http
            initialDelaySeconds: 120
java spring-boot kubernetes microservices jhipster
1个回答
1
投票

你是否尝试过禁用准备度和生命力探针?- 倪妮

在我移除准备度和活泼度探针后,它现在工作了。看来这需要额外的时间来运行。- mehmet

这是很常见的情况,因为某些原因,探针需要很长时间才能返回结果。

有时,你必须处理遗留的应用程序,这些应用程序可能需要在其第一次初始化时增加启动时间。在这种情况下,要在不影响快速响应死锁的情况下设置有效性探针参数是很棘手的。

诀窍是用相同的命令、HTTP或TCP检查来设置启动探针,并在其中加入 failureThreshold * periodSeconds 足够长的时间来覆盖最坏情况下的启动时间。

livenessProbe:
  httpGet:
    path: /healthz
    port: liveness-port
  failureThreshold: 1
  periodSeconds: 10

Probes 有许多字段,你可以用它们来更精确地控制可用性和准备度检查的行为。

initialDelaySeconds: 容器启动后,在启动活力或就绪度探测之前的秒数。默认值为 0 秒。最小值为 0。

periodSeconds: 执行探测的频率(以秒为单位)。默认值为 10 秒。最小值是1。

在你的YAML文件中,我首先要修改以下内容 readiness probe 第一

readinessProbe:
 httpGet:
   path: /management/health
 initialDelaySeconds: 20
 periodSeconds: 15
 failureThreshold: 6

livenessProbe:
 httpGet:
   path: /management/health
 initialDelaySeconds: 120

也就是说,在20+(6*15)=110秒后,Readiness探头将失效。同时 liveness 探头延迟设置为120秒。我会增加延时的 readiness 探头的数值与 livenes 一,以防止当流量被发送到Pod时,没有完全启动和运行的情况。

以下是一些信息 Kubernetes官方文档 探头上。

Liveness probe

许多长期运行的应用最终会过渡到破损状态,除非重新启动,否则无法恢复。Kubernetes提供了活力探针来检测和补救这种情况。

准备度探针

有时,应用程序会暂时无法提供流量服务。例如,应用程序可能需要在启动过程中加载大量数据或配置文件,或者在启动后依赖外部服务。在这种情况下,你不想杀死应用程序,但也不想给它发送请求。Kubernetes提供了就绪探针来检测和缓解这些情况。容器报告未准备好的pod不会通过Kubernetes服务接收流量。

注意:Readiness probes在容器的整个生命周期中都会在容器上运行。

Readiness probes 的配置与 liness probes 类似。唯一不同的是,您使用的是 readinessProbe 字段而不是 livenessProbe 领域。

readinessProbe:
  exec:
    command:
    - cat
    - /tmp/healthy
  initialDelaySeconds: 5
  periodSeconds: 5

希望能帮到你。


-1
投票

我怀疑您的健康终点 /management/health 未能返回200,提示K8s重新创建花苞。

© www.soinside.com 2019 - 2024. All rights reserved.