4.5. 使用镜像服务


要采用镜像服务(glance),您可以修补禁用了镜像服务的现有 OpenStackControlPlane 自定义资源(CR)。补丁使用 Red Hat OpenStack Platform (RHOSP)环境提供的配置参数启动服务。

如果您看到以下结果,则镜像服务的采用已完成:

  • GlanceAPI 服务已启动且正在运行。
  • Identity 服务端点被更新,源云的后端可用。

要完成镜像服务的采用,请确保您的环境满足以下条件:

  • 您有一个正在运行的 director 环境(源云)。
  • 您有一个在 Red Hat OpenShift Container Platform (RHOCP)集群中运行的单节点 OpenShift 或 OpenShift Local。
  • 可选:您可以通过 crc 和 director 访问内部/外部 Ceph 集群。

如果您在 RHOSP 17.1 中有镜像配额,则这些配额会传送到 OpenShift 上的 Red Hat OpenStack Services (RHOSO) 18.0,因为默认情况下禁用了 18.0 中的镜像配额系统。有关在 18.0 中启用镜像配额的更多信息,请参阅自定义持久性存储 中的 配置镜像配额。如果您在 RHOSO 18.0 中启用镜像配额,新配额会替换 RHOSP 17.1 中的旧配额。

4.5.1. 使用对象存储服务后端部署的镜像服务

采用您在 Red Hat OpenStack Platform (RHOSP)环境中使用 Object Storage 服务(swift)后端部署的 Image Service (glance)。control plane glanceAPI 实例使用以下配置进行部署。您可以在使用对象存储后端部署镜像服务的补丁清单中使用此配置:

..
spec
  glance:
   ...
      customServiceConfig: |
          [DEFAULT]
          enabled_backends = default_backend:swift
          [glance_store]
          default_backend = default_backend
          [default_backend]
          swift_store_create_container_on_put = True
          swift_store_auth_version = 3
          swift_store_auth_address = {{ .KeystoneInternalURL }}
          swift_store_endpoint_type = internalURL
          swift_store_user = service:glance
          swift_store_key = {{ .ServicePassword }}
Copy to Clipboard Toggle word wrap

先决条件

  • 您已完成了以前的采用步骤。

流程

  1. 创建一个新文件,如 glance_swift.patch,并包含以下内容:

    spec:
      glance:
        enabled: true
        apiOverride:
          route: {}
        template:
          secret: osp-secret
          databaseInstance: openstack
          storage:
            storageRequest: 10G
          customServiceConfig: |
            [DEFAULT]
            enabled_backends = default_backend:swift
            [glance_store]
            default_backend = default_backend
            [default_backend]
            swift_store_create_container_on_put = True
            swift_store_auth_version = 3
            swift_store_auth_address = {{ .KeystoneInternalURL }}
            swift_store_endpoint_type = internalURL
            swift_store_user = service:glance
            swift_store_key = {{ .ServicePassword }}
          glanceAPIs:
            default:
              replicas: 1
              override:
                service:
                  internal:
                    metadata:
                      annotations:
                        metallb.universe.tf/address-pool: internalapi
                        metallb.universe.tf/allow-shared-ip: internalapi
                        metallb.universe.tf/loadBalancerIPs: 172.17.0.80 
    1
    
                    spec:
                      type: LoadBalancer
              networkAttachments:
                - storage
    Copy to Clipboard Toggle word wrap
    1
    如果使用 IPv6,请将负载均衡器 IP 更改为环境中的负载均衡器 IP,如 metallb.universe.tf/loadBalancerIPs: fd00:bbbb::80
    注意

    对象存储服务作为后端与镜像服务建立依赖项。如果镜像服务配置了在 OpenStackControlPlane 自定义资源中不可用的对象存储服务,则任何部署的 GlanceAPI 实例都无法正常工作。在 Object Storage 服务以及特定的 SwiftProxy 之后,您可以继续进行 GlanceAPI 的采用。如需更多信息,请参阅 使用对象存储服务

  2. 验证 SwiftProxy 是否可用:

    $ oc get pod -l component=swift-proxy | grep Running
    swift-proxy-75cb47f65-92rxq   3/3     Running   0
    Copy to Clipboard Toggle word wrap
  3. 对 control plane 中部署的 GlanceAPI 服务进行补丁:

    $ oc patch openstackcontrolplane openstack --type=merge --patch-file=glance_swift.patch
    Copy to Clipboard Toggle word wrap

