-
Notifications
You must be signed in to change notification settings - Fork 74
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
Extending Spegel to Nomad Docker clusters #303
Comments
We will be adding more bootstrappers as part of the work to integrate with k3s, which means that in theory it should be possible. Are you planning on using the KV store in Consul to share the public key? Depending on how your container platform is designed it might be more interesting for you to import Spegel as a library in the same way that k3s will? |
I only briefly looked at the kubernetes bootstrapping code so I may be being naive here. I was thinking a similar leader election process would work with Consul as the KV backend for locking and choosing the initial leader. I'm using Nomad and Consul, so was looking to run Spegel as a system job on Nomad to handle caching and sharing existing docker images across nodes. I did see some mention of Spegel in k3s the other day, but didn't dive into the implementation details. Given that you say it will be embedded as a library it probably wouldn't be right for me unless Hashicorp were to accept it into their project.
What bootstrapping methods are you planning for the k3s integration? |
I am back from the holidays now so should be a bit faster to respond. I think that adding support for Nomad would be great to expand the user base. It has been a while since I have used Nomad so had a look at the different container drivers out there. Before we dive into looking at bootstrappers we need to verify that one of these drivers will work with Spegel. The main issue is that Spegel relies on CRI for the mirror configuration to work. Check how Containerd implements its CRI server. The Containerd driver does not implement any support for CRI mirror configuration. It looks like this is also the case with the podman driver. @stenh0use have i missed some driver that you are using? I think we need to prove that Spegel will work on your Nomad setup before looking more at how to bootstrap Spegel. |
Yeah sane thought process there, I'm using the builtin docker driver. The driver interfaces with So after looking through There are still 20 outstanding issues attached to this issue for "fix remaining failing tests with the containerd image store" so hopefully it's not too far away from graduating from experimental to supported. |
Oh there is a third driver, how did i miss the built in driver? I had a look at how docker does registry mirroring, and it is limited. Configuring the Docker daemon is simple enough, and just requires a restart of the daemon. The problem is that this will first of all mirror all image pulls, meaning it will not be possible to exclude registries. Second of all Docker does not include any reference to the original registry in its requests, which makes resolving tags impossible. https://docs.docker.com/docker-hub/mirror/#configure-the-docker-daemon I am a bit stuck right now. We need to figure out how to enable tag resolving for Docker. Spegel would work on Nomad with the Docker driver if we figure that out. |
The only remaining issues are for the (somewhat deprecated) classic builder, and these issues are the cache not working, but the build works. I guess what I'm saying is, give this a try, tell us if something breaks :) Here's how to enable the containerd image store feature https://docs.docker.com/storage/containerd/ |
@rumpl thanks for the input, I am unsure if using Containerd image store would solve this problem. Spegel relies on Containerds CRI implementation to supporting registry mirroring. Using another Snapshotter would not solve this problem as the image would still be pulled without the CRI API. |
I looked at the docker source code and It looks like it is using a different ImageService when https://github.com/moby/moby/blob/9cebefa7175c849a0fb89be9a2c0c23755afb3e2/daemon/daemon.go#L1089-L1097 Although I'm not entirely sure if this solves the problem? |
Good news, after a lot of tinkering and going through code I think I have figured it out. Using the Containerd snapshotter together with configuring the mirror in I think we should be able to move forward with this feature. The next step is to determine the best method of running Spegel in Nomad. The simplest should be to run it in a Docker container. |
Great news and thanks for tinkering! I think I'm ok with the downside that it's not possible to limit the mirroring of specific registries so long as it can mirror gcp gcr/ar registries. The best way to run it I would think is in a Docker container as system job, it's similar to a DaemonSet. |
I need to setup a test Nomad cluster to see how networking works, among other things. After that I should be able to figure out how bootstrapping should look like. |
Can I help you some how? I was thinking either host or bridge network would work with a static port as a system job, similar to how you've done it in kubernetes. The metrics port can be dynamic and registered as a service in consul for prometheus service discovery. https://developer.hashicorp.com/nomad/docs/job-specification/network#mode I have a WIP for hashistack in docker: https://github.com/stenh0use/hind I have locally updated the docker-ce version and was able to get
In its current state If you run I'll update the topic of this issue as we are talking about specifically docker and nomad. Edit: I got the snapshotter working in the dind setup linked above, I just merged into main the change. |
If I can help don’t hesitate to ping me, I can either help or delegate internally :) |
@stenh0use a lot has changed in Nomad since the last time I touched it, a lot for the better. I was thinking if we even need Consul to make bootstrapping work? Could we not instead use the Then as you stated using a static port for the registry should be fine for the mirror to work. |
I was thinking the same thing over the weekend. I do not think we should involve Consul, if we need Consul kv type functionality Nomad implemented this a few releases ago. https://developer.hashicorp.com/nomad/api-docs/variables/variables Regarding If Spegel only needs an initial list of IPs to create the cluster and it handles all of the leader election itself then we might not need to complicate a nomad deployment leader election. https://developer.hashicorp.com/nomad/docs/job-specification/template#change_mode Otherwise I was looking at something like this: https://github.com/razorpay/metro/blob/5eb8881adbf5da6d387d1f4659916c83028dfb06/pkg/leaderelection/candidate.go#L56 Edit: to answer the question about template value updates, you can set a restart policy when the template changes. You can set it |
Leader election is not actually needed. The reason it is used in Kubernetes is to make sure all nodes bootstrap with the same instance. We should be able to do the same without it using the identify protocol to distribute public keys. I tried running Hind on Linux and I get some build issues, will have to look at why it will not build for x86 or I will just find and alternative method of running a local multi node Nomad cluster. |
Ok good to know about the Leader election we can definitely pass in any the same node address on startup. I'm wondering how would bootstrapping work when a new node joins the cluster or a node fails? Can it then join the cluster based on any other node address? Given the statelessness I guess if we get into a split cluster situation we can always stop and restart the job. That is annoying about hind, what is the error you are getting? I will spin up a linux box look into fixing it, a friend said the said to me today. I have only tested hind on my laptop which is x86 Macbook using colima 0.6.x, it also requires the docker host to be using cgroupv2. |
I have a working Nomad cluster running with Vagrant now, and managed to get Spegel running without a bootstrap. My plan is to create a draft PR with the instructions and then you can have a look at it and give feedback. Would that work for you? |
Thank you so much @phillebaba! Plan sounds great with the draft PR, let me know once you have that and I'll take a look. |
Is there any documentation or a rough guide of how you set this up to help with dind? |
@phillebaba thanks for the updates here. Apologies, life has got in the way and I'm yet to test the new changes. I made a rough nomad job file to get this working a while back based off the helm chart, but need more time to incorporate the changes. |
@RoryDoherty you might be better off creating a new issue. Your architecture and where the image is meant to live would need to be understood in order to answer that question. |
So I tested this out on Nomad, I wasn't able to get it working using bridge networking, but I was able to get it working using host networking. This is due to container IP address being advertised from the bootstrap server for the router to connect to. As everything is running on private addresses the peer routers can't be reached. This wouldn't be so much of a problem with overlay networking like calico and cilium. Alternatively, an option to configure an "advertised" address as well as the listen address might work? For now I think host networking should get the job done. When using bridge network
When using host network
I need to clean up my wip, but will post back here once I have a good reference. I mostly copied the helm chart but I'm still a little unsure as to how the "service" address would work in Nomad, and also what significance the "local" address has/should be configured. For a load-balanced "service" address, consul DNS would work well, but unfortunately, you can't register a nomad job as both a consul service and a nomad service. So to do the nomadService rendevous hashing for the bootstrap node selection nomad service discovery has to be used. |
Update here: I created a repo nomad-spegel with my work. It includes 3 options for leader election, nomadService with rendevous hashing, nomad kv locking and consul kv locking, and options to use nomad or consul as a service discovery backend. After doing a lot of testing I found The kv/locking with consul/nomad binary works well, but perhaps it might be nice integrate the consul/nomad kv functionality as an alternative bootstrapper at a later stage. For now what I have seems to work well. I do have some follow up questions / issues that I wasn't able to figure out.
Once the cluster is established does the cluster maintain leadership via gossip or does the bootstrap/id as something that only can be updated on startup? eg. if the cluster already exists can a peer bootstrap with any member of the cluster? I ask this as I am restarting all registries and forcing a new bootstrap process everytime the leadership changes. The benifit of this at least means that the cluster will never have split rings in the event nodes bootstrapped with different sets of hosts.
Click to expand logs
Click to expand logs
|
@rumpl do you know if there are any plans to fix this issue moby/moby#18818 as part of the containerd snapshotter work? I was able to pull non dockerhub images via spegel using nerdctl but but not with the docker daemon/cli. |
After reading a bunch of PRs/issues on the moby page, it doesn't look like the mirror issue ever progressed/doesn't look like the feature is on the cards given the age of the above issue (unless @rumpl can provide any insights or updates there?). The good news is though it's fairly straightforward to update the dockerd code to support private registry mirrors. I compiled a custom dockerd binary tonight with a change to support |
@phillebaba I saw the other issue recently opened #672. I did get Spegel working with nomad and dockerd. By default it only works with docker.io, but with as little as a one line change you can recompile dockerd to support Spegel in conjunction with the containerd snapshotter. Is there something I can do to help you there? Here is all the nomad work I did - https://github.com/stenh0use/nomad-spegel If anyone has any questions I’d be more than happy to help. |
This looks really good @stenh0use. One option is to add a link to your documentation to make things easier for others to find. I am a bit hesitant adding it to the official documentation without tests to validate that things will continue to work with Nomad. Maybe that is something that we can have in the future. |
I see that in your fork for Nomad, it’s mentioned that this whole setup will only work with images from docker.io. At the same time, in the .hcl file, I see the following configuration: registries = [ The project is very interesting, but it doesn’t make much sense if it only supports docker.io images. I really want to try your fork in out Nomad cluster. |
Hey @valafon, the registries you refer to are part of the Spegel configuration. I copied the same variables as the helm chart. What those values do is generate the configuration for When I did my initial work there was no way to configure the registry mirrors in See
and
When I validated that it could work with other registries this was the main branch at the time of my testing. https://github.com/moby/moby/blob/9d07820b221db010bf1bdc26ca904468804ca712/daemon/daemon.go#L208
This was hard coded, and simply updating that map with the desired registries / and re-compiling the This was back at the end of April/start of May last year, and the previous PR has not evolved, but it does look like there have been some code changes on |
The |
@valafon as far as I can tell they removed the registryhosts config and now use the containerd hosts dir to configure the mirrors. I could be wrong, haven't had time to test it. But if that is the case then yes it will support other mirrors out of the box. The only caveat to this is, it looks like this is in v28 milestone which hasn’t been released yet. https://github.com/moby/moby/blob/2c000b8ac4d1d2a653497615eb3973648b82cd6b/daemon/hosts.go |
I deeply appreciate the research you’ve done. I will wait for the release of Docker version 28 and test your fork in our Nomad cluster. I’ll be sure to share my feedback and the test results. |
I just compiled dockerd from the main branch, and it looks like they do now support using the containerd certs.d directory for mirrors. This is good news as that means Spegel will work with docker and private registries without needing to patch and compile. I would need to update my nomad job files to run spegel with docker v28 as this line below merges in the legacy config and seems to overwrite the configuration from the certs directory. Also I tested this with an old spegel version as that is what I last had working (v0.0.21). https://github.com/moby/moby/blob/2c000b8ac4d1d2a653497615eb3973648b82cd6b/daemon/hosts.go#L35
In addition, docker by default uses a different certs directory to containerd. They are using Also @phillebaba I was thinking terminology wise, this thread isn't necessarily Spegel support for Nomad, it's technically support for the docker daemon. |
Hey, I really love the simple implementation of this service, I am looking for something to back GCR / AR registries without the operational overhead of running redis and postgres and I think Spegel is exactly what I am looking for!
I'd like to extend this to non kubernetes docker clusters, would you be open to adding functionality so that Spegel can be bootstrapped without kubernetes? I had a quick look over the source code and could only see the need for kubernetes in the bootstrapping section. If I do the leg work would you be interested in working with me to integrate Consul based bootstrapping into Spegel?
The text was updated successfully, but these errors were encountered: