If you want to launch a private registry server using Kubernetes, you need your own Kubernetes cluster. You will have set up your own Kubernetes while exploring this book. If you haven't done yet, please read Chapter 1, Building Your Own Kubernetes Cluster, to choose the easiest way.
Please note that Docker registry will store some of your Docker images. You must have a PersistentVolume to manage your storage via Kubernetes. In addition, we should expect that multiple pods will read and write to the same PersistentVolume due to scalability. Therefore, you must have the ReadWriteMany (RWX) access mode of PersistentVolume, such as GlusterFS or NFS.
Details of PersistentVolume are described in the Working with volumes section in Chapter 2, Walking through Kubernetes Concepts. Let's create a PersistentVolume that uses NFS and the name pvnfs01 to allocate 100 GB:
//my NFS server(10.138.0.5) shares /nfs directory
$ showmount -e 10.138.0.5
Export list for 10.138.0.5:
/nfs *
//please change spec.nfs.path and spec.nfs.server to yours
$ cat pv_nfs.yaml
apiVersion: "v1"
kind: "PersistentVolume"
metadata:
name: pvnfs01
spec:
capacity:
storage: "100Gi"
accessModes:
- "ReadWriteMany"
nfs:
path: "/nfs"
server: "10.138.0.5"
$ kubectl create -f pv_nfs.yaml
persistentvolume "pvnfs01" created
$ kubectl get pv
NAME CAPACITY ACCESS MODES RECLAIM POLICY STATUS CLAIM STORAGECLASS REASON AGE
pvnfs01 100Gi RWX Retain Available 5s
Next, create PersistentVolumeClaim that decouples NFS PersistentVolume and pod configuration. Let's create one PersistentVolumeClaim named pvc-1. Make sure accessModes is ReadWriteMany and that STATUS became Bound after creation:
$ cat pvc-1.yml
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: pvc-1
spec:
storageClassName: ""
accessModes:
- ReadWriteMany
resources:
requests:
storage: 100Gi
$ kubectl create -f pvc-1.yml
persistentvolumeclaim "pvc-1" created
$ kubectl get pvc
NAME STATUS VOLUME CAPACITY ACCESS MODES STORAGECLASS AGE
pvc-1 Bound pvnfs01 100Gi RWX 5s
This is enough to set up your private registry. It has some prerequisites; alternatively, using the public cloud is much simpler.