How do I pull a Github (ghcr.io) from Minikube?

1.9k views Asked by At

I run

docker pull ghcr.io/.../test-service

Everything works just fine, however, when I try to use it in a deployment and apply the deployment to a Minikube instance I get...

Warning  Failed     14s (x4 over 93s)  kubelet            Error: ErrImagePull
Normal   BackOff    1s (x6 over 92s)   kubelet            Back-off pulling image "ghcr.io/.../test-service:latest"
Warning  Failed     1s (x6 over 92s)   kubelet            Error: ImagePullBackOff

How do I configure Minikube to use my Github PAT?

My deployment looks like this...

apiVersion: apps/v1
kind: Deployment
metadata:
  name: test-app
  namespace: foo
spec:
  replicas: 1
  selector:
    matchLabels:
      app: test-app
      version: v1
  template:
    metadata:
      labels:
        app: test-app
        version: v1
    spec:
      serviceAccountName: test-app
      containers:
      - image: ghcr.io/.../test-service:latest
        imagePullPolicy: Always
        name: test-app
        ports:
        - containerPort: 8000
2

There are 2 answers

0
K Marco On

Another simpler way is to add registry-creds addon to Minikube

    $ minikube addons configure registry-creds
    # setup ghcr.io with your github username and PAT (Personal Access Token) token
    $ minikube addons enable registry-creds

Then you can refer to the github container registry creds as dpr-secret as below deployment example shows

# deployment.yml

apiVersion: apps/v1
kind: Deployment
metadata:
  name: b2b-integration-api 
  labels:
    app: api-app
  namespace: default

spec:
  template:
    metadata:
      name: b2b-integration-api-pods 
      labels:
        app: api-app 
        tier: api-layer 
    spec:
      containers:
        - name: b2b-integration-api 
          image: ghcr.io/<your github user or org>/<image>:<version>
          imagePullPolicy: IfNotPresent
          ports:
          - containerPort: 80
      imagePullSecrets:  
        - name: dpr-secret 
  replicas: 2
  selector:
    matchLabels:
      tier: api-layer 
0
behanzin777 On

It's because you did not create a docker registry secret. To do so, you can follow https://dev.to/asizikov/using-github-container-registry-with-kubernetes-38fb