How to use a private Docker registry from Kubernetes

I have the following machines:

  • 192.168.33.1: CentOS with private Docker registry
  • 192.168.33.10: CentOS Kubernetes master
  • 192.168.33.11: CentOS Kubernetes minion1
  • 192.168.33.12: CentOS Kubernetes minion2
  • 192.168.33.13: CentOS Kubernetes minion3

I want to push Docker images to the private registry and then use them in the Kubernetes cluster.

I must say docker to use the insecure registry. On all the Kubernetes nodes, edit the file /etc/sysconfig/docker, by adding the line:

INSECURE_REGISTRY='--insecure-registry 192.168.33.1:5000'

From my development machine (192.168.33.100) I push myimage to the private registry:

$ docker tag myimage 192.168.33.1:5000/myimage
$ docker push 192.168.33.1:5000/myimage

Then on the master I define the pod or replication controller, in a similar way:

# cat myimage-rc.yaml 
apiVersion: v1
kind: ReplicationController
metadata:
  name: my-image
spec:
  replicas: 2
  template:
    metadata:
      labels:
        app: myimage
    spec:
      containers:
      - name: myimage
        image: 192.168.33.1:5000/myimage
        ports:
        - containerPort: 80

Then I can create the pods from the master:

# kubectl create -f myimage-rc.yaml

Kubernetes will pull myimage from the private registry and create the pods.

 

Advertisements

One thought on “How to use a private Docker registry from Kubernetes

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s