LoginSignup
2
0

More than 3 years have passed since last update.

オンプレのOpenShiftでも内部レジストリ用のストレージにはS3を使おう

Last updated at Posted at 2021-01-26

オンプレのOpenShift構成を検討する際にしばしば問題になる事で、S2Iとかのビルドイメージを格納するための内部レジストリのストレージをどうするか、というのがある。
まあ、全てはイメージレジストリのストレージにNFSを使う事が、OpenShift製品的にはほぼサポートしないよと断言しているくらい後ろ向きであることに起因するのだが。
https://access.redhat.com/documentation/ja-jp/openshift_container_platform/4.6/html/scalability_and_performance/recommended-configurable-storage-technology_persistent-storage#specific-application-storage-recommendations

じゃあOpenshift Container Storage(OCS)使うか?とかいう方向へ進めることも出来るとは思うが、あまりお金を掛けたくない場合はOpenShiftクラスターをインターネットに接続出来るようにして、イメージレジストリのバックエンドストレージはAmazon S3を使うようにするのがお勧めである。

インターネットに接続したくない?そんな構成はOCS代をケチる貧乏環境では最初から検討しないのが身のためである。多分その環境では、定期的にOpenShiftの更新を適用する運用が回らないだろう。定期的な更新適用はOpenShiftのサポートを維持するために必要である。EUSでもパッチレベルを更新しないとサポートしないとか普通に言われるだろう。サポートが無くて良いなら、そもそもOpenShiftを使っている意味が分からない。検証環境であれば、NFSでもいいし何ならemptyDirでも良いのだ。

パブリックのQuay.ioやDockerHubのプライベートレポジトリを使うという選択肢も当然あると思うが、こちらはPullSecretの管理が面倒くせーな、という運用上の障壁がある。コンテナの脆弱性検査を勝手にやってくれるという付加価値もあるが、それも場合により良し悪し。あと多分S3を使う方が安い。どちらも大した金額ではないだろうが。

さらには、これは紛うこと無きハイブリッドクラウド構成なので、人によってはこれだけで何かの目標を達成出来たりするかもしれない。

Amazon S3を準備する

AWSのアカウントは予め持っていることが前提である。

1.S3へのアクセスキーを作る。IAMのUserより、「Add user」をクリックする。
https://console.aws.amazon.com/iam/home?region=ap-northeast-1#/users

2.名前とかは適当でも良いが、とりあえず以下でユーザーを作成する。

User name: ocp-registry
Access type: ☑ Programatic access
Set permissions: 「Attach existing policies directly」>「AmazonS3FullAccess」

3.ユーザーを作成したら、表示された「Access key ID」と「Secret access key」を手元のnotepadとかにコピーしておく。

OpenShiftレジストリーを設定する

(参考)https://access.redhat.com/documentation/ja-jp/openshift_container_platform/4.6/html/registry/setting-up-and-configuring-the-registry#registry-operator-configuration-resource-overview-aws-s3_configuring-registry-storage-aws-user-infrastructure

1.OCコマンドが実行可能な、bastionサーバーとかで、以下を実行する。

# myaccesskey=<「Access key ID」>
# mysecretkey=<「Secret access key」>
# oc create secret generic image-registry-private-configuration-user --from-literal=REGISTRY_STORAGE_S3_ACCESSKEY=$myaccesskey --from-literal=REGISTRY_STORAGE_S3_SECRETKEY=$mysecretkey --namespace openshift-image-registry

2.レジストリーの設定を変更する。
マニュアルの例にあるbucketは、指定しなければOpenShiftが適当なS3バケットを生成するが、regionは指定しないとオペレーターがエラーを吐いて失敗する。

# oc edit configs.imageregistry.operator.openshift.io/cluster

(以下を変える)
  storage:
    s3:
      region: ap-northeast-1

(初期設定の場合は以下も)
  managementState: Managed

3.しばらくして、image-registryのPodが起動するのを確認する。

[root@bastion ~]# oc get pod -n openshift-image-registry
NAME                                               READY   STATUS    RESTARTS   AGE
cluster-image-registry-operator-7dddbbc449-x75tn   1/1     Running   0          4d3h
image-registry-7f867d9766-dpgm7                    1/1     Running   0          5m49s
node-ca-7rbfk                                      1/1     Running   0          4d3h
node-ca-bn2cc                                      1/1     Running   0          4d3h
node-ca-tl6xh                                      1/1     Running   0          4d3h

Amazon S3の画面を見れば、新しいバケットが出来ているのが見えるだろう。
https://s3.console.aws.amazon.com/s3/home?region=ap-northeast-1
image.png

アプリをS2Iで動かしてみる

何でも良いが、S2Iでアプリをビルドして、イメージレジストリに何かをpushしてみる。

1.OpenShiftのマニュアルにあるPHPのサンプルアプリで良いか。
(参考)https://access.redhat.com/documentation/ja-jp/openshift_container_platform/4.6/html/applications/creating-applications-using-cli

# oc new-project sample
# oc new-app https://github.com/sclorg/cakephp-ex

2.oc get podとか、oc logs -f cakephp-ex-1-buildとかを眺めながら、アプリのPodが起動するのを待つ。

[root@bastion ~]# oc get pod
NAME                         READY   STATUS      RESTARTS   AGE
cakephp-ex-1-build           0/1     Completed   0          4m43s
cakephp-ex-64f9f74d7-wgm8g   1/1     Running     0          15s
[root@bastion ~]# oc expose svc cakephp-ex
route.route.openshift.io/cakephp-ex exposed

image.png

3.Amazon S3を確認すれば、バケット内に「/docker」というFolderが出来ているはずだ。
https___qiita-image-store.s3.ap-northeast-1.amazonaws.com_0_146381_c2066915-32ff-9cf4-2d06-3f8719d32522.png

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