How to use local docker images with microk8s?

15,849

Solution 1

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 <imageName:version> localhost:32000/<imageName:version>

$docker push localhost:32000/<imageName:version>.

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

Solution 2

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

Share:
15,849
Admin
Author by

Admin

Updated on June 11, 2022

Comments

  • Admin
    Admin almost 2 years

    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.

  • bjmc
    bjmc almost 5 years
    I found these docs microk8s.io/docs/working for more recent versions of microk8s.