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.
Set the environment variables with eval $(minikube docker-env) Build the image with the Docker daemon of Minikube (eg docker build -t my-image . ) Set the image in the pod spec like the build tag (eg my-image ) Set the imagePullPolicy to Never , otherwise Kubernetes will try to download the image.
The following documentation explains how to use MicroK8s with local images, or images fetched from public or private registries. A familiarity with building, pushing and tagging container images will be helpful. These examples use Docker but you can use your preferred container tool chain.
You don't need specifically docker to run pods using docker images on kubernetes.
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.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With