4.5.2. 使用块存储服务后端部署的镜像服务

重要

本节中的内容 作为技术预览提供,因此不受红帽完全支持。它只应用于测试,不应部署在生产环境中。如需更多信息,请参阅 技术预览

采用您在 Red Hat OpenStack Platform (RHOSP)环境中使用块存储服务(cinder)后端部署的 Image Service (glance)。control plane glanceAPI 实例使用以下配置进行部署。您可以在使用块存储后端部署镜像服务的补丁清单中使用此配置:

..
spec
  glance:
   ...
      customServiceConfig: |
          [DEFAULT]
          enabled_backends = default_backend:cinder
          [glance_store]
          default_backend = default_backend
          [default_backend]
          description = Default cinder backend
          cinder_store_auth_address = {{ .KeystoneInternalURL }}
          cinder_store_user_name = {{ .ServiceUser }}
          cinder_store_password = {{ .ServicePassword }}
          cinder_store_project_name = service
          cinder_catalog_info = volumev3::internalURL
          cinder_use_multipath = true
Copy to Clipboard Toggle word wrap

先决条件

  • 您已完成了以前的采用步骤。

流程

  1. 创建一个新文件,如 glance_cinder.patch,并包含以下内容:

    spec:
      glance:
        enabled: true
        apiOverride:
          route: {}
        template:
          secret: osp-secret
          databaseInstance: openstack
          storage:
            storageRequest: 10G
          customServiceConfig: |
            [DEFAULT]
            enabled_backends = default_backend:cinder
            [glance_store]
            default_backend = default_backend
            [default_backend]
            description = Default cinder backend
            cinder_store_auth_address = {{ .KeystoneInternalURL }}
            cinder_store_user_name = {{ .ServiceUser }}
            cinder_store_password = {{ .ServicePassword }}
            cinder_store_project_name = service
            cinder_catalog_info = volumev3::internalURL
            cinder_use_multipath = true
          glanceAPIs:
            default:
              replicas: 1
              override:
                service:
                  internal:
                    metadata:
                      annotations:
                        metallb.universe.tf/address-pool: internalapi
                        metallb.universe.tf/allow-shared-ip: internalapi
                        metallb.universe.tf/loadBalancerIPs: 172.17.0.80 
    1
    
                    spec:
                      type: LoadBalancer
              networkAttachments:
                - storage
    Copy to Clipboard Toggle word wrap
    1
    如果使用 IPv6,请将负载均衡器 IP 更改为环境中的负载均衡器 IP,如 metallb.universe.tf/loadBalancerIPs: fd00:bbbb::80
    注意

    块存储服务作为后端与镜像服务建立依赖项。如果镜像服务配置了 OpenStackControlPlane 自定义资源中不可用的块存储服务,则任何部署的 GlanceAPI 实例都无法正常工作。在块存储服务以及特定的 CinderVolume 应用之后,您可以继续采用 GlanceAPI。如需更多信息,请参阅 使用块存储服务

  2. 验证 CinderVolume 是否可用:

    $ oc get pod -l component=cinder-volume | grep Running
    cinder-volume-75cb47f65-92rxq   3/3     Running   0
    Copy to Clipboard Toggle word wrap
  3. 对 control plane 中部署的 GlanceAPI 服务进行补丁:

    $ oc patch openstackcontrolplane openstack --type=merge --patch-file=glance_cinder.patch
    Copy to Clipboard Toggle word wrap

4.5.3. 使用 NFS 后端部署的镜像服务

采用您使用 NFS 后端部署的 Image Service (glance)。要完成以下步骤,请确保您的环境满足以下条件:

  • Storage 网络被传播到 Red Hat OpenStack Platform (RHOSP) control plane。
  • 镜像服务可以访问存储网络,并通过端口 2049 连接到 nfs-server。

