sungsoo / sungsoo.github.io

Sung-Soo Kim's Blog
30 stars 8 forks source link

analysis: How to fix ErrImgePull and ImagePullBackoff #30

Open sungsoo opened 1 year ago

sungsoo commented 1 year ago

How to fix ErrImgePull and ImagePullBackoff

Article Source


Kubernetes pods sometimes experience issues when trying to pull container images from a container registry. If an error occurs, the pod goes into the ImagePullBackOff state.

When a Kubernetes cluster creates a new deployment, or updates an existing deployment, it typically needs to pull an image. This is done by the kubelet process on each worker node. For the kubelet to successfully pull the images, they need to be accessible from all nodes in the cluster that match the scheduling request.

The ImagePullBackOff error occurs when the image path is incorrect, the network fails, or the kubelet does not succeed in authenticating with the container registry. Kubernetes initially throws the ErrImagePull error, and then after retrying a few times, “pulls back” and schedules another download attempt. For each unsuccessful attempt, the delay increases exponentially, up to a maximum of 5 minutes.

To identify the ImagePullBackOff error: run the kubectl get pods command. The pod status will show the error like so:

NAME        READY    STATUS              RESTARTS    AGE
my-pod-1    0/1      ImagePullBackOff    0           2m34s

We’ll provide best practices for diagnosing and resolving simple cases of these errors, but more complex cases will require advanced diagnosis and troubleshooting, which is beyond the scope of this article.

ImagePullBackOff and ErrImagePull Errors: Common Causes

CAUSE | RESOLUTION -- | -- Pod specification provides the wrong repository name | Edit pod specification and provide the correct registry Pod specification provides the wrong image name, or an unqualified image name | Edit pod specification and provide the correct image name Pod specification provides an invalid tag, or fails to provide a tag | Edit pod specification and provide the correct tag. If the image does not have a latest tag, you must provide a valid tag Container registry is not accessible | Restore network connection and allow the pod to retry pulling the image The pod does not have the appropriate credentials to access the image | Add a Secret with the appropriate credentials and reference it in the pod specification