Red Hat Training

A Red Hat training course is available for OpenShift Container Platform

24.4.3. 为 Microsoft Azure 配置 OpenShift Container Platform registry

Microsoft Azure 提供 OpenShift Container Platform 可以用来使用 OpenShift Container Platform 容器镜像 registry 存储容器镜像的对象云存储。

如需更多信息,请参阅 Azure 文档中的 Cloud Storage

您可以使用 Ansible 配置 registry,或者通过配置 registry 配置文件来手动配置 registry。

先决条件

在安装前,您必须创建一个存储帐户来托管 registry 镜像。以下命令会创建一个在安装过程中用于镜像存储的存储帐户:

您可以使用 Microsoft Azure blob 存储来存储容器镜像。OpenShift Container Platform registry 使用 blob 存储来允许 registry 大小动态增长,而无需管理员进行干预。

  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 registry 配置只需要一个帐户键值。

选项 1:使用 Ansible 为 Azure 配置 OpenShift Container Platform registry

流程

  1. 将 registry 的 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 registry

要使用 Microsoft Azure 对象存储,请编辑 registry 的配置文件并挂载到 registry 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
    默认情况下,存储 realm core.windows.net
  4. 删除 registry-config secret:

    $ oc delete secret registry-config -n default
  5. 重新创建 secret 来引用更新的配置文件:

    $ oc create secret generic registry-config \
        --from-file=config.yml -n default
  6. 重新部署 registry 以读取更新的配置:

    $ oc rollout latest docker-registry -n default

验证 registry 正在使用 blob 对象存储

验证 registry 是否使用 Microsoft Azure blob 存储:

流程

  1. 在成功部署 registry 后,registry deploymentconfig 将始终显示 registry 使用 emptydir 而不是 Microsoft Azure blob 存储:

    $ 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 secret 中执行:

    $ oc describe secret registry-config
    Name:         registry-config
    Namespace:    default
    Labels:       <none>
    Annotations:  <none>
    
    Type:  Opaque
    
    Data
    ====
    config.yml:  398 bytes
  4. 安装程序会使用扩展的 registry 功能创建带有所需配置的 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

    或者,您可以查看 secret:

    $ 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