Using Kubernetes to run a Docker registry server

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
If you can't prepare RWX PersistentVolume, you may still be able to set up Docker registry by Kubernetes, but you can launch only one pod (replicas: one). As an alternative, you may use AWS S3 or GCP PD as private registry backend storage; please visit https://docs.docker.com/registry/configuration/ to learn how to configure backend storage for your registry.

Next, create PersistentVolumeClaim that decouples NFS PersistentVolume and pod configuration. Let's create one PersistentVolumeClaim named pvc-1Make 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.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.17.162.214