|
|
|
@@ -12,9 +12,7 @@ import io.kubernetes.client.openapi.ApiException; |
|
|
|
import io.kubernetes.client.openapi.apis.AppsV1Api; |
|
|
|
import io.kubernetes.client.openapi.apis.CoreV1Api; |
|
|
|
import io.kubernetes.client.openapi.models.*; |
|
|
|
import io.kubernetes.client.util.ClientBuilder; |
|
|
|
import io.kubernetes.client.util.Config; |
|
|
|
import io.kubernetes.client.util.credentials.AccessTokenAuthentication; |
|
|
|
import lombok.extern.slf4j.Slf4j; |
|
|
|
import org.apache.commons.lang.StringUtils; |
|
|
|
import org.json.JSONObject; |
|
|
|
@@ -630,6 +628,13 @@ public class K8sClientUtil { |
|
|
|
V1SecurityContext v1SecurityContext = new V1SecurityContext(); |
|
|
|
v1SecurityContext.setPrivileged(true); |
|
|
|
|
|
|
|
// 配置卷和卷挂载 |
|
|
|
List<V1VolumeMount> volumeMounts = new ArrayList<>(); |
|
|
|
volumeMounts.add(new V1VolumeMount().name("workspace").mountPath(mountPath)); |
|
|
|
|
|
|
|
List<V1Volume> volumes = new ArrayList<>(); |
|
|
|
volumes.add(new V1Volume().name("workspace").hostPath(new V1HostPathVolumeSource().path(hostPath + "/" + podName + "/" + mountPath).type("DirectoryOrCreate"))); |
|
|
|
|
|
|
|
V1Pod pod = new V1PodBuilder() |
|
|
|
.withNewMetadata() |
|
|
|
.withName(podName) |
|
|
|
@@ -639,7 +644,8 @@ public class K8sClientUtil { |
|
|
|
.withName(podName) |
|
|
|
.withImage(image) // 替换为您实际要使用的镜像名称 |
|
|
|
.withSecurityContext(v1SecurityContext) |
|
|
|
.withVolumeMounts(new V1VolumeMount().name("workspace").mountPath(mountPath)) |
|
|
|
// .withVolumeMounts(new V1VolumeMount().name("workspace").mountPath(mountPath)) |
|
|
|
.withVolumeMounts(volumeMounts) |
|
|
|
.withNewSecurityContext().withNewPrivileged(true).endSecurityContext() |
|
|
|
.addNewEnv() |
|
|
|
.withName("HTTP_PROXY") |
|
|
|
@@ -654,9 +660,10 @@ public class K8sClientUtil { |
|
|
|
.withValue("localhost,kubernetes.default.svc") |
|
|
|
.endEnv() |
|
|
|
.endContainer() |
|
|
|
.addNewVolume() |
|
|
|
.withName("workspace").withPersistentVolumeClaim(new V1PersistentVolumeClaimVolumeSource().claimName(pvcName)) |
|
|
|
.endVolume() |
|
|
|
// .addNewVolume() |
|
|
|
// .withName("workspace").withPersistentVolumeClaim(new V1PersistentVolumeClaimVolumeSource().claimName(pvcName)) |
|
|
|
// .endVolume() |
|
|
|
.withVolumes(volumes) |
|
|
|
.endSpec() |
|
|
|
.build(); |
|
|
|
try { |
|
|
|
|