
# 使用镜像快照加速镜像拉取
#### 场景描述
镜像快照服务提供更加高效的容器启动方式，使用镜像快照创建CCI 2.0实例可以加速拉取镜像，减少CCI实例的启动耗时，使用镜像快照可参考[使用镜像快照](https://support.huaweicloud.com/usermanual-cci2/cci_01_0114.html)。
#### 操作步骤
1. 登录[云容器实例 CCI2.0](https://console.huaweicloud.com/cci2.0/?#/cci/cluster/list)控制台。
2. 在左侧导航栏中选择"镜像加速"，单击右上角"YAML创建"，按以下yaml示例填写： 
   ```
   apiVersion: cci/v2
   kind: ImageSnapshot
   metadata:
     name: imagesnapshot-a
   spec:
     buildingConfig:
       namespace: test #命名空间
     imageSnapshotSize: 20 #快照大小，单位为GiB
     ttlDaysAfterCreated: 100 #镜像有效期
     images:
       - image: nginx:stable-alpine-perl #镜像
     registries: []
   ```
   
   
3. 在左侧导航栏中选择"负载管理 -\> 无状态负载"，单击左上角"YAML创建"创建负载，annotation配置cci.io/image-snapshot-auto-match: 'true'，示例如下： 
   ```
   kind: Deployment
   apiVersion: cci/v2
   metadata:
     name: nginx
   spec:
     replicas: 1
     selector:
       matchLabels:
         app: nginx
     template:
       metadata:
         labels:
           app: nginx
         annotations:
           cci.io/image-snapshot-auto-match: 'true' #镜像快照自动匹配
       spec:
         containers:
           - name: nginx
             image: nginx:stable-alpine-perl
             resources:
               requests:
                 cpu: 500m
                 memory: 1Gi
   ```
   
   
4. 检查启动后的 pod annotations中有字段：cci.io/image-snapshot-detail、cci.io/imagesnapshot-volume，显示匹配的快照，且挂载数据盘大小和快照大小一致。
 
