I needed a private docker registry because I wanted to get away from the docker ecosystem. I also wanted to see if I could configure one and set one up.
Installing Registry Via Helm
I configured /opt/k8s/reg-values.yaml
to ensure a LoadBalancer
was used.
helm repo add twuni https://helm.twun.io
helm repo update
helm install registry twuni/docker-registry -n registry --create-namespace -f /opt/k8s/reg-values.yaml
After configuring the registry I added a dns entry for the LoadBalancerIP.
Configuring Insecure Registries for containerd
Note below I had to configure another Registry Mirror for the config I had setup (registry.dev.local:5000):
This adds the default config into containerd:
containerd config default | sudo tee /etc/containerd/config.toml
Then I updated the lines below to add the custom registry:
[plugins."io.containerd.grpc.v1.cri".registry]
config_path = ""
[plugins."io.containerd.grpc.v1.cri".registry.auths]
[plugins."io.containerd.grpc.v1.cri".registry.configs]
[plugins."io.containerd.grpc.v1.cri".registry.headers]
[plugins."io.containerd.grpc.v1.cri".registry.mirrors]
[plugins."io.containerd.grpc.v1.cri".registry.mirrors."docker.io"]
endpoint = ["https://registry-1.docker.io"]
[plugins."io.containerd.grpc.v1.cri".registry.mirrors."registry.dev.local:5000"]
endpoint = ["registry.dev.local:5000"]
Listing the Catalog
Curling the registry shows a list of the images. Also there is a way to curl the different tags of each image:
# Show the images
curl http://registry.dev.local:5000/v2/_catalog
curl http://registry.dev.local:5000/v2/jmoore53.com/tags/list
From here I created a simple go script to list the images in my registry:
package main
import (
"fmt"
"net/http"
"encoding/json"
"os"
)
type Repositories struct {
Repositories []string `json:"repositories"`
}
type Tags struct {
Name string
Tags []string `json:"tags"`
}
func main(){
reg := os.Getenv("REGISTRY")
resp, err := http.Get(reg + "/v2/_catalog")
if err != nil {
fmt.Println(err)
}
decoder := json.NewDecoder(resp.Body)
var repos Repositories
err = decoder.Decode(&repos)
for i:=0; i < len(repos.Repositories); i++ {
fmt.Println(repos.Repositories[i])
resp, err = http.Get(reg + "/v2/" + repos.Repositories[i] + "/tags/list")
if err != nil {
fmt.Println(err)
}
decoder = json.NewDecoder(resp.Body)
var tags Tags
err = decoder.Decode(&tags)
for j:=0; j<len(tags.Tags); j++{
fmt.Println(" " + repos.Repositories[i] + ":" + tags.Tags[j])
}
}
}