Pods被卡在待定状态

12

我正在使用 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);

我增加了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());

    }

这将返回以下状态

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

然而,如果我从命令行输入kubectl get pods --all-namespaces,它返回pod状态为running。我是否使用了正确的API?我错过了什么吗?


如果远程主机在调用状态时仍在安排和启动容器,但是当您手动查看时,它们已经完成,那么很可能会出现这种情况,因此我认为您的代码大致正确,可能只需要等待更长时间。您可以通过检查 kubectl get pods --all-namespaces 的结果是否返回与您的 API 调用相同的 Pod 名称,只是状态、原因和容器引用不同来确定。 - heckj
是的,就是这个问题。我等了大约4分钟,状态一直是挂起的。我用kubectl手动检查了一下,pod都在运行。我不确定为什么库提供的结果和命令行kubectl不一样。 - user_mda
可能与https://github.com/kubernetes/kubernetes/issues/29876有关 - mghicks
2个回答

2

1

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接