How do I avoid `ErrImagePull` when using Kubernetes file, local docker image and `kubectl apply`?

7/14/2019

I have this that is working...

# Set docker env
eval $(minikube docker-env)

# Build image
docker build -t jrg/hw .

# Run in minikube
kubectl run hello-world --image=jrg/hw:latest --image-pull-policy=Never --port=8080
kubectl expose deployment hello-world --type=NodePort --name=hello-service

I can access the endpoint just as I expect. Now I am trying to use a .yml file to deploy like this...

apiVersion: v1
kind: Pod
metadata:
  name: hello-world-dev
  labels:
    purpose: simple
spec:
  containers:
  - name: hello-world-dev-container
    image: jrg/hw:latest
    env:
    - name: WORKING
      value: "Yup Working"

But when I run kubectl apply -f k8s/ineject/dev.envvars.yml I get...

NAME                           READY   STATUS         RESTARTS   AGE
hello-world-7d87b8ddd5-gqr8k   1/1     Running        1          2d22h
hello-world-dev                0/1     ErrImagePull   0          6s

So why can one see my local docker to get the image and 1 has an issue?

-- Jackie
docker
kubernetes

1 Answer

7/15/2019

In the docs regarding Pre-pulling Images we can read:

By default, the kubelet will try to pull each image from the specified registry. However, if the imagePullPolicy property of the container is set to IfNotPresent or Never, then a local image is used (preferentially or exclusively, respectively).

Also please see other options with imagePullPolicy in Container Images docs.

The imagePullPolicy and the tag of the image affect when the kubelet attempts to pull the specified image.

  • imagePullPolicy: IfNotPresent: the image is pulled only if it is not already present locally.

  • imagePullPolicy: Always: the image is pulled every time the pod is started.

  • imagePullPolicy is omitted and either the image tag is :latest or it is omitted: Always is applied.

  • imagePullPolicy is omitted and the image tag is present but not :latest: IfNotPresent is applied.

  • imagePullPolicy: Never: the image is assumed to exist locally. No attempt is made to pull the image.

-- Crou
Source: StackOverflow