更新时间:2025-09-12 GMT+08:00
分享

创建镜像快照

操作场景

本章介绍了如何创建镜像快照。要了解镜像快照的工作原理,请参阅镜像快照概述

操作步骤

运行容器需要先拉取指定的容器镜像,但因网络和容器镜像大小等因素,镜像拉取耗时往往成了Pod启动的主要耗时。通过镜像快照功能,可以事先将要使用的镜像制作成快照,基于该快照创建Pod,从而避免镜像下载,提升Pod的启动速度。

  1. 登录云容器实例 CCI2.0控制台。
  2. 单击左侧导航栏的“镜像快照”,进入镜像快照页面。
  3. 单击右上角“YAML创建”。

    以下示例创建一个名为my-imagesnapshot的镜像快照。

    apiVersion: cci/v2
    kind: ImageSnapshot
    metadata:
      name: 'my-imagesnapshot'
    spec:
      buildingConfig:
        namespace: test-namespace
        eipID: xxxxxxxx
      imageSnapshotSize: 30
      ttlDaysAfterCreated: 7
      images:
        - image: 'nginx:stable-alpine-perl'
      registries:
        - imagePullSecret: imagepull-secret
          server: xxxxx.myhuaweicloud.com
          plainHTTP: true
    表1 参数说明

    字段

    类型

    必填

    示例值

    描述

    .metadata.name

    string

    my-imagesnapshot

    镜像快照名称。

    .spec.images.image

    string

    nginx:latest

    用于制作镜像快照的镜像。

    .spec.registries.server

    string

    serverA.com

    不带 http:// 或 https:// 前缀的镜像仓库地址。

    .spec.registries.imagePullSecret

    string

    imagepull-secret

    访问镜像仓库使用的凭证Secret。

    .spec.registries.plainHTTP

    boolean

    true

    如果是使用HTTP协议的自建镜像仓库地址,需要设置为true,否则会因协议不同而导致镜像拉取失败。默认值为false。

    .spec.registries.insecureSkipVerify

    boolean

    true

    如果是使用自签发证书的自建镜像仓库地址,需要设置为true来跳过证书认证,否则会因证书认证失败而导致镜像拉取失败。默认值为false。

    .spec.buildingConfig.namespace

    string

    my-namespace-a

    用户命名空间。镜像快照制过程需要在用户命名空间创建CCI实例。

    .spec.buildingConfig.eipID

    string

    3cxxxxe0-xxxx-xxxx-xxxx-8xxxxf3xxxx4

    用于访问拉取公网镜像的EIP

    .spec.buildingConfig.autoCreateEIP

    boolean

    true

    在制作镜像快照时,是否自动为创建镜像快照实例创建弹性公网IP,当指定了eipId的情况下,autoCreateEIP配置将被忽略。当autoCreateEIP为true时,需通过autoCreateEIPAttribute指定弹性公网IP的配置。

    .spec.buildingConfig.autoCreateEIPAttribute.bandwidthChargeMode

    string

    bandwidth

    按流量计费还是按带宽计费。

    取值范围:bandwidth,traffic,不填或者为空时默认是bandwidth。其中IPv6国外默认是bandwidth,国内默认是traffic。

    .spec.buildingConfig.autoCreateEIPAttribute.bandwidthSize

    int

    1000

    带宽大小。

    取值范围:默认1Mbit/s~2000Mbit/s

    .spec.buildingConfig.autoCreateEIPAttribute.type

    string

    5_bgp

    EIP的类型。

    取值范围:5_bgp(全动态BGP),5_sbgp(静态BGP),5_youxuanbgp(优选BGP)。

    .spec.buildingConfig.autoCreateEIPAttribute.ipVersion

    int

    4

    弹性公网IP的版本。

    取值范围:4或者6。

    • 4表示IPv4,不填或空字符串时,默认创建IPv4。
    • 6表示IPv6,开启NAT64能力。

    .spec.buildingConfig.TimeoutMinutes

    int

    1440

    镜像快照制作完成的超时时间,单位分钟。

    取值范围:[30, 10080] 的整数,表示30分钟~1周。默认值为1440,表示1天。

    .spec.ttlDaysAfterCreated

    integer

    10

    镜像快照保留时间,单位为天,过期将会被清理。默认值为0,即永不过期。

    每当快照被负载/容器组资源使用时,其过期时间将被重置为当前时间加上快照保留时间。

    说明:

    快照过期后,仍会占用配额,需定期审核过期镜像快照后删除。

    .spec.imageSnapshotSize

    integer

    20

    镜像快照大小,单位为GiB,默认值为20。

相关文档