How to Debug basic kubernetes image pull failure

Advertisements

I am trying to learn how to deploy my application to Kubernetes, and am using the local docker desktop kubernetes instance. I have built my container image and have run a script that generates a deployment file for me. Essentially when I manually deploy it works but when I use a deployment.yml file it fails and I am at a loss as to understand why this is the case and diagnose what is wrong.

I’ve clearly missed something basic but how can I work out what the difference is between the commands and why it is failing?

When I run this command to apply the deployment yaml:

kubectl apply -f .\deployment.yml

The pod fails to start without being able to pull the image, but when I run what I think is the same command with a manual deployment like this:

kubectl create deployment manual-test3 --image=rts.api:1.0.0.1

It seems to work fine, so far the best logs I can find are using this command – the output for the manual deployment is here:

kubectl get events --field-selector involvedObject.name=manual-test3-87dbcbf66-dp7zt
LAST SEEN   TYPE     REASON      OBJECT                             MESSAGE
42s         Normal   Scheduled   pod/manual-test3-87dbcbf66-dp7zt   Successfully assigned default/manual-test3-87dbcbf66-dp7zt to docker-desktop
37s         Normal   Pulled      pod/manual-test3-87dbcbf66-dp7zt   Container image "rts.api:1.0.0.1" already present on machine
35s         Normal   Created     pod/manual-test3-87dbcbf66-dp7zt   Created container rts-api-7xrfz
34s         Normal   Started     pod/manual-test3-87dbcbf66-dp7zt   Started container rts-api-7xrfz

Running the same command for the failing deployment clearly states that it cant log in to get the image. However as this is all local I’m not sure what I would log in with ( docker desktop is logged in) and as far as I can tell it should be the same as the working manual deployment.

kubectl get events --field-selector involvedObject.name=rts-api-76759d7d7b-67ctg
LAST SEEN   TYPE      REASON      OBJECT                         MESSAGE
2m51s       Normal    Scheduled   pod/rts-api-76759d7d7b-67ctg   Successfully assigned default/rts-api-76759d7d7b-67ctg to docker-desktop
70s         Normal    Pulling     pod/rts-api-76759d7d7b-67ctg   Pulling image "rts.api:1.0.0.1"
68s         Warning   Failed      pod/rts-api-76759d7d7b-67ctg   Failed to pull image "rts.api:1.0.0.1": Error response from daemon: pull access denied for rts.api, repository does not exist or may require 'docker login': denied: requested access to the resource is denied
68s         Warning   Failed      pod/rts-api-76759d7d7b-67ctg   Error: ErrImagePull
46s         Normal    BackOff     pod/rts-api-76759d7d7b-67ctg   Back-off pulling image "rts.api:1.0.0.1"
58s         Warning   Failed      pod/rts-api-76759d7d7b-67ctg   Error: ImagePullBackOff

The deployment.yml file is here, but as far as I can tell it should be identical to the manual deployment.


apiVersion: apps/v1
kind: Deployment
metadata:
  name: rts-api    
spec:
  replicas: 1
  selector:
    matchLabels:
      app: rts-api
  template:
    metadata:
      labels:
        app: rts-api
    spec:
      containers:
      - name: rts-api
        image: rts.api:1.0.0.1
        imagePullPolicy: Always
   

Thank you for any help / insight.

>Solution :

Essentially when I manually deploy it works but when I use a
deployment.yml file it fails

That’s because you specified

imagePullPolicy: Always in your deployment.

If you check docs:

Always

every time the kubelet launches a container, the kubelet queries the container image registry to resolve the name to an image digest. If the kubelet has a container image with that exact digest cached locally, the kubelet uses its cached image; otherwise, the kubelet pulls the image with the resolved digest, and uses that image to launch the container.

Since there is not container registry, it can’t check image digest.

Change policy to IfNotPresent or Never

Leave a ReplyCancel reply