9
9

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

Docker Private Registryの構築 on Kubernetes

Last updated at Posted at 2018-12-06

Docker Private Registryの構築 on Kubernetes

(2018/11時点)

環境

  • OS: CentOS 7.4
  • Kubernetes: v1.12
  • Docker: docker-ce-18.06.1.ce
  • ストレージ: NFS

手順

0. NFSの準備 (割愛)

1. NFS Clientのインストール (各ノード)

shell
# yum -y install nfs-utils

2. Persistent Volumeの追加

NFSをPersistent Volumeとして追加する。

pv.yaml
apiVersion: v1
kind: PersistentVolume
metadata:
  name: pv01
spec:
  capacity:
    storage: <capacity n[Gi]>
  volumeMode: Filesystem
  accessModes:
    - ReadWriteOnce
  persistentVolumeReclaimPolicy: Recycle
  storageClassName: slow
  mountOptions:
    - hard
  nfs:
    server: <nfs server ip>
    path: <nfs shared directory>
pvc.yaml
kind: PersistentVolumeClaim
apiVersion: v1
metadata:
  name: pvc01
  annotations:
    volume.kubernetes.io/storage-class: "nfs"
spec:
  accessModes:
    - ReadWriteOnce
  volumeMode: Filesystem
  resources:
    requests:
      storage: <capacity n[Gi]>
  storageClassName: slow
shell
# kubectl apply -f pv.yaml
# kubectl apply -f pvc.yaml
# kubectl get pv
NAME   CAPACITY   ACCESS MODES   RECLAIM POLICY   STATUS   CLAIM           STORAGECLASS   REASON   AGE
pv01   100Gi      RWO            Recycle          Bound    default/pvc01   slow                    21d
# kubectl get pvc
NAME    STATUS   VOLUME   CAPACITY   ACCESS MODES   STORAGECLASS   AGE
pvc01   Bound    pv01     100Gi      RWO            slow           21d

3. PodおよびServiceの作成

srv-pr-pod.yaml
kind: Service
apiVersion: v1
metadata:
  name: srv-pregistry
spec:
  selector:
    app: pregistry
  type: NodePort
  ports:
  - protocol: TCP
    port: 5000
    targetPort: 5000
    name: registry-http
---
kind: Pod
apiVersion: v1
metadata:
  name: pregistry
  labels:
    app: pregistry
spec:
  containers:
    - name: pregistry
      image: registry:2
      volumeMounts:
      - mountPath: "/var/lib/registry"
        name: pvc01-pnt
      ports:
      - containerPort: 5000
  volumes:
    - name: pvc01-pnt
      persistentVolumeClaim:
        claimName: pvc01
shell
# kubectl apply -f srv-pr-pod.yaml
# kubectl get pod
NAME                 READY   STATUS    RESTARTS   AGE
pregistry            1/1     Running   0          21d
# kubectl get service
NAME                     TYPE        CLUSTER-IP       EXTERNAL-IP   PORT(S)          AGE
srv-pregistry            NodePort    x.x.x.x          <none>        5000:32523/TCP   21d

Master IP:32523に接続するとdocker imageをpush/pullすることが可能となる。

4. Web Frontendの作成

konradkleine/docker-registry-frontendをDeployすることでブラウザからPrivate Registryの中身を確認することが可能となる。

srv-prf-pod.yaml
kind: Service
apiVersion: v1
metadata:
  name: srv-pregistry-frontend
spec:
  selector:
    app: pregistry-frontend
  type: NodePort
  ports:
  - protocol: TCP
    port: 80
    targetPort: 80
    name: registry-http-frontend
---
kind: Pod
apiVersion: v1
metadata:
  name: pregistry-frontend
  labels:
    app: pregistry-frontend
spec:
  containers:
    - name: pregistry-frontend
      image: konradkleine/docker-registry-frontend:v2
      ports:
      - containerPort: 80
      env:
      - name: ENV_DOCKER_REGISTRY_HOST
        value: <private registry pod ip>
      - name: ENV_DOCKER_REGISTRY_PORT
        value: "5000"
shell
# kubectl apply -f srv-prf-pod.yaml
9
9
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
9
9

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?