通过配置readiness探针和preStop hook,实现优雅启动和停止(滚动部署)
1. k8s工作负载配置
readinessProbe:
httpGet:
path: /datetime
port: 8080
scheme: HTTP
initialDelaySeconds: 30
timeoutSeconds: 1
periodSeconds: 30
successThreshold: 1
failureThreshold: 6
lifecycle:
preStop:
exec:
command:
- /bin/sh
- '-c'
- sleep 15s
2. 网关改造文章来源:https://www.toymoban.com/news/detail-842304.html
@SpringBootApplication
public class GracefulShutdownApplication {
public static void main(String[] args) {
SpringApplication.run(GracefulShutdownApplication.class, args);
}
@Bean
public GracefulShutdown gracefulShutdown() {
return new GracefulShutdown();
}
}
public class GracefulShutdown implements ApplicationListener<ContextClosedEvent> {
@Override
public void onApplicationEvent(ContextClosedEvent contextClosedEvent) {
HttpResources.disposeLoopsAndConnectionsLater().delaySubscription(Duration.ofSeconds(20)).block();
}
}
经过测试发现,可以实现请求0失败文章来源地址https://www.toymoban.com/news/detail-842304.html
到了这里,关于spring cloud gateway k8s优雅启停的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!