看起来我的spring应用在k8s部署中调用了两次优雅关闭。有人有类似的问题吗?
{"level":"INFO","message":"Commencing graceful shutdown. Waiting for active requests to complete","logger":"org.springframework.boot.web.embedded.tomcat.GracefulShutdown","thread":"SpringApplicationShutdownHook"}
{"level":"INFO","message":"Graceful shutdown complete","logger":"org.springframework.boot.web.embedded.tomcat.GracefulShutdown","thread":"tomcat-shutdown"}
{"level":"INFO","message":"Commencing graceful shutdown. Waiting for active requests to complete","logger":"org.springframework.boot.web.embedded.tomcat.GracefulShutdown","thread":"SpringApplicationShutdownHook"}
{"level":"INFO","message":"Graceful shutdown complete","logger":"org.springframework.boot.web.embedded.tomcat.GracefulShutdown","thread":"tomcat-shutdown"}
{"level":"INFO","message":"Closing JPA EntityManagerFactory for persistence unit 'default'","traceId":"","spanId":"","requestId":"","user":"","logger":"org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean","thread":"SpringApplicationShutdownHook"}
我的应用程序属性:
spring:
lifecycle:
timeout-per-shutdown-phase: 20s
server:
shutdown: graceful
我的简化部署:
apiVersion: apps/v1
kind: Deployment
metadata:
name: my-api
spec:
template:
spec:
containers:
- name: my-container
image: my-api
ports:
- name: container-port
containerPort: 8080
- name: metrics
containerPort: 8081
lifecycle:
preStop:
exec:
command: ["sh", "-c", "sleep 10"]
- name: cloud-sql-proxy
image: gcr.io/cloudsql-docker/gce-proxy:1.30.0
command:
- "/cloud_sql_proxy"
- "-ip_address_types=PRIVATE"
- "-structured_logs"
- "-verbose=false"
lifecycle:
preStop:
exec:
command: ["sh", "-c", "sleep 10"]
1条答案
按热度按时间0md85ypi1#
它之所以会这样,是因为你在不同的端口上有app和actuator(至少我从你的Deployment描述符中猜到了)。检查你的启动日志,你应该会看到这样的内容:
因此,当应用程序关闭时,这两个都将关闭。