Red Hat Training

A Red Hat training course is available for OpenShift Container Platform

24.4.3. Microsoft Azure の OpenShift Container Platform レジストリーの設定

Microsoft Azure は、OpenShift Container Platform が OpenShift Container Platform コンテナーイメージレジストリーを使用してコンテナーイメージを保存するために使用できるオブジェクトクラウドストレージを提供します。

詳細は、Azure ドキュメントでクラウドストレージについて を参照してください。

レジストリーは、Ansible を使用するか、またはレジストリー設定ファイルを手動で設定して設定することができます。

前提条件

インストール前にレジストリーイメージをホストするためのストレージアカウントを作成する必要があります。以下のコマンドは、インストール時にイメージストレージに使用されるサービスアカウントを作成します。

コンテナーイメージを保存するために Microsoft Azure Blob ストレージを使用できます。OpenShift Container Platform レジストリーは Blob ストレージを使用して、管理者の介入なしにレジストリーのサイズを動的に拡張できるようにします。

  1. Azure ストレージアカウントを作成します。

    az storage account create
    --name <account_name> \
    --resource-group <resource_group> \
    --location <location> \
    --sku Standard_LRS

    これによってアカウントキーが作成されます。アカウントキーを表示するには、以下を実行します。

    az storage account keys list \
        --account-name <account-name> \
        --resource-group <resource-group> \
        --output table
    
    KeyName    Permissions    Value
    key1       Full           <account-key>
    key2       Full           <extra-account-key>

OpenShift Container Platform レジストリーの設定には、1 つのアカウントキー値のみが必要になります。

オプション 1: Ansible を使用した Azure の OpenShift Container Platform レジストリーの設定

手順

  1. レジストリーでストレージアカウントを使用できるように Ansible インベントリーを設定します。

    [OSEv3:vars]
    # Azure Registry Configuration
    openshift_hosted_registry_replicas=1 1
    openshift_hosted_registry_storage_kind=object
    openshift_hosted_registry_storage_azure_blob_accountkey=<account_key> 2
    openshift_hosted_registry_storage_provider=azure_blob
    openshift_hosted_registry_storage_azure_blob_accountname=<account_name> 3
    openshift_hosted_registry_storage_azure_blob_container=<registry> 4
    openshift_hosted_registry_storage_azure_blob_realm=core.windows.net
    1
    設定するレプリカ数
    2
    <account-name> に関連付けられたアカウントキー。
    3
    ストレージアカウント名。
    4
    データの保存に使用するディレクトリー。デフォルトで registry です。

オプション 2: Microsoft Azure についての OpenShift Container Platform レジストリーの手動設定

Microsoft Azure オブジェクトストレージを使用するには、レジストリーの設定ファイルを編集してレジストリー Pod にマウントします。

手順

  1. 現在の config.yml をエクスポートします。

    $ oc get secret registry-config \
        -o jsonpath='{.data.config\.yml}' -n default | base64 -d \
      >> config.yml.old
  2. 古い config.yml から新規の設定ファイルを作成します。

    $ cp config.yml.old config.yml
  3. ファイルを編集して Azure パラメーターを含めます。

    storage:
      delete:
        enabled: true
      cache:
        blobdescriptor: inmemory
      azure:
        accountname: <account-name> 1
        accountkey: <account-key> 2
        container: registry 3
        realm: core.windows.net 4
    1
    ストレージアカウント名に置き換えます。
    2
    <account-name> に関連付けられたアカウントキー。
    3
    データの保存に使用するディレクトリー。デフォルトで registry です。
    4
    デフォルトのストレージレルム core.windows.net
  4. registry-config シークレットを削除します。

    $ oc delete secret registry-config -n default
  5. シークレットを再作成して、更新された設定ファイルを参照します。

    $ oc create secret generic registry-config \
        --from-file=config.yml -n default
  6. 更新された設定を読み取るためにレジストリーを再デプロイします。

    $ oc rollout latest docker-registry -n default

レジストリーが Blob オブジェクトストレージを使用していることの確認

レジストリーが Microsoft Azure Blob ストレージを使用しているかどうかを確認するには、以下を実行します。

手順

  1. レジストリーの正常なデプロイ後に、レジストリー deploymentconfig は常にレジストリーが Microsoft Azure Blob ストレージではなく emptydir を使用していることを示します。

    $ oc describe dc docker-registry -n default
    ...
    Mounts:
      ...
      /registry from registry-storage (rw)
    Volumes:
    registry-storage:
    Type:       EmptyDir 1
    ...
    1
    Pod の寿命を共有する一時ディレクトリー
  2. /registry のマウントポイントが空かどうかを確認します。これは、Microsoft Azure ストレージが使用するボリュームです。

    $ oc exec \
        $(oc get pod -l deploymentconfig=docker-registry \
        -o=jsonpath='{.items[0].metadata.name}')  -i -t -- ls -l /registry
    total 0
  3. 空の場合は、Microsoft Azure Blob 設定が registry-config シークレットで実行されていることを示します。

    $ oc describe secret registry-config
    Name:         registry-config
    Namespace:    default
    Labels:       <none>
    Annotations:  <none>
    
    Type:  Opaque
    
    Data
    ====
    config.yml:  398 bytes
  4. インストーラーは、インストールドキュメントのストレージセクション で記載されているように、拡張されたレジストリー機能を使用して、希望の設定で config.yml ファイルを作成します。以下のコマンドで、ストレージバケット設定が保存されている storage セクションを含めて設定ファイルを表示します。

    $ oc exec \
        $(oc get pod -l deploymentconfig=docker-registry \
          -o=jsonpath='{.items[0].metadata.name}') \
      cat /etc/registry/config.yml
    
      version: 0.1
      log:
        level: debug
      http:
        addr: :5000
      storage:
        delete:
          enabled: true
        cache:
          blobdescriptor: inmemory
        azure:
          accountname: registry
          accountkey: uZekVBJBa6xzwAqK8EDz15/hoHUoc8I6cPfP31ZS+QOSxLfo7WT7CLrVPKaqvtNTMgztxH7CGjYfpFRNUhvMiA==
          container: registry
          realm: core.windows.net
      auth:
        openshift:
          realm: openshift
      middleware:
        registry:
        - name: openshift
        repository:
        - name: openshift
          options:
            pullthrough: True
            acceptschema2: True
            enforcequota: False
        storage:
        - name: openshift

    または、以下でシークレットを表示できます。

    $ oc get secret registry-config -o jsonpath='{.data.config\.yml}' | base64 -d
    version: 0.1
    log:
      level: debug
    http:
      addr: :5000
    storage:
      delete:
        enabled: true
      cache:
        blobdescriptor: inmemory
      azure:
        accountname: registry
        accountkey: uZekVBJBa6xzwAqK8EDz15/hoHUoc8I6cPfP31ZS+QOSxLfo7WT7CLrVPKaqvtNTMgztxH7CGjYfpFRNUhvMiA==
        container: registry
        realm: core.windows.net
    auth:
      openshift:
        realm: openshift
    middleware:
      registry:
      - name: openshift
      repository:
      - name: openshift
        options:
          pullthrough: True
          acceptschema2: True
          enforcequota: False
      storage:
      - name: openshift

emptyDir ボリュームを使用する場合には、/registry マウントポイントは以下のようになります。

$ oc exec \
    $(oc get pod -l deploymentconfig=docker-registry \
    -o=jsonpath='{.items[0].metadata.name}')  -i -t -- df -h /registry
Filesystem      Size  Used Avail Use% Mounted on
/dev/sdc         30G  226M   30G   1% /registry


$ oc exec \
    $(oc get pod -l deploymentconfig=docker-registry \
    -o=jsonpath='{.items[0].metadata.name}')  -i -t -- ls -l /registry
total 0
drwxr-sr-x. 3 1000000000 1000000000 22 Jun 19 12:24 docker