DEV Community

Anuchit Prasertsang
Anuchit Prasertsang

Posted on

1

ดึง Images จาก Private Registry - Kubernetes

ดึง Image จาก Private Registry สำหรับ Kubernetes

  1. สร้าง docker-registry secret ใน Kubernetes
kubectl create secret docker-registry SECRET_NAME \
  --docker-server=REGISTRY_URL \
  --docker-username=REGISTRY_USERNAME \
  --docker-password=REGISTRY_PASSWORD \
  --docker-email=REGISTRY_EMAIL
Enter fullscreen mode Exit fullscreen mode
  • SECRET_NAME ชื่อของ secret ตั้งเป็นอะไรก็ได้
  • REGISTRY_URL แทนที่ด้วย registry server เช่น https://registry.gitlab.com หรือ https://ghcr.io หรือ https://index.docker.io/v1/
  • REGISTRY_USERNAME แทนที่ด้วย username ที่คุณใช้กับ Registry นั้น
  • REGISTRY_PASSWORD แทนที่ด้วยรหัสผ่าน ถ้าเป็น GitLab, GitHub ให้ใช้ Access Token
  • REGISTRY_EMAILแทนที่ด้วยอีเมล์ของคุณที่ใช้กับ Registry นั้น

ตัวอย่าง GitLab Registry

kubectl create secret docker-registry gitlab-registry-secret \
  --docker-server=https://registry.gitlab.com \
  --docker-username=mygitlab \
  --docker-password=glpat-xk......E5 \
  --docker-email=hello@gmail.com 
Enter fullscreen mode Exit fullscreen mode
  1. เพิ่ม imagePullSecrets ใน ไฟล์ deployment manifest หรือ ใน pod
spec:
  imagePullSecrets:
    - name: gitlab-registry-secret
Enter fullscreen mode Exit fullscreen mode

ตัวอย่างเช่น

apiVersion: v1
kind: Pod
metadata:
  name: api-service
spec:
  hostNetwork: true
  containers:
  - name: api-service
    image: registry.gitlab.com/<mygitlab>/<repo>/<images>:v1.0.0

  imagePullSecrets: 
  - name: gitlab-registry-secret
Enter fullscreen mode Exit fullscreen mode

จากนั้นก็สั่ง apply ได้เลย kubectl apply -f pod.yaml

หมายเหตุ: ถ้าจะใช้ image pull secrets กับ Pod (หรือ Deployment หรืออื่น ๆ ที่มี pod template) ต้องตรวจสอบให้แน่ใจว่า Secret ที่เราต้องการมีอยู่ใน namespace ที่ถูกต้อง ซึ่ง namespace นั้นต้องเป็น namespace เดียวกับที่เรากำหนด Pod ไว้ด้วยนะ

Reference:

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

Image of Datadog

The Future of AI, LLMs, and Observability on Google Cloud

Datadog sat down with Google’s Director of AI to discuss the current and future states of AI, ML, and LLMs on Google Cloud. Discover 7 key insights for technical leaders, covering everything from upskilling teams to observability best practices

Learn More

Top comments (0)

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more