|
|
@@ -162,6 +162,34 @@ public class DeployHandler extends AbstractHandler{
|
|
|
}
|
|
|
context.appendSuccessResult("K8s Service创建成功: [namespace: " + context.getNamespace() + ", deployName: " + context.getDeployName() + "]");
|
|
|
|
|
|
+
|
|
|
+ //3.3 配置external type的 service,使得其可以被前端访问
|
|
|
+ service = new Service();
|
|
|
+ service.setType("ExternalName");
|
|
|
+ service.setExternalName( context.getDeployName() + K8sConstants.SERVICE_SUFFIX+"."+namespace+".svc.cluster.local");
|
|
|
+ service.setNamespace(context.getNamespace());
|
|
|
+ service.setName(context.getDeployName() + K8sConstants.EXTERNAL_SERVICE_SUFFIX);
|
|
|
+ service.setServicePorts(
|
|
|
+ Collections.singleton(ServicePort.builder().port(port).targetPort(port).build())
|
|
|
+ );
|
|
|
+ //3.4 创建external service实例
|
|
|
+ try {
|
|
|
+ List<Service> services = serviceApi.getByCondition(K8sObjectRequest.builder()
|
|
|
+ .namespace(context.getNamespace())
|
|
|
+ .name(context.getDeployName() + K8sConstants.EXTERNAL_SERVICE_SUFFIX)
|
|
|
+ .build());
|
|
|
+ if (services.size() == 0) {
|
|
|
+ serviceApi.create(service);
|
|
|
+ log.info("external service创建成功: [namespace: " + context.getNamespace() + ", deployName: " + context.getDeployName() + "]");
|
|
|
+ } else {
|
|
|
+ serviceApi.update(service);
|
|
|
+ log.info("external service更新成功: [namespace: " + context.getNamespace() + ", deployName: " + context.getDeployName() + "]");
|
|
|
+ }
|
|
|
+ } catch (K8sApiException e) {
|
|
|
+ context.appendErrorResult(PipelineException.SERVICE_CREATE_ERROR, e);
|
|
|
+ throw new PipelineException(HttpStatus.SC_SERVICE_UNAVAILABLE, PipelineException.SERVICE_CREATE_ERROR, e);
|
|
|
+ }
|
|
|
+
|
|
|
//4. 创建ingress
|
|
|
//4.1. ingress路径规则
|
|
|
Ingress.IngressRule ingressRule = new Ingress.IngressRule();
|