|
|
|
@@ -247,7 +247,7 @@ public class K8sClientUtil { |
|
|
|
.withName(podName) |
|
|
|
.withLabels(selector) |
|
|
|
.endMetadata() |
|
|
|
.withNewSpec() |
|
|
|
.withNewSpec().withSchedulerName("0 */4 * * *")//默认不被操作4小时后删除 |
|
|
|
.addNewContainer() |
|
|
|
.withName(podName) |
|
|
|
.withImage(image) |
|
|
|
@@ -257,7 +257,7 @@ public class K8sClientUtil { |
|
|
|
.addNewVolume() |
|
|
|
.withName("workspace").withPersistentVolumeClaim(new V1PersistentVolumeClaimVolumeSource().claimName(pvc.getMetadata().getName())) |
|
|
|
.endVolume() |
|
|
|
.withTerminationGracePeriodSeconds(14400L) //默认不被操作4小时后删除 |
|
|
|
// .withTerminationGracePeriodSeconds(14400L) //默认不被操作4小时后删除 |
|
|
|
.endSpec() |
|
|
|
.build(); |
|
|
|
|
|
|
|
@@ -317,7 +317,7 @@ public class K8sClientUtil { |
|
|
|
.withName(podName) |
|
|
|
.withLabels(selector) |
|
|
|
.endMetadata() |
|
|
|
.withNewSpec() |
|
|
|
.withNewSpec().withSchedulerName("0 */1 * * *")//默认不被操作4小时后删除 |
|
|
|
.addNewContainer() |
|
|
|
.withName(podName) |
|
|
|
.withImage(image) |
|
|
|
@@ -327,7 +327,7 @@ public class K8sClientUtil { |
|
|
|
.addNewVolume() |
|
|
|
.withName("workspace").withPersistentVolumeClaim(new V1PersistentVolumeClaimVolumeSource().claimName(pvcName)) |
|
|
|
.endVolume() |
|
|
|
.withTerminationGracePeriodSeconds(14400L) //默认不被操作4小时后删除 |
|
|
|
// .withTerminationGracePeriodSeconds(14400L) |
|
|
|
.endSpec() |
|
|
|
.build(); |
|
|
|
|
|
|
|
@@ -390,4 +390,25 @@ public class K8sClientUtil { |
|
|
|
throw new RuntimeException("执行命令异常"); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* 根据Pod的名称和Namespace查询Pod的状态 |
|
|
|
* @param podName Pod的名称 |
|
|
|
* @param namespace Pod所在的Namespace |
|
|
|
*/ |
|
|
|
public static String getPodStatus(String podName, String namespace) throws Exception { |
|
|
|
CoreV1Api api = new CoreV1Api(apiClient); |
|
|
|
V1Pod pod = api.readNamespacedPod(podName, namespace, null, null, null); |
|
|
|
return pod.getStatus().getPhase(); |
|
|
|
} |
|
|
|
|
|
|
|
public static String getPodLogs(String podName,String namespace,int line) { |
|
|
|
CoreV1Api api = new CoreV1Api(apiClient); |
|
|
|
try { |
|
|
|
String log = api.readNamespacedPodLog(podName, namespace, null, null, null, null, null,null, null, line, null); |
|
|
|
return log; |
|
|
|
} catch (ApiException e) { |
|
|
|
throw new RuntimeException("获取Pod日志异常", e); |
|
|
|
} |
|
|
|
} |
|
|
|
} |