先决条件

  • 您已完成了以前的采用步骤。
  • 在源云中,验证 overcloud 用来配置镜像服务后端的 NFS 参数。具体来说,在您的director heat 模板中,找到以下变量来覆盖 /usr/share/openstack-tripleo-heat-templates/environments/storage 目录中的 glance-nfs.yaml 文件提供的默认内容:

    GlanceBackend: file
    GlanceNfsEnabled: true
    GlanceNfsShare: 192.168.24.1:/var/nfs
    Copy to Clipboard Toggle word wrap
    注意

    在本例中,GlanceBackend 变量显示镜像服务没有 NFS 后端的概念。变量使用 文件 驱动程序,并在后台使用 filesystem_store_datadirfilesystem_store_datadir 映射到 GlanceNfsShare 变量提供的导出值,而不是 /var/lib/glance/images/。如果您没有通过传播到 OpenShift (RHOSO)控制平面上的红帽 OpenStack 服务的网络导出 GlanceNfsShare,则必须停止 nfs-server 并将导出重新映射到 存储网络。在这样做前,请确保镜像服务在源 Controller 节点上停止。

    在 control plane 中,镜像服务附加到 Storage 网络,然后通过关联的 NetworkAttachmentsDefinition 自定义资源(CR)传播,生成的 pod 已具有通过此网络处理镜像服务流量的正确权限。在部署的 RHOSP control plane 中,您可以通过检查 NodeNetworkConfigPolicy (nncp)和 NetworkAttachmentDefinition (net-attach-def)来验证网络映射是否与基于 director 的环境中部署的相匹配。以下是您应该在 Red Hat OpenShift Container Platform (RHOCP)环境中检查的输出示例,以确保传播网络没有问题:

    $ oc get nncp
    NAME                        STATUS      REASON
    enp6s0-crc-8cf2w-master-0   Available   SuccessfullyConfigured
    
    $ oc get net-attach-def
    NAME
    ctlplane
    internalapi
    storage
    tenant
    
    $ oc get ipaddresspool -n metallb-system
    NAME          AUTO ASSIGN   AVOID BUGGY IPS   ADDRESSES
    ctlplane      true          false             ["192.168.122.80-192.168.122.90"]
    internalapi   true          false             ["172.17.0.80-172.17.0.90"]
    storage       true          false             ["172.18.0.80-172.18.0.90"]
    tenant        true          false             ["172.19.0.80-172.19.0.90"]
    Copy to Clipboard Toggle word wrap

流程

  1. 采用镜像服务,再创建一个新的 默认 GlanceAPI 实例,该实例与现有 NFS 共享连接:

    $ cat << EOF > glance_nfs_patch.yaml
    
    spec:
      extraMounts:
      - extraVol:
        - extraVolType: Nfs
          mounts:
          - mountPath: /var/lib/glance/images
            name: nfs
          propagation:
          - Glance
          volumes:
          - name: nfs
            nfs:
              path: <exported_path> 
    1
    
              server: <ip_address> 
    2
    
        name: r1
        region: r1
      glance:
        enabled: true
        template:
          databaseInstance: openstack
          customServiceConfig: |
            [DEFAULT]
            enabled_backends = default_backend:file
            [glance_store]
            default_backend = default_backend
            [default_backend]
            filesystem_store_datadir = /var/lib/glance/images/
          storage:
            storageRequest: 10G
          keystoneEndpoint: nfs
          glanceAPIs:
            nfs:
              replicas: 3
              type: single
              override:
                service:
                  internal:
                    metadata:
                      annotations:
                        metallb.universe.tf/address-pool: internalapi
                        metallb.universe.tf/allow-shared-ip: internalapi
                        metallb.universe.tf/loadBalancerIPs: 172.17.0.80 
    3
    
                    spec:
                      type: LoadBalancer
              networkAttachments:
              - storage
    EOF
    Copy to Clipboard Toggle word wrap
    1
    使用 <exported_path> nfs-server 中导出的路径替换。
    2
    <ip_address > 替换为您要与 nfs-server 通信的 IP 地址。
    3
    如果使用 IPv6,请将负载均衡器 IP 更改为环境中的负载均衡器 IP,如 metallb.universe.tf/loadBalancerIPs: fd00:bbbb::80
  2. 修补 OpenStackControlPlane CR,以使用 NFS 后端部署镜像服务:

    $ oc patch openstackcontrolplane openstack --type=merge --patch-file glance_nfs_patch.yaml
    Copy to Clipboard Toggle word wrap
  3. 修补 OpenStackControlPlane CR 以删除默认镜像服务:

    $ oc patch openstackcontrolplane openstack --type=json -p="[{'op': 'remove', 'path': '/spec/glance/template/glanceAPIs/default'}]"
    Copy to Clipboard Toggle word wrap

