豆荚陷入待定状态

use*_*mda 12 java azure fabric8 kubernetes

我正在使用Kubernetes-client java客户端在Kubernetes集群上创建Deployments.这是代码

Deployment deployment = new DeploymentBuilder()
        .withNewMetadata()
        .withName("first-deployment")
        .endMetadata()
        .withNewSpec()
        .withReplicas(3)
        .withNewTemplate()
        .withNewMetadata()
        .addToLabels(namespaceID, "hello-world-example")
        .endMetadata()
        .withNewSpec()
        .addNewContainer()      
        .withName("nginx-one")
        .withImage("nginx")
        .addNewPort()
        .withContainerPort(80)
        .endPort()
        .withResources(resourceRequirements)
        .endContainer()
        .endSpec()
        .endTemplate()
        .endSpec()
        .build();
    deployment = client.extensions().deployments().inNamespace(namespace).create(deployment);
Run Code Online (Sandbox Code Playgroud)

我添加了3分钟的等待时间,然后测试了pod的状态

PodList podList = client.pods().withLabel(namespaceID, "hello-world-example").list();
    System.out.println("Number of pods " + podList.getItems().size());
    for (Pod pod : podList.getItems()) {
        System.out.println("Name " + pod.getMetadata().getName() 
            + " Status " + pod.getStatus().getPhase() 
            + " Reason " + pod.getStatus().getReason()
        + " Containers " + pod.getSpec().getContainers().get(0).getResources().getLimits());

    }
Run Code Online (Sandbox Code Playgroud)

这将返回以下sttaus

Name first-deployment-2418943216-9915m Status Pending Reason null Containers null
Name first-deployment-2418943216-fnk21 Status Pending Reason null Containers null
Name first-deployment-2418943216-zb5hr Status Pending Reason null Containers null
Run Code Online (Sandbox Code Playgroud)

但是如果我得到命令行的话kubectl get pods --all-namespaces.它将pod状态返回为running.我使用正确的API吗?我错过了什么?

fat*_*ook 2

也许检查这一点的更好方法是有一个循环并在循环中休眠并不断检查状态,直到所有 pod 都启动并运行。我做了类似的事情,通过检查状态来检查所有必需的 Pod 是否已启动。但在进行此类检查之前,您可能还需要考虑在 Pod 上添加活性和就绪探针。此处提供了其他详细信息。

https://kubernetes.io/docs/tasks/configure-pod-container/configure-liveness-readiness-probes/