通過(guò)配置readiness探針和preStop?hook,實(shí)現(xiàn)優(yōu)雅啟動(dòng)和停止(滾動(dòng)部署)
1. k8s工作負(fù)載配置
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. 網(wǎng)關(guān)改造文章來(lái)源:http://www.zghlxwxcb.cn/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();
}
}
經(jīng)過(guò)測(cè)試發(fā)現(xiàn),可以實(shí)現(xiàn)請(qǐng)求0失敗文章來(lái)源地址http://www.zghlxwxcb.cn/news/detail-842304.html
到了這里,關(guān)于spring cloud gateway k8s優(yōu)雅啟停的文章就介紹完了。如果您還想了解更多內(nèi)容,請(qǐng)?jiān)谟疑辖撬阉鱐OY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!