
# 自动创建镜像快照
在实际使用中，手动创建镜像快照可能会增加运维复杂度。为简化操作，CCI提供了自动创建镜像快照功能。当系统拉取镜像时，若无法匹配已有的镜像快照，就会自动创建新的镜像快照，从而减少人工干预，并提升工作负载创建效率。
#### 操作步骤
1. 登录[云容器实例 CCI2.0](https://console.huaweicloud.com/cci2.0/?#/cci/cluster/list)控制台。
2. 在左侧导航栏，单击"负载管理"。
3. 单击右上角的"YAML创建"。通过YAML自动创建镜像快照。 
   YAML参考示例如下：
   ```
   kind: Deployment
   apiVersion: cci/v2
   metadata:
     name: deploy-example
     namespace: test
   spec:
     replicas: 1
     selector:
       matchLabels:
         app: deploy-example
     template:
       metadata:
         labels:
           app: deploy-example
         annotations:
           cci.io/image-snapshot-create-if-not-present: 'true'  # 自动创建镜像快照
       spec:
         containers:
           - name: deploy-example
             image: nginx:latest
             resources:
               limits:
                 cpu: '1'
                 memory: 2G
               requests:
                 cpu: '1'
                 memory: 2G
             terminationMessagePath: /dev/termination-log
             terminationMessagePolicy: File
         restartPolicy: Always
         terminationGracePeriodSeconds: 30
         dnsPolicy: Default
         securityContext: {}
         imagePullSecrets:
           - name: imagepull-secret
         schedulerName: default-scheduler
     strategy:
       type: RollingUpdate
       rollingUpdate:
         maxUnavailable: 25%
         maxSurge: 100%
     progressDeadlineSeconds: 600
   ```
   表1自动创建镜像快照参数说明 
   | 参数                                          | 类型     | 描述                                                                                                                                                  |
   |:---|:---|:---|
   | cci.io/image-snapshot-create-if-not-present | string | 自动创建镜像快照开关。不配置则默认关闭自动创建。如果镜像快照不存在，则不创建；如果镜像快照已存在，则直接使用现有镜像快照。 **true**：开启自动创建。如果镜像快照不存在，则自动创建；如果镜像快照已存在，则直接使用现有镜像快照。 |
      
   ![](https://support.huaweicloud.com/usermanual-cci2/public_sys-resources/caution_3.0-zh-cn.png)
   - 如果Pod中有多个镜像，只要任意一个镜像匹配到已有镜像快照，系统将会直接使用该匹配的镜像快照，而不会再为该镜像自动创建新的镜像快照。
    
   
   
4. 自动创建镜像快照。 
   查看容器组，无匹配的镜像快照时，CCI自动创建名为cci-imagesnapshot-xxx的临时Pod制作镜像快照。
   ![](https://support.huaweicloud.com/usermanual-cci2/zh-cn_image_0000002477171346.png "点击放大")
   ![](https://support.huaweicloud.com/usermanual-cci2/zh-cn_image_0000002568063057.png "点击放大")
   
   
   cci-imagesnapshot-xxx Pod消失后，镜像快照制作完成。
   ![](https://support.huaweicloud.com/usermanual-cci2/zh-cn_image_0000002477176350.png "点击放大")
   ![](https://support.huaweicloud.com/usermanual-cci2/zh-cn_image_0000002531279099.png "点击放大")
   
   
   扩容副本时，新建Pod会自动使用已自动创建的镜像快照，无需额外操作。
   
   
 
