Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

K8s to pull private image from Github container registry (ghcr) using GITHUB_TOKEN

Is it possible to pull private images in Github Container Registry using GITHUB_TOKEN?

If so, what do I need to configure in k8s?

like image 766
Joseph Y Avatar asked Dec 04 '25 05:12

Joseph Y


1 Answers

Yes you can. You will have to create a secret object in your cluster.

kubectl create secret docker-registry ghcr-login-secret --docker-server=https://ghcr.io --docker-username=$YOUR_GITHUB_USERNAME --docker-password=$YOUR_GITHUB_TOKEN --docker-email=$YOUR_EMAIL

Note: Your credentials will become part of shell history, so be careful and remove the shell history afterwards.

This will internally create a dockerconfig.json with your provided values and generate a secret that will be used to authenticate with your registry.

You can then proceed to specify in your Pod specification that you are using a private registry and pass this secret as:

...
imagePullSecrets:
  - name: ghcr-login-secret
...

You can read more about external registry interfacing with Kubernetes here.

like image 150
zer0 Avatar answered Dec 06 '25 05:12

zer0



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!