> For the complete documentation index, see [llms.txt](https://til.duyet.net/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://til.duyet.net/data-engineering/kubernetes/pull-an-image-from-a-private-registry.md).

# K8S: Pull an Image from a Private Registry

## Create the Secret

```bash
kubectl create secret docker-registry <name> \
    --docker-server=docker.pkg.github.com \
    --docker-username=<github-username> \
    --docker-password=<personal-token> \
    --docker-email=<github-email>
```

```bash
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

{% code title="pod.yaml" %}

```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>
```

{% endcode %}

Apply to k8s

```yaml
kubectl apply -f pod.yaml
```

## Reference

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