Using Private Docker Registry with Skaffold

in #blog2 years ago

When doing a skaffold build, skaffold will attempt to verify artifacts created. Artifacts are images, so it will check to see if the artifact is there or not. There is nothing you can do about this. Honestly, I would not want to. This is a reasonable assumption that if you create an artifact, check if it got created. The trouble is that skaffold wants to work mostly with docker.io or public docker registries. It does not give much in the way of supporting private or secure registries. See below:

❯ skaffold build  --cache-artifacts=false
Generating tags...
 - registry.localhost/repo/project -> registry.localhost/repo/project:latest
Starting build...
Checking for kaniko secret [default/regcred]...
Creating docker config secret [regcred]...
Building [registry.localhost/repo/project]...
job.batch/project-buildkit-base created
getting image: GET https://registry.localhost/repo/project/manifests/latest: nexpected status code 401 Unauthorized: 401 Unauthorized

What can then be done? Luckily, skaffold does not require docker to be installed or I would be in trouble. I do not use docker. I use containerd and buildkit. Docker would be the end for me. Instead, skaffold only requires that ~/.docker/config.json have your credentials in it. That is easily fixed. Kubernetes already has my docker config as a secret.

kubectl get secret regcred -o yaml | grep dockerconfigjson | head -1 | cut -d ' ' -f 4 | base64 -d > ~/.docker/config.json

Now I can run skaffold build with no problem.