文档

镜像

更新时间:

在拉取阿里云镜像服务ACR中的镜像时,您可以通过配置免密简化配置,加速镜像拉取。本文介绍如何在工作流集群中使用镜像缓存加速创建工作流Pod。

前提条件

步骤一:配置workflow免密拉取ACR企业版镜像

通过在workflow.yaml文件中增加Pod的annotations: k8s.aliyun.com/acr-instance-id指定镜像所在的ACR企业版实例,其中acr-instance-id配置格式为ACR企业版实例所在地域:实例ID,如果工作流与ACR企业版实例在同一地域,则直接配置ACR企业版实例ID,可将地域省略。

apiVersion: argoproj.io/v1alpha1
kind: Workflow
metadata:
  generateName: hello-world-
spec:
  entrypoint: whalesay
  podMetadata:
    annotations:
      k8s.aliyun.com/acr-instance-id: "cn-hangzhou:cri-f34lmbk2rxqx41u8"   # 指定镜像所在的ACR企业版实例的地域和ID。
  templates:
    - name: whalesay
      container:
        image: acr-en-hangzhou-registry.cn-hangzhou.cr.aliyuncs.com/workflow/whalesay   # 从ACR企业版拉取镜像。
        command: [ cowsay ]
        args: [ "hello world" ]

步骤二:使用镜像缓存加速创建工作流Pod

您可以通过以下自动创建和手工创建两种方式使用镜像缓存ImageCache,加速创建工作流Pod。关于使用镜像缓存的更多信息,请参见使用镜像缓存

自动创建并使用镜像缓存ImageCache

通过在workflow.yaml文件中增加Pod的annotations: k8s.aliyun.com/eci-image-cache: "true"开启镜像缓存功能,自动使用工作流中的镜像创建镜像缓存。

如果镜像缓存已存在,则直接使用镜像缓存创建工作流Pod,无需镜像下载,可加速Pod创建过程。

apiVersion: argoproj.io/v1alpha1
kind: Workflow
metadata:
  generateName: hello-world-
spec:
  podMetadata:
    annotations:
      k8s.aliyun.com/eci-image-cache: "true"  # 开启自动镜像缓存功能。
  entrypoint: whalesay
  templates:
    - name: whalesay
      container:
        image: docker/whalesay
        command: [ cowsay ]
        args: [ "hello world" ]

手工创建并使用镜像缓存ImageCache

  1. 使用以下YAML内容,创建imagecache.yaml文件。
    apiVersion: eci.alibabacloud.com/v1
    kind: ImageCache
    metadata:
      name: imagecache-helloworld
      annotations:
        k8s.aliyun.com/imc-enable-reuse: "true"  # 开启镜像缓存复用。
    spec:
      images:                         # 用于创建镜像缓存的容器镜像列表。
      - docker/whalesay
      imagePullSecrets:               # 镜像仓库对应的Secret列表,公开镜像可省略。
      - default:secret1
      imageCacheSize:                 # 镜像缓存大小。默认为20 GiB。取值范围为[20~32768] GiB。
       20
      retentionDays:                  # 镜像缓存保留时长,过期会被清理。单位为天。默认永不过期。
       7
  2. 执行以下命令,部署镜像缓存ImageCache。
    kubectl apply -f imagecache.yaml
  3. 执行以下命令,获取ImageCache状态。
    kubectl get imagecaches

    预期输出:

    NAME                    AGE     CACHEID        PHASE   PROGRESS
    imagecache-helloworld   3m36s   imc-f8zfxxxx   Ready   100%

    待状态变为Ready后,即可使用此ImageCache创建工作流。

  4. 在工作流中指定ImageCache ID,避免镜像下载,加速工作流创建过程。
    apiVersion: argoproj.io/v1alpha1
    kind: Workflow
    metadata:
      generateName: hello-world-
    spec:
      podMetadata:
        annotations:
          k8s.aliyun.com/eci-image-snapshot-id: "imc-f8zf****"  # 明确指定使用的哪个ImageCache缓存创建Pod。
      entrypoint: whalesay
      templates:
        - name: whalesay
          container:
            image: docker/whalesay
            command: [ cowsay ]
            args: [ "hello world" ]
  • 本页导读 (1)
文档反馈