java - 在简单的打印 hello world 程序中的 kubernetes 部署中出现错误“ErrImagePull”
问题描述
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
解决方案
我已经重新创建了您的应用程序的图像,正如@mmking 在评论中提到的那样,它被终止,因为 pod 已经完成了它的任务。当您检查 pod 的日志时,您可以看到它已正确运行并打印了helloworld
20 次,然后被终止,因为该 pod 没有什么可做的了:
$kubectl logs javakubedeployment-7bcfb44b74-8b5zz
helloworld 1
helloworld 2
helloworld 3
[...]
helloworld 19
helloworld 20
要保持 pod 运行,您可以sleep
在其中添加简单的命令。
推荐阅读
- django - 删除/隐藏保存,保存并在管理面板中为我的一个模型添加另一个按钮
- r - 返回从数据框中修剪了多少修剪
- sql - 在我将身份规范更改为“是”后,为什么在 SQL Server 中它又变回了“否”?
- r - pglm 带偏移量的固定效应泊松模型
- mysql - 无法在我的数据库上运行特定的 SQL 查询
- laravel - 在 Vue 组件中解析 JSON 编码的数据
- c - 创建pthread时如何正确调用函数?
- sql - 为 SQL Server 和 Oracle 编写通用 SQL 以显示日期
- android - Google Play 崩溃日志未使用 Android App Bundle 进行符号化
- javascript - 我应该使用 CSS 还是 Javascript 来显示取决于屏幕大小的信息?重要吗?