验证

  • GlanceAPI 处于活跃状态时,请确认您可以看到单个 API 实例:

    $ oc get pods -l service=glance
    NAME                      READY   STATUS    RESTARTS
    glance-nfs-single-0   2/2     Running   0
    glance-nfs-single-1   2/2     Running   0
    glance-nfs-single-2   2/2     Running   0
    Copy to Clipboard Toggle word wrap
  • 确保 pod 的描述报告以下输出:

    Mounts:
    ...
      nfs:
        Type:      NFS (an NFS mount that lasts the lifetime of a pod)
        Server:    {{ server ip address }}
        Path:      {{ nfs export path }}
        ReadOnly:  false
    ...
    Copy to Clipboard Toggle word wrap
  • 检查指向 /var/lib/glance/images 的挂载点是否已映射到您在新的默认 GlanceAPI 实例中定义的预期 nfs 服务器 ip 和 nfs 路径

    $ oc rsh -c glance-api glance-default-single-0
    
    sh-5.1# mount
    ...
    ...
    {{ ip address }}:/var/nfs on /var/lib/glance/images type nfs4 (rw,relatime,vers=4.2,rsize=1048576,wsize=1048576,namlen=255,hard,proto=tcp,timeo=600,retrans=2,sec=sys,clientaddr=172.18.0.5,local_lock=none,addr=172.18.0.5)
    ...
    ...
    Copy to Clipboard Toggle word wrap
  • 确认 UUID 已在 NFS 节点上的导出的目录中创建。例如:

    $ oc rsh openstackclient
    $ openstack image list
    
    sh-5.1$  curl -L -o /tmp/cirros-0.6.3-x86_64-disk.img http://download.cirros-cloud.net/0.6.3/cirros-0.6.3-x86_64-disk.img
    ...
    ...
    
    sh-5.1$ openstack image create --container-format bare --disk-format raw --file /tmp/cirros-0.6.3-x86_64-disk.img cirros
    ...
    ...
    
    sh-5.1$ openstack image list
    +--------------------------------------+--------+--------+
    | ID                                   | Name   | Status |
    +--------------------------------------+--------+--------+
    | 634482ca-4002-4a6d-b1d5-64502ad02630 | cirros | active |
    +--------------------------------------+--------+--------+
    Copy to Clipboard Toggle word wrap
  • nfs-server 节点上,相同的 uuid 位于导出的 /var/nfs 中:

    $ ls /var/nfs/
    634482ca-4002-4a6d-b1d5-64502ad02630
    Copy to Clipboard Toggle word wrap

采用您使用 Red Hat Ceph Storage 后端部署的 Image Service (glance)。使用 customServiceConfig 参数将正确的配置注入 GlanceAPI 实例。

先决条件

  • 您已完成了以前的采用步骤。
  • 确保在 openstack 命名空间中创建了与 Ceph 相关的 secret (ceph-conf-files),并且 OpenStackControlPlane 自定义资源(CR)的 extraMounts 属性已正确配置。有关更多信息 ,请参阅配置 Ceph 后端

    $ cat << EOF > glance_patch.yaml
    spec:
      glance:
        enabled: true
        template:
          databaseInstance: openstack
          customServiceConfig: |
            [DEFAULT]
            enabled_backends=default_backend:rbd
            [glance_store]
            default_backend=default_backend
            [default_backend]
            rbd_store_ceph_conf=/etc/ceph/ceph.conf
            rbd_store_user=openstack
            rbd_store_pool=images
            store_description=Ceph glance store backend.
          storage:
            storageRequest: 10G
          glanceAPIs:
            default:
              replicas: 0
              override:
                service:
                  internal:
                    metadata:
                      annotations:
                        metallb.universe.tf/address-pool: internalapi
                        metallb.universe.tf/allow-shared-ip: internalapi
                        metallb.universe.tf/loadBalancerIPs: 172.17.0.80 
    1
    
                    spec:
                      type: LoadBalancer
              networkAttachments:
              - storage
    EOF
    Copy to Clipboard Toggle word wrap
    1
    如果使用 IPv6,请将负载均衡器 IP 更改为环境中的负载均衡器 IP,如 metallb.universe.tf/loadBalancerIPs: fd00:bbbb::80
