简体   繁体   English

如何设置 Kubernetes 镜像拉取重试限制

[英]How to set Kubernetes image pull retry limit

Kubernetes ends up with long running pods when an image specified for a container is purged from an image repository.当为容器指定的映像从映像存储库中清除时,Kubernetes 最终会产生长时间运行的 pod。 These deployments are created by a continuous integration system and sometimes pipelines are run or rerun when images have been purged.这些部署由持续集成系统创建,有时在清除映像时运行或重新运行管道。

The status from kubectl get pods shows ImagePullBackOff . kubectl get pods的状态显示ImagePullBackOff

What should be set in the kube config yaml file to stop these pods from running for days?应该在 kube config yaml 文件中设置什么来阻止这些 pod 运行数天? Ideally we just want the Image to be pulled a couple of times and then fail if it's unsuccessful.理想情况下,我们只希望 Image 被拉动几次,如果不成功则失败。

The pod definition is pod 定义是

apiVersion: v1
kind: Pod
metadata:
  name: test-missing-image

spec:
  containers:

  - image: missingimage

    name: test
    resources:
      limits:
        memory: "10000Mi"
    readinessProbe:
      httpGet:
        port: 5678
        path: /somePath
      initialDelaySeconds: 360
      periodSeconds: 30
      timeoutSeconds: 30

  restartPolicy: Never
  terminationGracePeriodSeconds: 0

Thanks!谢谢!

AKAIK, the only way to control this as of this writing is with the imagePullPolicy in the container spec. AKAIK,在撰写本文时控制这一点的唯一方法是使用容器规范中的imagePullPolicy

You may set it to Never but your pod will not run since the image is not present locally.您可以将其设置为Never但您的 pod 将不会运行,因为本地不存在该图像。 Or you can set it to IfNotPresent but somehow you will have to have to create an image with that specific tag locally in your K8s nodes.或者您可以将其设置为IfNotPresent但不知何故,您必须在您的 K8s 节点本地创建具有该特定标签的图像。 Either option is not ideal, but I believe there might be a rationale to have it go into ImagePullBackOff : people would want to to know why their pod is not running.任一个选项都不理想,但我相信将它放入ImagePullBackOff可能有一个理由:人们想知道为什么他们的 pod 没有运行。

So IMO the bigger question is why would you want to delete/invalidate images in your docker registry that are still running in your cluster?所以 IMO 更大的问题是,为什么要删除/使 docker 注册表中仍在集群中运行的图像无效? Why not update the pods/deployments/daemonsets/replicasets/statefulsets with the latest images prior to deleting or invalidating an image in the docker registry (also called deploy)?为什么不在pods/deployments/daemonsets/replicasets/statefulsets注册表(也称为部署)中删除或使图像失效之前使用最新的图像更新pods/deployments/daemonsets/replicasets/statefulsets

The general practice could be something like this:一般的做法可能是这样的:

create new image => deploy it => make sure everything is ok => 
{
  ok => invalidate the old image tag.
  not ok => rollback => delete new image tag => go back to create new image => create new image tag.
}

Note, layers, and images are not deleted in a docker registry.注意,层和图像不会在 docker 注册表中删除。 You can delete or overwrite tags: How to delete images from a private docker registry?您可以删除或覆盖标签: 如何从私有 docker 注册表中删除图像?

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

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