-
-
Notifications
You must be signed in to change notification settings - Fork 476
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Enhancement] Using "local" images from the host docker #19
Comments
Currently no way yet. But latest k3s ssupports custom containerd config so we could possibly create a local docker registry pushing to which should be trivial. cc @iwilltry42 |
A big YES to this feature request! |
As a quick and temporary solution I would suggest to add a
|
There is already a volume mount feature in the latest update. Checkout |
Just to give an update on this: while you can certainly preload the images like @Megzo mentioned, I'd like to have the images shared directly without the need for |
What about running a registry within k3s? Microk8s offers a similar feature out of the box: |
@runningman84 , I have the exact same idea. if @iwilltry42 has some time he can look into it. I think the best experience would be creating a local docker registry and forwarding port (5000) so that the user can push their images to this registry and the k3s container should be able to pull images with same prefix. For example: |
+1 being able to configure a local registry is a MUST HAVE |
Local registry would be a work-around for me -- ideally would be sharing the same images as the docker host (i.e. by volume mounting in something under /var/lib/docker - but that may not be possible) |
could kaniko be used to solve this issue as we can build an image without the dependency on docker daemon |
Both these solutions require you to store your code in multiple places. With
I like @iwilltry42 solution of trying to somehow allow Docker file format to work with containerd file formwat. Or what I think he's trying to get to. Ultimately, I think moby/moby#38043 needs to get merged in before we can easily achieve having docker images shared. |
So I just started working on this. UPDATE 1: I don't think that my original idea to simply share files, won't work, since the image storage formats differ too much and also people might use different storage drivers in docker, which would create the need to support all of them. I see those two options for now:
|
so we do this for our gitlab pipeline with k3s by mounting the docker volume script: |
Thanks for the input @kajanth. |
Came across another tool that might be interesting: https://github.com/containers/skopeo which supports OCI export. I haven't tried anything yet, but we might be able to mount the k3s OCI directory on the host and export Docker images via |
On first glance this looks pretty cool @silasb! |
Just to give you an update on this: I created a working version of an |
You can check out this release: https://github.com/rancher/k3d/releases/tag/v1.3.0-dev.0 |
@iwilltry42 this is awesome. I see that you are importing the images from the host (by saving to a tar) and then moving them to each worker via |
@iwilltry42 Thanks. By adding registry.yml:
If I understand correctly, the docker image I've created knows to pull from docker.io for missing images, the |
Hi,
Upd: |
Hi @bademux , thanks for your input 👍
You can use
Registry names have to match, so you have to use some way to resolve the registry name to |
Here straightforward solution how to share docker image pushed into localhost:5000 repository with k3d cluster Create registry Create file registries.yaml with content: mirrors:
"localhost:5000":
endpoint:
- http://k3d-registry.localhost:5000 Create Cluster with registry and expose port Now you can push |
It works! Thanks My file pod: apiVersion: v1
kind: Pod
metadata:
name: api-flask-pod
spec:
containers:
- name: flask-api
image: k3d-registry.localhost:5002/api_flask:v0.1
imagePullPolicy: IfNotPresent
ports:
- containerPort: 5001 |
Also works for me. Took me a while to figure
|
Is there any way to do this without create a new cluster? |
how k8s in docker for mac is able to to access local images? couldn't it be done in the same way? |
@MGReyes , the registries.yaml is translated to the containerd TOML config which cannot be hot-reloaded, so definitely a cluster restart would be necessary. We could look into adding a flag to |
@ciekawy DfD runs Kubernetes with Docker as the container runtime. K3s (which is the Kubernetes distro in k3d) uses plain |
And wouldn’t it be possible to provide some kind of proxy?
…On Thu, 17 Feb 2022 at 17:24, Thorsten Klein ***@***.***> wrote:
how k8s in docker for mac is able to to access local images? couldn't it
be done in the same way?
@ciekawy <https://github.com/ciekawy> DfD runs Kubernetes with Docker as
the container runtime. K3s (which is the Kubernetes distro in k3d) uses
plain containerd, so we cannot share the image repository.
—
Reply to this email directly, view it on GitHub
<#19 (comment)>, or
unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAVXJUEUV5BYLEQDP6Q3NPTU3UOMNANCNFSM4HJPBP5Q>
.
You are receiving this because you were mentioned.Message ID:
***@***.***>
|
Not sure what you mean by proxy in this context, but you can use a local registry. |
fwiw k3s supports the |
@mgoltzsche How would you setup that to work with K3D? Would it be possible to mount a volume inside K3D cluster to share local docker images with the cluster? |
To make the docker integration work, the
Here is how to run a k3s server (single node cluster) using docker directly: mkdir -p /var/lib/rancher/k3s /var/lib/kubelet /var/lib/cni
docker run --rm --privileged --network=host --pid=host \
--tmpfs=/run --tmpfs=/var/run \
--mount type=bind,src=/etc/machine-id,dst=/etc/machine-id \
--mount type=bind,src=/var/run/docker.sock,dst=/var/run/docker.sock \
--mount type=bind,src=/var/lib/docker,dst=/var/lib/docker,bind-propagation=rshared \
--mount type=bind,src=/var/lib/kubelet,dst=/var/lib/kubelet,bind-propagation=rshared \
--mount type=bind,src=/var/lib/cni,dst=/var/lib/cni \
--mount type=bind,src=/sys,dst=/sys \
--mount type=bind,src=/var/lib/rancher/k3s,dst=/var/lib/rancher/k3s,bind-propagation=rshared \
--mount type=bind,src="`pwd`",dst=/output \
-e K3S_KUBECONFIG_OUTPUT=/output/kubeconfig.yaml \
-e K3S_KUBECONFIG_MODE=666 \
rancher/k3s:v1.27.2-k3s1 server --docker However, I cannot make this work using k3d since it doesn't let me specify the mount propagation since it does not expose docker's k3d cluster create mycluster --servers=1 --agents=0 --k3s-arg='--docker@server:0' -v /var/run/docker.sock:/var/run/docker.sock -v /var/lib/docker:/var/lib/docker -v /var/lib/kubelet:/var/lib/kubelet -v /var/lib/cni:/var/lib/cni |
Thanks @mgoltzsche! |
@mgoltzsche In general, there is experimental support for using the containerd-snapshotter in Docker v24 - so we could give that a try at some püoint. |
@mgoltzsche @mgoltzsche Have you come up with any solution about using the k3s --docker argument on k3d ?
I have made 2 tries:
So i cannot connect to the node and see the pods. |
On my machine (Ubuntu) cluster creation using your commands succeeds but no pod/container starts afterwards due to a CNI error:
Adding the
The load balancer is not created since the option |
I ran into this issue as well (came up because I kept hitting docker.io rate limits), so created a custom registry that proxies all image requests to the host docker instance: https://github.com/ligfx/k3d-registry-dockerd I use it like so: configfile=$(mktemp)
cat << HERE > "$configfile"
apiVersion: k3d.io/v1alpha5
kind: Simple
registries:
create:
image: ligfx/k3d-registry-dockerd:v0.1
proxy:
remoteURL: "*"
volumes:
- /var/run/docker.sock:/var/run/docker.sock
HERE
k3d cluster create mytest --config "$configfile" It's also had the side effect of significantly speeding up cluster creation and pod rollout, which is nice! |
@ligfx Dude, I could kiss you. Your solution has saved me tons of time and reduced the pain of building a new cluster. Thanks a lot!! |
@ligfx this looks like a pretty smooth solution, thank you! - I wonder if we could tightly integrate this into k3d. |
@iwilltry42 That would be great. The only complaint I have about https://github.com/ligfx/k3d-registry-dockerd is that it makes it harder for me to find my own images when I run Do you plan to open a separate issue to track this feature request? |
@iwilltry42 I’m open to that. How do you envision that working? |
Tracking over here: #1555 |
It appears that since this is some form of "DinD" that the docker images built locally from the host are not visible to run in the k3s cluster.
Is there anywork around to this?
The text was updated successfully, but these errors were encountered: