在简单打印 hello world 程序中的 kubernetes 部署中出现错误“ErrImagePull”

时间:2020-12-29 17:31:25

标签: java docker kubernetes

helloworld.java

import java.util.*; 
public class helloworld {
public static void main(String[] a)
{
    int index;
    Scanner scan = new Scanner(System.in);
    for(index=0;index<20;index++)
    System.out.println("helloworld\t"+(index+1));
}
}

Dockerfile.file

FROM openjdk:7
LABEL maintainer="Arun kumar"
COPY . /usr/src/myapp
WORKDIR /usr/src/myapp
RUN javac helloworld.java
CMD ["java", "helloworld"]

这会准备一个 docker 镜像,然后我可以使用这个命令创建它(在文件所在的存储库中): docker built -t javaprogram .

然后我使用这个命令运行这个图像: docker run -it -d javaprogram

然后我使用以下命令创建容器的副本: docker commit containerId arunkumarduraisamy66/javacontprogram

然后我使用以下命令以公共模式将映像推送到我的 docker hub 存储库: docker push arunkumarduraisamy66/javacontprogram

然后我启动 MiniKube: minikube start

然后我尝试使用以下命令创建一个容器: kubectl create deployment javakubedeployment --image=arunkumarduraisamy66/javacontprogram

它给出了以下错误:ErrImagePull

我不知道如何解决这个问题。

C:\Users\thula\Documents\kubernetes and docker\docker java\helloworld> kubectl describe pod javaprogram-64b48854-ns7jp
Name:         javaprogram-64b48854-ns7jp
Namespace:    default
Priority:     0
Node:         minikube/192.168.49.2
Start Time:   Wed, 30 Dec 2020 09:04:42 +0530
Labels:       app=javaprogram
              pod-template-hash=64b48854
Annotations:  <none>
Status:       Running
IP:           172.17.0.3
IPs:
  IP:           172.17.0.3
Controlled By:  ReplicaSet/javaprogram-64b48854
Containers:
  javacontprogram:
    Container ID:   docker://8cb0722bde94704a3dfbec2514958c1cea88bd0f5df0afb2678292835c4f871e
    Image:          arunkumarduraisamy66/javacontprogram
    Image ID:       docker-pullable://arunkumarduraisamy66/javacontprogram@sha256:fe00f09ebc6a6bc651343a807b1adf9e48b62596ddf9424abc11ef3c6f713291
    Port:           <none>
    Host Port:      <none>
    State:          Terminated
      Reason:       Error
      Exit Code:    1
      Started:      Wed, 30 Dec 2020 09:05:50 +0530
      Finished:     Wed, 30 Dec 2020 09:05:51 +0530
    Last State:     Terminated
      Reason:       Error
      Exit Code:    1
      Started:      Wed, 30 Dec 2020 09:05:16 +0530
      Finished:     Wed, 30 Dec 2020 09:05:17 +0530
    Ready:          False
    Restart Count:  3
    Environment:    <none>
    Mounts:
      /var/run/secrets/kubernetes.io/serviceaccount from default-token-bs9b6 (ro)
Conditions:
  Type              Status
  Initialized       True
  Ready             False
  ContainersReady   False
  PodScheduled      True
Volumes:
  default-token-bs9b6:
    Type:        Secret (a volume populated by a Secret)
    SecretName:  default-token-bs9b6
    Optional:    false
QoS Class:       BestEffort
Node-Selectors:  <none>
Tolerations:     node.kubernetes.io/not-ready:NoExecute op=Exists for 300s
                 node.kubernetes.io/unreachable:NoExecute op=Exists for 300s
Events:
  Type     Reason     Age                From               Message
  ----     ------     ----               ----               -------
  Normal   Scheduled  79s                default-scheduler  Successfully assigned default/javaprogram-64b48854-ns7jp to minikube
  Normal   Pulled     74s                kubelet            Successfully pulled image "arunkumarduraisamy66/javacontprogram" in 3.4663937s
  Normal   Pulled     68s                kubelet            Successfully pulled image "arunkumarduraisamy66/javacontprogram" in 3.5957121s
  Normal   Pulled     46s                kubelet            Successfully pulled image "arunkumarduraisamy66/javacontprogram" in 3.8325583s
  Normal   Pulling    16s (x4 over 77s)  kubelet            Pulling image "arunkumarduraisamy66/javacontprogram"
  Normal   Pulled     13s                kubelet            Successfully pulled image "arunkumarduraisamy66/javacontprogram" in 3.5564947s
  Normal   Created    12s (x4 over 74s)  kubelet            Created container javacontprogram
  Normal   Started    12s (x4 over 73s)  kubelet            Started container javacontprogram
  Warning  BackOff    10s (x5 over 66s)  kubelet            Back-off restarting failed container

1 个答案:

答案 0 :(得分:0)

我已经重新创建了您的应用程序的映像,并且正如@mmking 在评论中所述,它已终止,因为 pod 已完成其任务。当您检查 pod 的日志时,您可以看到它已正确运行并打印了 helloworld 20 次,然后由于此 pod 无事可做而被终止:

$kubectl logs javakubedeployment-7bcfb44b74-8b5zz
helloworld      1
helloworld      2
helloworld      3
[...]
helloworld      19
helloworld      20

要保持 pod 运行,您可以在其中添加简单的 sleep 命令。