繁体   English   中英

如何使用 Kubernetes Java API 创建和运行 Pod?

[英]How to create and run a Pod with the Kubernetes Java API?

我想创建一个 pod,并且我还想在 pod/job 中执行一些命令,正如您在参数POST 'http://localhost:4009/src/getEndpount中看到的那样,我只是看到该作业是在控制台kubectl get jobs -A ,但我无法看到作业内部发生了什么或 Pod 是否已创建。 我没有看到任何created kubectl get pods的作业的 pod。

    fun newJob(uuid: String, githubURL: String?, token: String): V1Job? {
        val respondToEndpoint = String.format("%s%s%s", backendUrl, REST_API_BASE_PATH, uuid)
    
        return V1JobBuilder()
          .withNewMetadata()
          .withName(uuid.toString())
          .endMetadata()
          .withNewSpec()
          .withActiveDeadlineSeconds(120)
          .withParallelism(1)
          .withNewTemplate().withNewSpec()
          .addNewImagePullSecret()
          .withName(imagePullSecret)
          .endImagePullSecret()
          .withRestartPolicy("Never")
          .addNewContainer()
          .withName(uuid)
          .withImage(analystImage)
          .withImagePullPolicy("Always")
          .addToCommand("/bin/sh", "-c")
          .addToArgs(
            String.format(
              // "git clone %s /tmp/code && cd /tmp/code && r=$(/opt/tools/bin/sca_bom.sh $(pwd) $(git rev-parse HEAD) run 2>/dev/null) && curl --location --request PATCH '%s' -H 'Content-Type: text/plain' -H 'token: %s' --data-raw \"\$r\"",
              "curl --location --request POST 'http://localhost:4009/src/getEndpount' -H 'Content-Type: text/plain' -H 'token: %s' --data-raw \"\$r\"",
              token
            )
          )
          .endContainer().endSpec().endTemplate().endSpec()
          

   .build()
   }

创建作业后,我使用下一个代码创建名称空间,

  val job: V1Job? = kubeClient.newJob(uuid, repoURL, token)
  batchV1Api.createNamespacedJob(namespace, job, null, null, "", "")

我的问题是,如果来自 batchV1Api 的createNamespacedJob方法,我正在运行或创建一些 Pod,我看不到太多关于幕后发生的事情的信息。

检查 kubernetes 客户端 Java SDK Doc Here createNamespacedJob

它返回一个 V1Job,其中包含您可能需要的一些信息。

如果这对您来说还不够,您可以尝试readNamespacedJob

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM