0
0

More than 1 year has passed since last update.

KubernetesでPrivate RegistryからDocker Imageを引っ張ってくる方法

Last updated at Posted at 2022-02-03

前書き

公式ドキュメントだと、何種類かの方法とそれの検証方法が書かれていてその上英語なのでわかる人には最高のドキュメントなんでしょうが、初学者にはちと厳しいので、決定版だけ抜き出して書いておきます。備忘録です。

引用元:

本文

ワンライナーの方法もあるのですが、入力ミスでイライラしそうなのでdocker loginでログインする方法を使います。

Kubernetesは普通にインストールすると、dockerではなくcontainerdで動いているので、docker imageとか今回使うdocker login等が使えないと思います。今回はとりあえずdocker.ioというパッケージをインストールします。

とりあえず、Ubuntuのインストール方法をば。

apt install docker.io

ログイン!オプションをいじれば、DockerHub以外のRegistryからも引っ張ってこれます。

docker login #指示通りにユーザー名とパスワードを入力

ホームディレクトリ配下の.docker/config.jsonに認証情報が保存されているはずなのでそれを使います。フルパスで指定しないとエラーを吐きます。

kubectl create secret generic regcred --from-file=.dockerconfigjson=<ホームディレクトリ>/.docker/config.json --type=kubernetes.io/dockerconfigjson

公式ドキュメントにもある通り、こんな感じでImagePullSecretsのnameにgenericの次に入力したオプション(上の通りならregcred)を書けば勝手に認証してくれます。

apiVersion: v1
kind: Pod
metadata:
  name: private-reg
spec:
  containers:
  - name: private-reg-container
    image: <ユーザー名>/<リポジトリ名>
  imagePullSecrets:
  - name: regcred

おわり

最近docker-composeのprofileでやりくりしていたのをKubernetesに移行しようと試行錯誤中なのですがやっぱりKubernetesは難しいですね。PersistentVolumeでつまづいてます。

0
0
0

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
0
0