GHCR: Cannot pull docker image without auth in Kubernetes

I have created a public docker image ghcr.io/windsource/nextcloud-influxdb-tracks-importer:1.0.0.

Using docker without being logged in to ghcr.io I can pull that image using:

docker pull ghcr.io/windsource/nextcloud-influxdb-tracks-importer:1.0.0

When I use that image without image pull secrets in Kubernetes I get the error:

Events:
  Type     Reason     Age                From               Message
  ----     ------     ----               ----               -------
  Normal   Scheduled  46s                default-scheduler  Successfully assigned default/mypod to manjaro
  Normal   BackOff    21s (x2 over 44s)  kubelet            Back-off pulling image "ghcr.io/windsource/nextcloud-influxdb-tracks-importer:1.0.0"
  Warning  Failed     21s (x2 over 44s)  kubelet            Error: ImagePullBackOff
  Normal   Pulling    9s (x3 over 46s)   kubelet            Pulling image "ghcr.io/windsource/nextcloud-influxdb-tracks-importer:1.0.0"
  Warning  Failed     9s (x3 over 44s)   kubelet            Failed to pull image "ghcr.io/windsource/nextcloud-influxdb-tracks-importer:1.0.0": rpc error: code = Unknown desc = failed to pull and unpack image "ghcr.io/windsource/nextcloud-influxdb-tracks-importer:1.0.0": failed to resolve reference "ghcr.io/windsource/nextcloud-influxdb-tracks-importer:1.0.0": failed to authorize: failed to fetch anonymous token: unexpected status: 403 Forbidden
  Warning  Failed     9s (x3 over 44s)   kubelet            Error: ErrImagePull

Steps to reproduce:

curl -sfL https://get.k3s.io | sh -s - --write-kubeconfig-mode 644
k3s kubectl run -it mypod --image=ghcr.io/windsource/nextcloud-influxdb-tracks-importer:1.0.0 --restart=Never -- sh

Hi @clarkbw,

I just saw your comment in Download from Github Package Registry without authentication so is my report a bug?

:wave: @windsource I was able to pull your image into my cluster ok.

Locally I have kubernetes running with minikube.
I was getting a similar error, but found that doing this fixed my issue.

Perhaps you have a similar issue? The “anonymous token” error message also isn’t one coming from Container Registry (I validated :smile:) I think it’s coming from k8s

Events:
Type Reason Age From Message


Normal Scheduled 2m55s default-scheduler Successfully assigned default/windsource-6bb75db69f-f7tz9 to minikube
Normal Pulling 2m55s kubelet, minikube Pulling image “ghcr.io/windsource/nextcloud-influxdb-tracks-importer:1.0.0
Normal Pulled 2m50s kubelet, minikube Successfully pulled image “ghcr.io/windsource/nextcloud-influxdb-tracks-importer:1.0.0” in 4.629080496s
Normal Created 77s (x5 over 2m50s) kubelet, minikube Created container nextcloud-influxdb-tracks-importer
Normal Started 77s (x5 over 2m50s) kubelet, minikube Started container nextcloud-influxdb-tracks-importer
Normal Pulled 77s (x4 over 2m50s) kubelet, minikube Container image “ghcr.io/windsource/nextcloud-influxdb-tracks-importer:1.0.0” already present on machine

Hi @whitneyimura, I also think that the problem might not be in GHCR but either in k3s or containerd. Switching to docker driver as you have described it is no solution for me as I want to get away from docker driver on Kubernetes.
I have created an issue in k3s.