问题描述
我为Spring Cloud Dataflow创建了一个自定义s3-sink应用程序,但在流部署期间,该应用程序保持deploying
状态。我同时包含了网络和人工依赖,但我仍然面临着同样的问题。我认为该应用程序本身正在运行,因为它向s3-bucket添加了数据,但是一段时间后,该应用程序将显示Failed
状态,并且收到以下警告。
Warning Unhealthy 3m54s (x4 over 7m54s) kubelet,ip-x-x-x-x.ec2.internal Liveness probe Failed: HTTP probe Failed with statuscode: 404
Warning Unhealthy 3m45s (x15 over 8m4s) kubelet,ip-x-x-x-x.ec2.internal Readiness probe Failed: HTTP probe Failed with statuscode: 404
我正在将该应用程序部署为Kubernetes环境中Maven项目的dockerized映像。这是我的自定义应用程序代码。
@SpringBootApplication
@EnableBinding(Processor.class)
@EnableConfigurationProperties(Properties.class)
public class SpringCloudCustomApp {
@Autowired
private Properties AWSProperties;
@ServiceActivator(inputChannel = Processor.INPUT)
public void handleMessage(String msg) throws InterruptedException {
Regions clientRegion = Regions.US_EAST_1;
//Todo: add batch size to config
//Generate Unique ID
String uuid = (UUID.randomUUID().toString());
//Add Unique ID prefix to file name
String outName = uuid + "-" + AWSProperties.getFileObjKeyName();
try {
//Generate AWS Credentials using Properties class
BasicAWSCredentials awsCreds = new BasicAWSCredentials(AWSProperties.getAccessKey(),AWSProperties.getSecretKey());
//Create S3 Client
AmazonS3 s3Client = AmazonS3ClientBuilder.standard().withRegion(clientRegion).withCredentials(new AWsstaticCredentialsProvider(awsCreds)).build();
// Upload a text string as a new object.
ObjectMetadata Metadata = new ObjectMetadata();
Metadata.setContentType("application/json");
InputStream targetStream = new ByteArrayInputStream(msg.getBytes());
s3Client.putObject(AWSProperties.getBucketName(),outName,targetStream,Metadata);
} catch (AmazonServiceException e) {
// The call was transmitted successfully,but Amazon S3 Couldn't process
// it,so it returned an error response.
e.printstacktrace();
} catch (SdkClientException e) {
// Amazon S3 Couldn't be contacted for a response,or the client
// Couldn't parse the response from Amazon S3.
e.printstacktrace();
} catch (Exception e)
{
e.printstacktrace();
}
}
public static void main(String[] args) {
SpringApplication.run(SpringCloudCustomApp.class,args);
}
}
编辑:当我在本地部署maven项目时,该应用程序能够完全部署而没有任何问题,因此我的问题似乎与docker映像或kubernetes环境中的部署有关。
解决方法
您可以检查readiness
和liveness
探测端点是什么。默认情况下,SCDF将Spring Boot执行器端点设置为探针端点。
根据您使用的Spring Boot版本,您将得到以下探针端点:
对于Spring Boot 1.x:
Readiness: /info
Liveness: /health
对于Spring Boot 2.x:
Readiness: /actuator/info
Liveness: /actuator/health
这意味着您需要在应用程序中启用这些管理端点。例如,我需要具有以下属性:
我相信health
和info
端点在Spring Boot 1.x中都是默认启用的(如果情况并非如此,可以启用它们)。
但是,在Spring Boot 2.x中,您需要显式启用它们。因此,您需要这样的东西:
management.endpoints.web.exposure.include=health,info