K8S: Pull an Image from a Private Registry

Pull Image from Github Docker Package Private

Create the Secret

kubectl create secret docker-registry <name> \
    --docker-server=docker.pkg.github.com \
    --docker-username=<github-username> \
    --docker-password=<personal-token> \
    --docker-email=<github-email>
kubectl create secret docker-registry <name> \
    --docker-server=docker.pkg.github.com \
    --docker-username=<github-username> \
    --docker-password=<personal-token> \
    --docker-email=<github-email>
    -o yaml > github-secret.yaml
    
# view the content
cat github-secret.yaml

# apply to k8s
kubectl apply -f github-secret.yaml

Create deployment

pod.yaml
apiVersion: v1
kind: Pod
metadata:
  name: pod-name
spec:
  containers:
  - name: name
    image: docker.pkg.github.com/duyet/<image-name>:latest
  imagePullSecrets:
  - name: <name>

Apply to k8s

kubectl apply -f pod.yaml

Reference

https://kubernetes.io/docs/tasks/configure-pod-container/pull-image-private-registry/

Last updated