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


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://til.duyet.net/data-engineering/kubernetes/pull-an-image-from-a-private-registry.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
