Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ImagePullBackOff local repository with Minikube

I'm trying to use minikube and kitematic for testing kubernetes on my local machine. However, kubernetes fail to pull image in my local repository (ImagePullBackOff).

I tried to solve it with this : Can not pull docker image from private repo when using Minikube

But I have no /etc/init.d/docker, I think it's because of kinematic ? (I am on OS X)

EDIT :

I installed https://github.com/docker/docker-registry, and

docker tag local-image-build localhost:5000/local-image-build

docker push localhost:5000/local-image-build

My kubernetes yaml contains :

spec:
  containers:
  - name: backend-nginx
    image: localhost:5000/local-image-build:latest
    imagePullPolicy: Always

But it's still not working... Logs :

Error syncing pod, skipping: failed to "StartContainer" 
for "backend-nginx" with ErrImagePull: "Error while pulling image: 
Get http://127.0.0.1:5000/v1/repositories/local-image-build/images: 
dial tcp 127.0.0.1:5000: getsockopt: connection refused

EDIT 2 :

I don't know if I'm on the good path, but I find this :

http://kubernetes.io/docs/user-guide/images/

But I don't know what is my DOCKER_USER...

kubectl create secret docker-registry myregistrykey --docker-server=DOCKER_REGISTRY_SERVER --docker-username=DOCKER_USER --docker-password=DOCKER_PASSWORD --docker-email=DOCKER_EMAIL

EDIT 3

now I got on my pod :

Failed to pull image "local-image-build:latest": Error: image library/local-image-build not found
Error syncing pod, skipping: failed to "StartContainer" for "backend-nginx" with ErrImagePull: "Error: image library/local-image-build not found"

Help me I'm going crazy.

EDIT 4

Error syncing pod, skipping: failed to "StartContainer" for "backend-nginx" with ErrImagePull: "Error response from daemon: Get https://192.168.99.101:5000/v1/_ping: tls: oversized record received with length 20527"

I added :

EXTRA_ARGS='
    --label provider=virtualbox
    --insecure-registry=192.168.99.101:5000

to my docker config, but it's still don't work, the same message....

By the way, I changed my yaml :

 spec:
      containers:
      - name: backend-nginx
        image: 192.168.99.101:5000/local-image-build:latest
        imagePullPolicy: Always

And I run my registry like that :

docker run -d -p 5000:5000 --restart=always --name myregistry registry:2
like image 670
Xero Avatar asked Aug 16 '16 15:08

Xero


People also ask

How do I fix error ImagePullBackOff?

To resolve it, double check the pod specification and ensure that the repository and image are specified correctly. If this still doesn't work, there may be a network issue preventing access to the container registry. Look in the describe pod text file to obtain the hostname of the Kubernetes node.

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.

What does ImagePullBackOff mean in Kubernetes?

So what exactly does ImagePullBackOff mean? The status ImagePullBackOff means that a Pod couldn't start, because Kubernetes couldn't pull a container image. The 'BackOff' part means that Kubernetes will keep trying to pull the image, with an increasing delay ('back-off').


6 Answers

Use the minikube docker registry instead of your local docker

https://kubernetes.io/docs/tutorials/stateless-application/hello-minikube/#create-a-docker-container-image

Set docker to point to minikube

eval $(minikube docker-env)

Push to minikube docker

docker build -t hello-node:v1 .

Set your deployment to not pull IfNotPresent

K8S default is set to "Always" Change to "IfNotPresent"

imagePullPolicy: IfNotPresent

Related Issue

like image 80
Doug Avatar answered Oct 05 '22 17:10

Doug


I think I solved by doing

minikube start --vm-driver="virtualbox" --insecure-registry="$REG_IP":80

instead of just

minikube start

$REG_IP is :

REG_IP=docker-machine ip registry

Source

like image 40
Xero Avatar answered Oct 05 '22 16:10

Xero


If you're using --vm-driver=none, you'll need to set imagePullPolicy to Never.

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

like image 42
Homer6 Avatar answered Oct 05 '22 16:10

Homer6


in my case, I had to do the following steps.

$ eval $(minikube docker-env)

$ minikube config set driver virtualbox

$ minikube start

like image 43
Shree Prakash Avatar answered Oct 05 '22 18:10

Shree Prakash


Check this great article: How to Run Locally Built Docker Images in Kubernetes

My Environment

  • OS: Debian
  • Version: 11 (Bullseye)
  • Minikube: v1.24.0
  • Kubectl: v1.22.4
  • Docker: 20.10.5+dfsg1

It covers all wrong image stages and workarounds.

Stages

ErrImagePull

Edit deployment.yaml and add imagePullPolicy: Never:

apiVersion: apps/v1
kind: Deployment
metadata:
  name: my-local-deployment
spec:
  template:
    metadata:
      name: my-pod
    spec:
      containers:
      - name: my-container
        image: my-local-image    # The one built and tagged locally
        imagePullPolicy: Never   # So it doesn't pull the image from remote registry

ErrImageNeverPull

Run: eval $(minikube -p minikube docker-env)

that outputs environment variables needed to point the local Docker daemon to the minikube internal Docker registry

Finally

Rebuild the image, to install it in minikube registry:

docker build . -t my-image

like image 35
Felix Aballi Avatar answered Oct 05 '22 18:10

Felix Aballi


As per the kubernetes documentation here: https://kubernetes.io/docs/concepts/containers/images/#imagepullpolicy-defaulting

If you use the latest tag for deployment then it will try to pull image. I was able to deploy service with v1 tag after following steps on WSL-2

  1. eval $(minikube -p minikube docker-env)
  2. minikube start
  3. docker build --tag=my-service:v1 .
  4. kubectl create deployment my-service --image=my-service:v1
  5. kubectl expose pod "my-service" --type=NodePort --port=8080
  6. minikube service my-serivce
like image 37
rubalvjaiswal Avatar answered Oct 05 '22 17:10

rubalvjaiswal