简体   繁体   English

如何在 kubernetes Pod 中重试图像拉取?

[英]How to retry image pull in a kubernetes Pods?

I am new to kubernetes.我是 kubernetes 的新手。 I have an issue in the pods.我在豆荚中遇到了问题。 When I run the command当我运行命令时

 kubectl get pods

Result:结果:

NAME                   READY     STATUS             RESTARTS   AGE
mysql-apim-db-1viwg    1/1       Running            1          20h
mysql-govdb-qioee      1/1       Running            1          20h
mysql-userdb-l8q8c     1/1       Running            0          20h
wso2am-default-813fy   0/1       ImagePullBackOff   0          20h

Due to an issue of "wso2am-default-813fy" node, I need to restart it.由于“wso2am-default-813fy”节点的问题,我需要重新启动它。 Any suggestion?有什么建议吗?

如果没有 yaml 文件:

kubectl get pod PODNAME -n NAMESPACE -o yaml | kubectl replace --force -f -

Usually in case of "ImagePullBackOff" it's retried after few seconds/minutes.通常在“ImagePullBackOff”的情况下,它会在几秒/分钟后重试。 In case you want to try again manually you can delete the old pod and recreate the pod.如果您想手动重试,您可以删除旧 pod 并重新创建 pod。 The one line command to delete and recreate the pod would be:删除和重新创建 pod 的一行命令是:

kubectl replace --force -f <yml_file_describing_pod>
$ kubectl replace --force -f <resource-file>

if all goes well, you should see something like:如果一切顺利,您应该会看到如下内容:

<resource-type> <resource-name> deleted
<resource-type> <resource-name> replaced

details of this can be found in the Kubernetes documentation, "manage-deployment" and kubectl-cheatsheet pages at the time of writing.有关详细信息,请参见撰写本文时的 Kubernetes 文档、“管理部署”和kubectl-cheatsheet页面。

If the Pod is part of a Deployment or Service , deleting it will restart the Pod and, potentially, place it onto another node:如果PodDeploymentService ,删除它会重新启动Pod并可能将其放置到另一个节点上:

$ kubectl delete po $POD_NAME

replace it if it's an individual Pod :如果它是单个Podreplace它:

$ kubectl get po -n $namespace $POD_NAME -o yaml | kubectl replace -f -

尝试删除 pod,它会再次尝试拉取图像。

kubectl delete pod <pod_name> -n <namespace_name>

First try to see what's wrong with the pod:首先尝试查看 pod 出了什么问题:

kubectl logs -p <your_pod>

In my case it was a problem with the YAML file.就我而言,这是 YAML 文件的问题。

So, I needed to correct the configuration file and replace it:所以,我需要更正配置文件并替换它:

kubectl replace --force -f <yml_file_describing_pod>

Most probably the issue of ImagePullBackOff is due to either the image not being present or issue with the pod YAML file. ImagePullBackOff 的问题很可能是由于图像不存在或 pod YAML 文件问题。

What I will do is this我要做的是这个

kubectl get pod -n $namespace $POD_NAME --export > pod.yaml | kubectl -f apply -

I would also see the pod.yaml to see the why the earlier pod didn't work我还会看到 pod.yaml 以了解为什么较早的 pod 不起作用

There is also possibility that the pull policy is not defined or kubernetes is configured to pull from the hub but fails due network issues.也有可能未定义拉取策略或将 kubernetes 配置为从集线器拉取但由于网络问题而失败。 Try setting up a local secure registry and execute a pull .尝试设置本地安全注册表并执行 pull 。 It would work.它会工作。

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

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