Image showing 4 easy steps to use local docker images with Minikube

4 easy steps to use local docker images with Minikube

affiliate best offer

I have previously shared a short tutorial on Minikube, and while I was using it, I thought I would reuse my local images directly, without uploading and then downloading them again.

Two things I have tried (and didn’t work)

Import the images using ##@@10000@@##

I first cleaned the instances of minikube and start fresh to make sure that the is no collision.

kubectl run hdfs --image=fluxcapacitor/hdfs:latest --port=8989
kubectl run hdfs --image=fluxcapacitor/hdfs:latest --port=8989 imagePullPolicy=Never

And the output was :

NAME                    READY     STATUS              RESTARTS   AGE
hdfs-2425930030-q0sdl   0/1       ContainerCreating   0          10m

As you see, it get stuck on some status but it never reach the ready state.

Create a local registery

The idea here is to create a local registry and put my images into it. With that, I don’t need to upload then download my images.

That didn’t work either.

The solution

The solution was to use the eval $(minikube docker-env).

The steps are:

Step 1 : Set the environment variables

To set your environment variables, use the command :

eval $(minikube docker-env)

Step 2: Build the image with the daemon of minikube

To build the image use this command :

docker build -t my-image

Of source, replace my-image with your image name.

Step 3: Set the image in the kubernetes pod

Use the tag in the kubernetes pod. Eg: my-image

Step 4: Tell kubernetes not to download the image anymore

To achieve that, you need to use the imagePullPolicy to Never.

More information here: How to set imagePullPolicy to never.

Tips and pilfalls

Run the env command in all your terminals

Make sure you run the eval $(minikube docker-env) in all your terminal. You will have the environment variables in all of them.

If not, some of the commands my fail because of the lack of these variables.

If you close your terminal, rerun eval $(minikube docker-env)

Once you close your terminal, the environment variables are cleared.

If you then build your images, they won’t update in minikube. You will think that it is not working, but it is because the environment variables are not there.

Exit from minikube?

If you want to exit from minikube, run this command :

eval $(minikube docker-env -u)

Conclusion

This tutorial shows you how you can use your local image with minikube without uploading then downloading them.

Watchout for the pitfalls.

Once you have use your local images, you may want to expose the services ports to access them. This tutorial shows you how.

There are also a very interesting post on using a nice url for your application using a reverse proxy and nginx.

References

This readme

This stackoverflow post

You might also like these blog posts

Full Bright

Full Bright

A professional and sympathic business man.

Contact

Contact Us

To order one of our services, navigate to the order service page

Address

10 rue de Penthièvre,
75008 Paris

Email Us

hello at bright-softwares dot com

Open Hours

Monday - Friday
9:00AM - 05:00PM