Kubernetes : Private Registry の設定2025/01/27 |
自身の Private Registry からコンテナーイメージを Pull できるよう設定します。 当例では以下のように 4 台のノードを使用して Kubernetes クラスターを構成しています。 +----------------------+ +----------------------+ | [ ctrl.srv.world ] | | [ dlp.srv.world ] | | Manager Node | | Control Plane | +-----------+----------+ +-----------+----------+ eth0|10.0.0.25 eth0|10.0.0.30 | | ------------+--------------------------+----------- | | eth0|10.0.0.51 eth0|10.0.0.52 +-----------+----------+ +-----------+----------+ | [ node01.srv.world ] | | [ node02.srv.world ] | | Worker Node#1 | | Worker Node#2 | +----------------------+ +----------------------+ |
[1] |
Registry Pod を起動したいノードで
こちらを参考に、認証有効 + HTTPS (正規の証明書) で Registry を起動しておきます。 |
[2] | 認証トークンを Kubernetes に登録します。 |
# 任意のユーザーで Registry にログイン [cent@ctrl ~]$ podman login ctrl.srv.world:5000 Username: serverworld Password: Login Succeeded! # ログインすると下記ファイルが生成される [cent@ctrl ~]$ ll /run/user/$(id -u)/containers/auth.json -rw-------. 1 cent cent 91 Jan 27 10:18 /run/user/1000/containers/auth.json AUTH=$(cat /run/user/$(id -u)/containers/auth.json | base64 | tr -d '\n')
[cent@ctrl ~]$ cat <<EOF > regcred.yml
apiVersion: v1
kind: Secret
data:
.dockerconfigjson: ${AUTH}
metadata:
name: regcred
type: kubernetes.io/dockerconfigjson
EOF
[cent@ctrl ~]$ kubectl apply -f regcred.yml secret "regcred" created [cent@ctrl ~]$ kubectl get secrets NAME TYPE DATA AGE regcred kubernetes.io/dockerconfigjson 1 5s |
[3] | Private Registry から Pull するには 登録した Secret と Private Registry の image を指定して Pod をデプロイします。 |
[cent@ctrl ~]$ podman images REPOSITORY TAG IMAGE ID CREATED SIZE ctrl.srv.world:5000/nginx my-registry 9bea9f2796e2 2 months ago 196 MB docker.io/library/nginx latest 9bea9f2796e2 2 months ago 196 MB
[cent@ctrl ~]$
vi private-nginx.yml apiVersion: v1 kind: Pod metadata: name: private-nginx spec: containers: - name: private-nginx # Private Registry の image image: ctrl.srv.world:5000/nginx:my-registry imagePullSecrets: # 登録した Secret 名 - name: regcred
[cent@ctrl ~]$
[cent@ctrl ~]$ kubectl apply -f private-nginx.yml pod "private-nginx" created kubectl get pods NAME READY STATUS RESTARTS AGE private-nginx 1/1 Running 0 6s[cent@ctrl ~]$ kubectl describe pods private-nginx Name: private-nginx Namespace: default Priority: 0 Service Account: default Node: node02.srv.world/10.0.0.52 Start Time: Mon, 27 Jan 2025 10:36:11 +0900 Labels: <none> Annotations: cni.projectcalico.org/containerID: 4dd4af0f4e827c9a06a9811c2968ee852abf21ee87822321181840bb30c93806 cni.projectcalico.org/podIP: 192.168.241.133/32 cni.projectcalico.org/podIPs: 192.168.241.133/32 Status: Running IP: 192.168.241.133 IPs: IP: 192.168.241.133 Containers: private-nginx: Container ID: cri-o://c1486b11f07dad83f3ca9dda9d0cd3f7dd1eb94fed55f23742df577b3b293188 Image: ctrl.srv.world:5000/nginx:my-registry Image ID: ctrl.srv.world:5000/nginx@sha256:0a399eb16751829e1af26fea27b20c3ec28d7ab1fb72182879dcae1cca21206a Port: <none> Host Port: <none> State: Running Started: Mon, 27 Jan 2025 10:36:12 +0900 Ready: True Restart Count: 0 Environment: <none> Mounts: /var/run/secrets/kubernetes.io/serviceaccount from kube-api-access-2dk5s (ro) ..... ..... |
Sponsored Link |
|