LoginSignup
4

More than 5 years have passed since last update.

kubenetes(v1.1)でdocker private registryを利用する (AWS)

Last updated at Posted at 2016-02-14

kubernetesでコンテナイメージをdocker hubではなく、自分でたてたprivate registryからpullする。
すべてAWS上で実現します。
※シンプルにprivate registry用EC2 ×1台と、kubernetes(master/minion兼用)用EC2 ×1台を同一VPC上に作成し、両者間のdocker pullはSSLを使わないケースです。

1.private registryを用意

以下を参照し、AWS上にdocker private registryを立てる

2.kubernetesクラスタを用意

以下を参照し、EC2(CentOS7)1台にkubernetesクラスタを立てる。
この時、1で立てたprivate registryを同じVPC上とする。

3.kubernetesでprivate docker registryを利用する設定

2で立てたkubernetesクラスタ上でdocker設定ファイルを編集
/etc/sysconfig/dockerに以下を追加

private registryパスを追加
ADD_REGISTRY='--add-registry <private registryのプライベートIP>:5000'

SSLを使わない場合の設定
INSECURE_REGISTRY='--insecure-registry <private registryのプライベートIP>:5000'

例)


$ sudo vi /etc/sysconfig/docker

# Modify these options if you want to change the way the docker daemon runs
OPTIONS='--selinux-enabled'

# If you want to add your own registry to be used for docker search and docker
# pull use the ADD_REGISTRY option to list a set of registries, each prepended
# with --add-registry flag. The first registry added will be the first registry
# searched.
ADD_REGISTRY='--add-registry 172.20.0.84:5000'

# If you want to block registries from being used, uncomment the BLOCK_REGISTRY
# option and give it a set of registries, each prepended with --block-registry
# flag. For example adding docker.io will stop users from downloading images
# from docker.io
# BLOCK_REGISTRY='--block-registry'

# If you have a registry secured with https but do not have proper certs
# distributed, you can tell docker to not look for full authorization by
# adding the registry to the INSECURE_REGISTRY line and uncommenting it.
# INSECURE_REGISTRY='--insecure-registry'
INSECURE_REGISTRY='--insecure-registry 172.20.0.84:5000'

(以下省略)

編集後、dockerサービス再起動

sudo service docker restart

master/minionのホストを分ける場合

masterとminionが異なるホストの場合は、/etc/sysconfig/dockerの設定はminion含めた全ホストで反映する必要がある。
※minion側の反映がされていない場合、kubectl createでpod作成時に、docker pullによるimage取得がエラーとなる。

トラブルシューティング

(1)エラー:unable to ping registry endpoint
podをcreateしても以下のようなエラーとなる場合は、次の理由が考えられる

エラー)

$ kubectl get pod
NAME      READY     STATUS    RESTARTS   AGE
my-pod    0/1       unable to ping registry endpoint https://172.20.0.84:5000/v0/
v2 ping attempt failed with error: Get https://172.20.0.84:5000/v2/: x509: cannot validate certificate for 172.20.0.84 because it doesn't contain any IP SANs
 v1 ping attempt failed with error: Get https://172.20.0.84:5000/v1/_ping: x509: cannot validate certificate for 172.20.0.84 because it doesn't contain any IP SANs   0         6s

理由)
①/etc/sysconfig/dockerの設定が反映されていない

②/etc/sysconfig/dockerのADD_REGISTRY設定に誤りがある

③/etc/sysconfig/dockerのINSECURE_REGISTRY設定に誤りがある

設定が正しい事を確認し、sudo service docker restart を実行する

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