dockerkubernetesdockerhubk3d

Getting rate limited when trying to create K3D cluster with local registry (registry image pulls from Dockerhub)


I'm getting a rate limiting issue when trying to spin up a K3D cluster via k3d cluster create MyCluster --servers 1 -p "8081:80@loadbalancer" -p "443:443@loadbalancer" --registry-create registry:0.0.0.0:80 because the image for the registry (docker.io/library/registry:2) is failing to pull due to rate limiting.

This is happening because I'm on a company VPN that apparently makes calls to Dockerhub a lot.

When I faced this issue with other images in the past, I used

docker save IMAGE_NAME > IMAGE.tar on the dev machine and

docker load < IMAGE.tar on the target machine (after file transfer from dev to target machine).

I then pushed to the local k3d registry (e.g. docker tag alpine:3.16.2 127.0.0.1:5000/alpine:3.16.2 && docker push 127.0.0.1:5000/alpine:3.16.2) to get around the rate limit.

In this case however, the image needed is for the registry itself. Is there any way to get around this rate limit issue by creating the cluster with a local registry image file?


Solution

  • Yup, creating a local registry and then integrating it with k3D should indeed work. Here are the steps you'd follow:

    Start by creating your local registry.

    docker volume create local_registry
    
    docker container run -d --name registry.localhost -v local_registry:/var/lib/registry --restart always -p 12345:5000 registry:2
    

    Add the registry to the registries.yaml configuration file. [1]

    version: 0
    mirrors:
      "localhost:12345":
        endpoint:
          - "http://localhost:12345"
    

    Next, check that the registry's network is connected to the k3d cluster network to enable direct communication.

    Verify that your registry container and k3d cluster are on the same network by executing docker network ls and searching for a network named similarly to k3d-my-cluster. Then, connect your registry container to this network with the following command:

    docker network connect k3d-my-cluster registry.localhost

    You may test it by pushing the image to your local development machine, then use that local deployment in your K3D cluster

    For more general information, you can check the answer of @Suhas_Pote in this StackOverflow thread and this guide.

    [1]. https://k3d.io/v5.4.2/usage/registries/