CentOS Stream 10

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 を起動しておきます
当例では Manager ノード上に Registry を起動します。

[2] 認証トークンを Kubernetes に登録します。
# 任意のユーザーで Registry にログイン

[centos@ctrl ~]$
podman login ctrl.srv.world:5000

Username:
serverworld

Password:
Login Succeeded!
# ログインすると下記ファイルが生成される

[centos@ctrl ~]$
ll /run/user/$(id -u)/containers/auth.json

-rw-------. 1 centos centos 91 Jul 4 08:52 /run/user/1000/containers/auth.json
[centos@ctrl ~]$
AUTH=$(cat /run/user/$(id -u)/containers/auth.json | base64 | tr -d '\n')

[centos@ctrl ~]$ cat <<EOF > regcred.yml
apiVersion: v1
kind: Secret
data:
  .dockerconfigjson: ${AUTH}
metadata:
  name: regcred
type: kubernetes.io/dockerconfigjson
EOF 

[centos@ctrl ~]$
kubectl apply -f regcred.yml

secret "regcred" created
[centos@ctrl ~]$
kubectl get secrets

NAME      TYPE                             DATA   AGE
regcred   kubernetes.io/dockerconfigjson   1      6s
[3] Private Registry から Pull するには 登録した Secret と Private Registry の image を指定して Pod をデプロイします。
[centos@ctrl ~]$
podman images

REPOSITORY                 TAG          IMAGE ID      CREATED     SIZE
ctrl.srv.world:5000/nginx  my-registry  9592f5595f2b  9 days ago  196 MB
docker.io/library/nginx    latest       9592f5595f2b  9 days ago  196 MB

[centos@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

[centos@ctrl ~]$
kubectl apply -f private-nginx.yml

pod "private-nginx" created
[centos@ctrl ~]$
kubectl get pods

NAME            READY   STATUS    RESTARTS   AGE
private-nginx   1/1     Running   0          7s

[centos@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:       Fri, 04 Jul 2025 08:55:32 +0900
Labels:           <none>
Annotations:      cni.projectcalico.org/containerID: 677ec70ad374af53ba270fd1d5b7b80416353d1350a2bf0f7098e32f454d781a
                  cni.projectcalico.org/podIP: 192.168.241.135/32
                  cni.projectcalico.org/podIPs: 192.168.241.135/32
Status:           Running
IP:               192.168.241.135
IPs:
  IP:  192.168.241.135
Containers:
  private-nginx:
    Container ID:   cri-o://f08b8fa09701fcf10dac82533722cdbaff2448059e0fb7c5fba463987de49ce6
    Image:          ctrl.srv.world:5000/nginx:my-registry
    Image ID:       ctrl.srv.world:5000/nginx@sha256:13920fe73b382aa9017f7cf38b1377bc46ffb605fe980eb00f61aad26311ebf7
    Port:           <none>
    Host Port:      <none>
    State:          Running
      Started:      Fri, 04 Jul 2025 08:55:33 +0900
    Ready:          True
    Restart Count:  0
    Environment:    <none>
    Mounts:
      /var/run/secrets/kubernetes.io/serviceaccount from kube-api-access-fmqwz (ro)
.....
.....
関連コンテンツ