LoginSignup
4
2

More than 5 years have passed since last update.

Docker for Macで起動したKubernetesクラスタ上にprivate registryを作成しアクセスする

Last updated at Posted at 2018-11-03

この記事ではDocker for Mac Version: 18.06.1-ce-mac73を使っています。

背景

Docker for Mac 18.06.0-ceから使用できるようになったKubernetesですが、ちょっとしたアプリケーションなどのイメージをlocalで試したいときに、わざわざDocker HubやGCR, ECRなどのレジストリにプッシュしたくなかったため、local registryを起動してみました。

環境

Docker for Mac Version: 18.06.1-ce-mac73
Kubernetes: v1.10.3

やりたいこと

Docker for MacでデプロイしたKubernetesクラスタ上でregistryを起動し、そこにイメージをpushする。そのイメージをpullして他のpodで使用する。

Kubernetes上にregistryを用意

下記のregistry.yamlにあるように
DaemonSetにてregistryのPodを作成し、LoadBalancer Serviceを用いてアクセスする。

registry.yaml
---
apiVersion: apps/v1
kind: DaemonSet
metadata:
  name: registry-ds
spec:
  selector:
    matchLabels:
      app: registry
  template:
    metadata:
      labels:
        app: registry
    spec:
      containers:
      - name: registry-container
        image: registry:latest
        ports:
        - containerPort: 5000
---
apiVersion: v1
kind: Service
metadata:
  name: registry-service
spec:
  selector:
    app: registry
  ports:
    - protocol: TCP
      port: 5000
      targetPort: 5000
  type: LoadBalancer

上記ファイルを適用し、

$ kubectl apply -f registry.yaml
daemonset "registry-ds" created
service "registry-service" created

registry-serviceが作成されてることを確認。

$ kubectl get services registry-service
NAME               TYPE           CLUSTER-IP       EXTERNAL-IP   PORT(S)          AGE
registry-service   LoadBalancer   10.100.223.219   localhost     5000:30124/TCP   1m

registryにアクセスする

curlでアクセスできるが、普通にpushしようとするとできない...

$ curl -I localhost:5000
HTTP/1.1 200 OK
Cache-Control: no-cache
Date: Sat, 03 Nov 2018 15:00:00 GMT
Content-Type: text/plain; charset=utf-8
$ docker push localhost:5000/whatever-image
The push refers to repository [localhost:5000/whatever-image]
Get http://localhost:5000/v2/: dial tcp [::1]:5000: connect: connection refused

下図の様にDocker for MacのDaemonに docker.for.mac.localhost:5000insecure registriesに追加する。
Screen Shot 2018-11-04 at 1.10.33.png
その上で docker push docker.for.mac.localhost:5000/whatever-image すると成功する。

参考

4
2
1

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
4
2