<p>Kubernetes ends up with long running pods when an image specified for a container is purged from an image repository.  These deployments are created by a continuous integration system and sometimes pipelines are run or rerun when images have been purged.</p>

<p>The status from <code>kubectl get pods</code> shows <code>ImagePullBackOff</code>.</p>

<p>What should be set in the kube config yaml file to stop these pods from running for days?  Ideally we just want the Image to be pulled a couple of times and then fail if it's unsuccessful.</p>

<p>The pod definition is </p>

<pre><code>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
</code></pre>

<p>Thanks!</p>

<p>AKAIK, the only way to control this as of this writing is with the <a href="https://kubernetes.io/docs/concepts/configuration/overview/#container-images" rel="nofollow noreferrer">imagePullPolicy </a> in the container spec. </p>

<p>You may set it to <code>Never</code> but your pod will not run since the image is not present locally. Or you can set it to <code>IfNotPresent</code> but somehow you will have to have to create an image with that specific tag locally in your K8s nodes. Either option is not ideal, but I believe there might be a rationale to have it go into <code>ImagePullBackOff</code>: people would want to to know why their pod is not running.</p>

<p>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? Why not update the <code>pods/deployments/daemonsets/replicasets/statefulsets</code> with the latest images prior to deleting or invalidating an image in the docker registry (also called deploy)? </p>

<p>The general practice could be something like this:</p>

<pre><code>create new image =&gt; deploy it =&gt; make sure everything is ok =&gt; 
{
  ok =&gt; invalidate the old image tag.
  not ok =&gt; rollback =&gt; delete new image tag =&gt; go back to create new image =&gt; create new image tag.
}
</code></pre>

<p>Note, layers, and images are not deleted in a docker registry. You can delete or overwrite tags: <a href="https://stackoverflow.com/questions/25436742/how-to-delete-images-from-a-private-docker-registry?answertab=votes#tab-top">How to delete images from a private docker registry?</a></p>
