Home > Enterprise >  How do I deploy a local docker image to minikube?
How do I deploy a local docker image to minikube?

Time:04-08

I have some images on my local docker instance, one of which is named door_controls:

>docker image ls
REPOSITORY                    TAG       IMAGE ID       CREATED        SIZE
door_controls                 latest    d22f58cdc9c1   3 hours ago    1.12GB
[...]

This image is also deployed to my minikube instance:

>minikube ssh -- docker image ls
door_controls                             latest    d22f58cdc9c1   3 hours ago     1.12GB
[...]

(It is also clear to me that these are different docker daemons, because the one on minikube also lists the k8s daemons). The documentation (and this canonical Stackoverflow answer) suggests that

minikube image load door_controls
minikube kubectl run door-controls --image=door_controls --port=7777

is the way to deploy this image from the command line, but the event log tells me something failed along the way:

Events:
  Type     Reason     Age                From               Message
  ----     ------     ----               ----               -------
  Normal   Scheduled  59s                default-scheduler  Successfully assigned default/door-controls to minikube
  Normal   Pulling    17s (x3 over 59s)  kubelet            Pulling image "door_controls"
  Warning  Failed     16s (x3 over 57s)  kubelet            Failed to pull image "door_controls": rpc error: code = Unknown desc = Error response from daemon: pull access denied for door_controls, repository does not exist or may require 'docker login': denied: requested access to the resource is denied
  Warning  Failed     16s (x3 over 57s)  kubelet            Error: ErrImagePull
  Normal   BackOff    1s (x3 over 57s)   kubelet            Back-off pulling image "door_controls"
  Warning  Failed     1s (x3 over 57s)   kubelet            Error: ImagePullBackOff

In the classic tradition of invoking commands I don't understand in the hope that it fixes the problem, I have followed the advice of another answer and tried setting the docker daemon to minikube's:

>eval $(minikube -p minikube docker-env)
//these aren't echoed by the shell of course
export DOCKER_TLS_VERIFY="1"
export DOCKER_HOST="tcp://127.0.0.1:54664"
export DOCKER_CERT_PATH="/Users/airza/.minikube/certs"
export MINIKUBE_ACTIVE_DOCKERD="minikube"

It seems as though the default configuration wants TLS enabled (from localhost to localhost?) but I am not sure how to turn it off or how to add valid TLS from localhost to localhost in the first place.

It is also not clear if this is even the issue or if something else is. Is my nomenclature for the image wrong? Do I need to specify a repo? Why does this image not deploy?

CodePudding user response:

Minikube comes with its own docker daemon and not able to find images by default, the below works in my local env, i noticed the first step is already done and looks like the the image is still being pulled, step-2 might solve the problem below.

  1. Set the environment variables with eval $(minikube docker-env), i see you have set this already.
  2. Set ImagePullPolicy to Never in order to use local docker images with the deployment, this will ensure that the image is not pulled from docker repo.

you can try running the below yaml on your cluster for your use-case.

apiVersion: v1
kind: Pod
metadata:
  name: test
spec:
  containers:
    image: door_controls
    name: door_controls
    imagePullPolicy: Never
    ports:
      - containerPort: 7777

blog article: https://medium.com/bb-tutorials-and-thoughts/how-to-use-own-local-doker-images-with-minikube-2c1ed0b0968

  • Related