Skip to content

Commit

Permalink
perf: 容器化环境支持无损更新 TencentBlueKing#2338
Browse files Browse the repository at this point in the history
1. k8s环境下支持停止接收流量后延迟一段时间关闭Spring容器,用于无损更新/扩缩容;
2. 基础镜像增加网络调试相关工具。
  • Loading branch information
jsonwan committed Aug 17, 2023
1 parent 7424e6d commit e804ee0
Show file tree
Hide file tree
Showing 9 changed files with 67 additions and 6 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package com.tencent.bk.job.common.consul.config;

import org.springframework.boot.availability.ApplicationAvailabilityBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration(proxyBeanMethods = false)
public class JobApplicationAvailabilityAutoConfiguration {

@Bean
public ApplicationAvailabilityBean applicationAvailability() {
return new ApplicationAvailabilityBean();
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
org.springframework.boot.autoconfigure.EnableAutoConfiguration=\
com.tencent.bk.job.common.consul.config.JobApplicationAvailabilityAutoConfiguration
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package com.tencent.bk.job.common.k8s.availability;

import com.tencent.bk.job.common.util.ThreadUtils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.availability.ApplicationAvailabilityBean;
import org.springframework.boot.availability.AvailabilityChangeEvent;
import org.springframework.boot.availability.ReadinessState;

@Slf4j
public class JobApplicationAvailabilityBean extends ApplicationAvailabilityBean {
@Override
public void onApplicationEvent(AvailabilityChangeEvent<?> event) {
super.onApplicationEvent(event);
if (ReadinessState.REFUSING_TRAFFIC == event.getState()) {
// SpringCloud负载均衡缓存默认为35s,等待调用方缓存刷新后再真正关闭Spring容器
int waitSeconds = 35;
while (waitSeconds > 0) {
ThreadUtils.sleep(1000);
log.info("wait for GracefulShutdown, {}s left", waitSeconds--);
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package com.tencent.bk.job.common.k8s.config;

import com.tencent.bk.job.common.k8s.availability.JobApplicationAvailabilityBean;
import org.springframework.boot.availability.ApplicationAvailabilityBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration(proxyBeanMethods = false)
public class JobApplicationAvailabilityAutoConfiguration {

@Bean
public ApplicationAvailabilityBean applicationAvailability() {
return new JobApplicationAvailabilityBean();
}

}
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
org.springframework.boot.autoconfigure.EnableAutoConfiguration=\
com.tencent.bk.job.common.k8s.config.K8sServiceInfoServiceAutoConfig
com.tencent.bk.job.common.k8s.config.K8sServiceInfoServiceAutoConfig,\
com.tencent.bk.job.common.k8s.config.JobApplicationAvailabilityAutoConfiguration
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,15 @@
import com.tencent.bk.job.common.config.FeatureToggleConfig;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.autoconfigure.availability.ApplicationAvailabilityAutoConfiguration;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.cloud.openfeign.EnableFeignClients;

/**
* @date 2019/09/20
*/
@SpringBootApplication(scanBasePackages = "com.tencent.bk.job")
@SpringBootApplication(scanBasePackages = "com.tencent.bk.job", exclude =
{ApplicationAvailabilityAutoConfiguration.class})
@EnableFeignClients
@EnableConfigurationProperties({FeatureToggleConfig.class})
public class JobLogBootApplication {
Expand Down
2 changes: 1 addition & 1 deletion support-files/kubernetes/images/backend/backend.Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM bkjob/jdk:0.0.2
FROM bkjob/jdk:0.0.3

LABEL maintainer="Tencent BlueKing Job"

Expand Down
4 changes: 2 additions & 2 deletions support-files/kubernetes/images/backend/jdk.Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM bkjob/os:0.0.1
FROM bkjob/os:0.0.2

LABEL maintainer="Tencent BlueKing Job"

Expand All @@ -10,4 +10,4 @@ RUN mkdir -p /data && \
rm -f TencentKona8.0.3.b2_jdk_linux-x86_64_8u262.tar.gz
ENV JAVA_HOME=/data/TencentKona-8.0.3-262
ENV PATH=${JAVA_HOME}/bin:$PATH
ENV CLASSPATH=.:${JAVA_HOME}/lib
ENV CLASSPATH=.:${JAVA_HOME}/lib
4 changes: 3 additions & 1 deletion support-files/kubernetes/images/backend/os.Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,6 @@ RUN ln -snf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime &&\
RUN yum install -y vim && \
yum install -y less && \
yum install -y wget && \
yum install -y lrzsz
yum install -y lrzsz && \
yum install -y net-tools.x86_64 && \
yum install -y bind-utils

0 comments on commit e804ee0

Please sign in to comment.