Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

kubectl run from local docker image?

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
like image 252
mathtick Avatar asked Aug 13 '18 16:08

mathtick


People also ask

How do I use local image in kubectl?

Kubernetes use local docker image is nothing but create Kubernetes image locally and deploy the same on Kubernetes cluster locally; the first step is to deploy our application on Kubernetes to build the docker image. Next, we need to use minikube to run the Kubernetes in our local environment.

Can minikube use local Docker image?

You can load a Docker image from your local machine into the Minikube cluster with the following command. After loading the image to your Minikube cluster, you can restart your Pods of the above Deployment and notice that they are starting fine. But it can get even easier.


1 Answers

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
like image 109
Marcin Romaszewicz Avatar answered Oct 05 '22 20:10

Marcin Romaszewicz