DEV Community

orca forge
orca forge

Posted on Originally published at forge.workstyle.tech

Why Kubernetes Recreate Deployments Stop on Image Not Found

📝 Originally published (in Japanese) at forge.workstyle.tech.

TL;DR: A Kubernetes Recreate deployment stopped when a new container image returned not found. The image was present in the registry, but connections from production nodes timed out. Measuring the registry path and avoiding image pulls during deployment helped in some cases.

TL;DR

When a Recreate deployment stalled on Kubernetes with not found, the image was present in the registry, but the connection from the production node to the registry was timing out. Changing the pull policy to IfNotPresent avoided re-pulling an existing image. Preloading the image onto the target node before the Recreate deployment also helped avoid pulling it during deployment. The root cause of the network issue is still unknown.

Why Did not found Stop the Recreate?

not found alone doesn’t tell you whether the image is missing from the registry or the registry is unreachable. Recreate is a deployment strategy that stops the old component before replacing it with a new one. So the replacement can’t proceed until the new image has been pulled.

From 03:01:48 to 03:03:29 on October 11, a component using Recreate was down for about 1 minute and 40 seconds. The logs showed failed to resolve reference … not found. That message made the image specification seem like the likely culprit, but the image was in the registry. The problem was the connection to the registry.

At around 00:22 on October 12, a prefetch pod—a Kubernetes unit for running an application—failed to pull the image before deployment, blocking three GPU-backed deployments. The pod finished pulling the 11.85 GB image at 00:31:51, while it was being deleted. The pull took 6 minutes and 49 seconds, so it wasn’t ready in time for the deployment decision.

From 16:11 to 16:17 that same day, a pull took about 6 minutes. But because this deployment used RollingUpdate, a strategy that replaces components gradually, there was no downtime. Another pull took about 45 seconds at 22:52.

At 09:47 on October 13, a component using Recreate failed to pull the image with not found, and the service stopped accepting requests for about a minute. It entered ErrImagePull at 09:47:44, then succeeded in 4.8 seconds on a retry 14 seconds later. It was Running by 09:48:16. The same kind of incident happened six times that day.

Which Connection Tests Can Help Narrow Down the Cause?

I measured connectivity in four stages, from two production nodes to the registry endpoint: TCP connect, GET /v2/, token retrieval, and a HEAD request for the manifest. The manifest contains an image’s configuration, and HEAD is an HTTP request that checks the response without retrieving the content. I ran each test 30 times, with a five-second timeout per attempt.

On the two production nodes, TCP connect succeeded 21 out of 30 times. About 30% of attempts could not connect. Errors included dial tcp …:443: i/o timeout and DeadlineExceeded.

There were no failures at any of the four stages on the other nodes or in the development pod. This difference showed that the not found error could not be explained by a missing image alone: at times, requests were timing out on the route to the registry, preventing the image from being fetched. The root cause of the network path issue is still unknown, and the investigation is ongoing.

Avoid Pulling an Image That’s Already Present with IfNotPresent

The first change was to switch imagePullPolicy (the image pull policy) from Always to IfNotPresent. With Always, Kubernetes contacts the registry every time it recreates a pod. From 02:21 to 03:58 on the 12th, I updated 31 workloads. Each reported already present, and none restarted.

However, tags can be overwritten. As part of the same update, I pinned each workload to the digest (the value that identifies an image) of the image currently running. I’m not including the digest values in this article.

This avoids a pull only when the pod is scheduled on a node that already has the image. If the image isn’t on the node, it still needs to be pulled. Also, every configuration change recreates the pod. IfNotPresent alone doesn’t guarantee safety, so pin the image that’s running and check that it’s available on the node where the pod will be scheduled.

Preload Images onto Target Nodes Before Recreate

The second mitigation is to preload images onto the target nodes before a Recreate deployment. I run one preload pod at a time and keep it until the download is complete. In one case, preloading took 6 minutes and 37 seconds, and no image download was needed during the deployment.

RollingUpdate does not require preloading. When a download took about 6 minutes, from 16:11 to 16:17 on 10-12, there was no downtime. Whether waiting for an image download causes downtime depends on the deployment strategy.

If a download hits DeadlineExceeded, I stop and report it instead of repeatedly retrying. Repeating the same operation while the image remains unavailable can leave the deployment stuck. I report the issue as soon as it stalls, check the download path, and then decide what to do next.

Check for Image Pulls in Events

After making the change, check the pod’s events (the record of events that occurred). If you see already present on machine, that’s a clue that no pull occurred and the node used an image it already had.

Even if the error says not found, don’t immediately conclude that the image is missing. Check each step in order, from the TCP connection through the HEAD request for the manifest. Comparing a production node with one that hasn’t failed can reveal connection failures limited to a particular node, as in this case.

Changing to IfNotPresent and pre-pulling the image gave us a way to avoid pulls during deployment in some situations. Even so, we haven’t confirmed why the route to the registry times out or whether the issue is resolved. Rather than drawing a conclusion from the words not found alone, we continue operating while checking image availability and the route’s response separately.

Key takeaways

  • Confirm that the image exists in the registry before treating not found as a missing image.
  • Measure TCP connect, GET /v2/, token retrieval, and HEAD for the manifest from production nodes.
  • Compare results with other nodes and development pods to locate the failing stage.
  • Check pod events for already present on machine to confirm whether an image pull occurred.
  • For Recreate, preload the image on target nodes; if retrieval reaches DeadlineExceeded, stop the rollout and notify.

Top comments (0)