注意

如果您从原始环境中备份了 Red Hat OpenStack Platform (RHOSP)服务配置文件,您可以将它与您采用的 confgiuration 文件进行比较,并确保配置正确。如需更多信息,请参阅从 director 部署拉取配置

os-diff diff /tmp/collect_tripleo_configs/glance/etc/glance/glance-api.conf glance_patch.yaml --crd
Copy to Clipboard Toggle word wrap

此命令产生两个 ini 配置文件之间的区别。

流程

  • 修补 OpenStackControlPlane CR,以使用 Red Hat Ceph Storage 后端部署镜像服务:

    $ oc patch openstackcontrolplane openstack --type=merge --patch-file glance_patch.yaml
    Copy to Clipboard Toggle word wrap

4.5.5. 验证镜像服务的采用

验证您是否将 Image Service (glance)添加至 OpenShift (RHOSO) 18.0 部署上的 Red Hat OpenStack Services 中。

流程

  1. 通过 Red Hat OpenStack Platform CLI 测试镜像服务。您可以比较并确保配置应用到镜像服务 pod:

    $ os-diff diff /etc/glance/glance.conf.d/02-config.conf glance_patch.yaml --frompod -p glance-api
    Copy to Clipboard Toggle word wrap

    如果没有显示行,则配置正确。

  2. 检查生成的镜像服务 pod:

    GLANCE_POD=`oc get pod |grep glance-default | cut -f 1 -d' ' | head -n 1`
    oc exec -t $GLANCE_POD -c glance-api -- cat /etc/glance/glance.conf.d/02-config.conf
    
    [DEFAULT]
    enabled_backends=default_backend:rbd
    [glance_store]
    default_backend=default_backend
    [default_backend]
    rbd_store_ceph_conf=/etc/ceph/ceph.conf
    rbd_store_user=openstack
    rbd_store_pool=images
    store_description=Ceph glance store backend.
    Copy to Clipboard Toggle word wrap
  3. 如果使用 Red Hat Ceph Storage 后端,请确保挂载 Red Hat Ceph Storage secret:

    $ oc exec -t $GLANCE_POD -c glance-api -- ls /etc/ceph
    ceph.client.openstack.keyring
    ceph.conf
    Copy to Clipboard Toggle word wrap
  4. 检查服务是否活跃,并在 RHOSP CLI 中更新端点:

    $ oc rsh openstackclient
    $ openstack service list | grep image
    
    | fc52dbffef36434d906eeb99adfc6186 | glance    | image        |
    
    $ openstack endpoint list | grep image
    
    | 569ed81064f84d4a91e0d2d807e4c1f1 | regionOne | glance       | image        | True    | internal  | http://glance-internal-openstack.apps-crc.testing   |
    | 5843fae70cba4e73b29d4aff3e8b616c | regionOne | glance       | image        | True    | public    | http://glance-public-openstack.apps-crc.testing     |
    Copy to Clipboard Toggle word wrap
  5. 检查您之前在源云中列出的镜像是否在采用的服务中可用:

    $ openstack image list
    +--------------------------------------+--------+--------+
    | ID                                   | Name   | Status |
    +--------------------------------------+--------+--------+
    | c3158cad-d50b-452f-bec1-f250562f5c1f | cirros | active |
    +--------------------------------------+--------+--------+
    Copy to Clipboard Toggle word wrap
返回顶部
Red Hat logoGithubredditYoutubeTwitter

学习

尝试、购买和销售

社区

关于红帽文档

通过我们的产品和服务,以及可以信赖的内容,帮助红帽用户创新并实现他们的目标。 了解我们当前的更新.

让开源更具包容性

红帽致力于替换我们的代码、文档和 Web 属性中存在问题的语言。欲了解更多详情,请参阅红帽博客.

關於紅帽

我们提供强化的解决方案,使企业能够更轻松地跨平台和环境(从核心数据中心到网络边缘)工作。

Theme

© 2025 Red Hat