-
Notifications
You must be signed in to change notification settings - Fork 4.8k
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
Proxy cache #8082
Comments
@michmike Is this referring to deploying a worker instance close to the edge nodes functioning specifically as a local registry mirror for a central Harbor and have the edge daemons pointing to it for local pulls? or is Harbor being used as proxy cache to pull from other registries like Docker hub and such? I mean is this this linking Harbor instances or w/ rest of the registry ecosystem. somethings to think about
|
@michmike our need is that we don't pull Images from "registry-1.docker.io" (from Docker hub in Internet) but from internal Harbor Register which will act as Proxy/Cache ( for example this Option is available in Nexus 3), which will Cache and if not cached pull Images from Docker hub and provide to user. |
proxy cache is a feature of registry v2. this is what i meant - https://mtijhof.wordpress.com/2018/07/23/using-nexus-oss-as-a-proxy-cache-for-docker-images/ |
we of course don't have to restrict the Harbor capabilities, so it could pull images as a cache from any type of replication target we can support |
The pull through proxy only works for docker hub, it doesn't work for other registry repository. |
@stonezdj yes it seems the docker registry's own proxy mechanism still only works for docker hub. There's a pr on supporting other self hosted registries but still unmerged after 2 years |
PRD: |
As docker hub is soon enforcing strict image pull limits this feature is very important I think. https://www.docker.com/blog/scaling-docker-to-serve-millions-more-developers-network-egress/ |
Is there anyway to configure harbor 2.1 as a transparent docker hub mirror? I can only make 2.1 pull from the upstream by doing things like this |
@bagel-dawg The name of the Harbor project is literally |
@jgallucci32 Thanks, I actually got it working. It seemed that I was running into this issue with the Host header. The redirect kept occurring over and over again until it failed, and then docker would failback to the the non-mirror address. |
@bagel-dawg @jgallucci32 For example, I tried to pull the busybox image from my docker side and I can see HTTP requests in Harbor's proxy.log. so I think the registry-mirror setting in docker-client is correct.
Thanks |
@hwchiu The first 2 lines look correct. You get HTTP/401 for You will need to first verify your proxy cache is working by attempting a pull-through request like this
If that is successful, then try to get the manifest directly using a web browser with the DNS alias you use for the mirror
This will test if you can get to the image in the proxy cache using the DNS alias with the full path to the image. Unfortunately nginx logging in K8s is not very good (or at least I haven't figured out how to get good debugging yet) |
@jgallucci32 |
@jgallucci32 |
@hwchiu @bagel-dawg I did some refactoring to use map variables to make it more clear what you need to set and reduces the changes made. I also added an improvement where the DNS suffix can be used in the form of Harbor can act as both a transparent proxy and Private Registry for multiple repositories:
Modifications to
Please test this out and let me know if you run into any issues. |
@hwchiu @bagel-dawg I created a new issue (feature request) to track this and plan to work this into a PR for review #13579 |
Thanks for your help, I will run it again when I have the time and let you know if I have any issues. |
As shown by @jgallucci32, you could rewrite the
But this could fail if your nginx reverse proxy runs on a different port than the docker client uses to connect to it. In my example, my nginx runs at port 443 inside the container, but the port is mapped to 5000 on the host ( To fix this, we can just use the variable
|
I've tried so setup a transparent registry with Harbor 2.3.2 and editing the nginx.conf but it does not work. I always get this error message
my modified nginx.conf: https://gist.github.com/aSauerwein/424ac58e13c7aadd619b3c75461e555f debugging with curl shows me that the |
Hello all, just an update with the code for nginx that enabled us to use Harbor as a dockerproxy with containerd and docker. We are using NGINX helm chart, and added the following in the http:
Added after the following annotations on the proxy ingress:
Hope it helps |
Ran into the authenticate issue with both |
I am also seeing 401 unauth when trying to use docker-io.docker-registry.mydomain.local like described above. |
If anyone is still looking, here is an approach based of @jgallucci32 and @ricardojdsilva87 with no if's:
How to use:
If 'harbor.local' is not a good suffix for you, make sure you change it in the hosts file as well as in the nginx configuration at |
If anybody has issues with their non-nginx-based ingress controller, welcome to this simple chart. Thanks for the inspiration: |
EDIT 20240528: Please see my comment below with an updated solution @pedroosorio Thank you for your solution for this problem. I've made one slight modification to better handle images like
Without the extra line that I added, I was having issues pulling "official images" that don't have a publisher name, like
The line I added makes pulling official images work as expected:
|
The following is a further modification of @pedroosorio 's solution that adds the capability to bypass the mapping and rewriting process for certain domains. I needed both transparent proxy caches and the ability to upload to other projects, but I had issues with the Unfortunately I did have to use an
|
Hi all, I experimented with this today, and found that this configuration working to me:
map $host $harbor_project {
default 0;
~^harbor.example.com$ 0;
~^(?<project>.+).example.com$ $project;
}
map "$harbor_project#$request_uri" $harbor_registry_uri {
default $request_uri;
"~^0#.*$" $request_uri;
"~^.+#/v2/_catalog.*$" $request_uri;
"~^.+#/v2/(.+)(/tags/list.*)$" /v2/$harbor_project/$1$2;
"~^.+#/v2/(.+)(/blobs/uploads.*)$" /v2/$harbor_project/$1$2;
"~^.+#/v2/([^/]+)(.*)$" /v2/$harbor_project/library/$1$2;
"~^.+#/v2/([^?]+)(.*)$" /v2/$harbor_project/$1;
}
map $args $harbor_args{
default $args;
~^(?<arg_prefix>.*scope=repository%3A)(?<arg_suffix>.*)$ $arg_prefix$harbor_project%2F$arg_suffix;
}
map $upstream_http_www_authenticate $harbor_authenticate_header {
default $upstream_http_www_authenticate;
~^(?<header_prefix>.*http.+//).*(?<header_suffix>/service/token.*)$ $header_prefix$http_host$header_suffix;
}
rewrite ^/v2/(.+)$ $harbor_registry_uri break;
proxy_hide_header Www-Authenticate;
add_header Www-Authenticate $harbor_authenticate_header always;
set $args $harbor_args; many thanks to you folks for provided snippets! <3 |
I have encountered the same problem as him. If you want to push to a non-proxy cache project using project.domain.example, something with /blob/uploads dont work. Anyone has resolved this issue ? |
enable proxy cache for Harbor.
This is very useful in situations of intermittent network connectivity where you still need access to local images. the expectation is that the network will go off in ROBO or IoT scenarios
Of course, the standard use case of reducing redundant image pulls across the network applies here
The text was updated successfully, but these errors were encountered: