How to use local docker images with microk8s?

3/22/2019

I have been using minikube to test Kubernetes locally. In minikube, we can use local docker images by using eval $(minikube docker-env) command.

I started to explore microk8s. Installed microk8s using snap on my machine running on Ubuntu 18.

Is there any way to use local docker images with microk8s like we use minikube for testing and development other than creating local docker registry?

microk8s.docker command is also not working, it's showing:

Command 'microk8s.docker' not found, but can be installed with:

snap install microk8s

but its already installed.

-- techrider
docker
kubernetes
microk8s
minikube

2 Answers

2/22/2020

microk8s has a private registry which can be used for this purpose.

You must enable the registry prior, with the following command

$ microk8s.enable registry

The registry maps the traffic to port 32000, so you will have to push your docker image to the registry. If the image is already present in local you can use docker tag command. $docker tag localhost:32000/ $docker push localhost:32000/.

use https://microk8s.io/docs/registry-built-in for more information.

-- Naveen Kulkarni
Source: StackOverflow

4/2/2019

Unfortunately you did not provide microk8 version and your steps.

I supposed that you used sudo snap install microk8s --classic command to install. Currently it will download v1.14.0.
You can check your version using snap info microk8s

Version 1.14.0 introduced changes in microk8s.daemon-docker and change it to microk8s.daemon-containerd. Due to this change microk8s cannot execute docker commands. Microk8s contains daemon-docker between versions 1.11 and 1.13.

If you are used to use docker install microk8s v1.13 by sudo snap install microk8s --classic --channel=1.13/stable

For future use:

1) Install microk8s - sudo snap install microk8s --classic --channel=1.13/stable (if still want use docker)

2) Make sure that microk8s is started - microk8s.start (you can stop it by microk8s.stop)

3) Check what services are running by - microk8s.inspect

4) Commands in microk8s differs prefix, i.e instead of - kubectl get all --all-namespaces you need to use microk8s.kubectl get all --all-namespaces (later you can use allias to chage it)

5) You can create image via Dockerfile using microk8s.docker build . (don't forget to have Dockerfile and "." on the end of the command).

You can always check Microk8s documentation

-- PjoterS
Source: StackOverflow