kubectl run from local docker image?

8/13/2018

How to refer to the local image that exists?

kubectl run u --rm -i --tty --image my_local_image -- bash

Results in ImagePullBackOff and kubectl is obviously trying to pull from a remote repository instead of local register.

This answer is unhelpful, and the follow up refers to minikube and kubernetes.

Some event logs

Events:
  Type     Reason                 Age               From                         Message
  ----     ------                 ----              ----                         -------
  Normal   Scheduled              1m                default-scheduler            Successfully assigned u-6988b9c446-zcp99 to docker-for-desktop
  Normal   SuccessfulMountVolume  1m                kubelet, docker-for-desktop  MountVolume.SetUp succeeded for volume "default-token-q2qm7"
  Normal   SandboxChanged         1m                kubelet, docker-for-desktop  Pod sandbox changed, it will be killed and re-created.
  Normal   Pulling                23s (x3 over 1m)  kubelet, docker-for-desktop  pulling image "centos_postgres"
  Warning  Failed                 22s (x3 over 1m)  kubelet, docker-for-desktop  Failed to pull image "centos_postgres": rpc error: code = Unknown desc = Error response from daemon: pull access denied for centos_postgres, repository does not exist or may require 'docker login'
  Warning  Failed                 22s (x3 over 1m)  kubelet, docker-for-desktop  Error: ErrImagePull
  Normal   BackOff                9s (x5 over 1m)   kubelet, docker-for-desktop  Back-off pulling image "centos_postgres"
  Warning  Failed                 9s (x5 over 1m)   kubelet, docker-for-desktop  Error: ImagePullBackOff
-- mathtick
docker
kubernetes
macos

1 Answer

8/13/2018

Kubernetes Pods have an imagePullPolicy field. If you set that to Never, it will never try to pull an image, and it's up to you to ensure that the docker daemon which the kubelet is using contains that image. The default policy is IfNotPresent, which should work the same as Never if an image is already present in the docker daemon. Double check that your docker daemon actually contains what you think it contains, and make sure your imagePullPolicy is set to one of the two that I mentioned.

apiVersion: v1
kind: Pod
metadata:
  name: my-pod
spec:
  containers:
    - name: my-image
      image: local-image-name
      imagePullPolicy: Never
-- Marcin Romaszewicz
Source: StackOverflow