All Products
Search
Document Center

Container Service for Kubernetes:Images

Last Updated:Dec 18, 2023

You can pull images from a Container Registry Enterprise Edition instance without providing a password. This simplifies the operation and accelerates image pulling. This topic describes how to create workflow pods by using image caches in workflow clusters.

Prerequisites

Step 1: Configure a workflow to pull images from the Container Registry Enterprise Edition instance without a password

Add the pod annotation annotations: k8s.aliyun.com/acr-instance-id to the workflow.yaml file to specify the ID of the Container Registry Enterprise Edition instance. Set acr-instance-id in the Region ID: Instance ID format. If the workflow and the Container Registry Enterprise Edition instance are deployed in the same region, you do not need to specify the region 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"   # The region ID and instance ID of the Container Registry Enterprise Edition instance. 
  templates:
    - name: whalesay
      container:
        image: acr-en-hangzhou-registry.cn-hangzhou.cr.aliyuncs.com/workflow/whalesay   # The image that you want to pull from the Container Registry Enterprise Edition instance. 
        command: [ cowsay ]
        args: [ "hello world" ]

Step 2: Create a workflow pod by using an image cache

Perform the following operations to automatically or manually create an image cache and then use the image cache to create a workflow pod. For more information about how to use image caches, see Use image caches.

Automatically create an image cache and use the image cache to create a workflow pod

Add the pod annotation annotations: k8s.aliyun.com/eci-image-cache: "true" to the workflow.yaml file to enable image caching. After the image caching feature is enabled, the workflow can automatically uses image caches.

If an image cache of the specified image already exists, the workflow automatically uses the existing image cache to create a pod. This accelerates pod creation.

apiVersion: argoproj.io/v1alpha1
kind: Workflow
metadata:
  generateName: hello-world-
spec:
  podMetadata:
    annotations:
      k8s.aliyun.com/eci-image-cache: "true" # Specify whether to enable automatic image caching. 
  entrypoint: whalesay
  templates:
    - name: whalesay
      container:
        image: docker/whalesay
        command: [ cowsay ]
        args: [ "hello world" ]

Manually create an image cache and use the image cache to create a workflow pod

  1. Create a file named imagecache.yaml and copy the following content to the file:

    apiVersion: eci.alibabacloud.com/v1
    kind: ImageCache
    metadata:
      name: imagecache-helloworld
      annotations:
        k8s.aliyun.com/imc-enable-reuse: "true" # Enable the feature of reusing image caches. 
    spec:
      images:                         # The images for which you want to enable caching. 
      - docker/whalesay
      imagePullSecrets:               # The Secrets that are used to pull images from the image repository. Secrets are not required for pulling public images. 
      - default:secret1
      imageCacheSize:                 # The size of the image cache. Unit: GiB. Default value: 20. Valid values: 20 to 32768. 
       20
      retentionDays:                  # The retention period of the image cache. The image cache is deleted after the retention period ends. Unit: days. This parameter is left empty by default, which indicates that the image cache never expires. 
       7
  2. Run the following command to create an image cache:

    kubectl apply -f imagecache.yaml
  3. Run the following command to query the status of the image cache:

    kubectl get imagecaches

    Expected output:

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

    After the image cache enters the Ready state, you can use the image cache to create a workflow.

  4. Specify the ID of the image cache in the workflow configuration to accelerate workflow creation.

    apiVersion: argoproj.io/v1alpha1
    kind: Workflow
    metadata:
      generateName: hello-world-
    spec:
      podMetadata:
        annotations:
          k8s.aliyun.com/eci-image-snapshot-id: "imc-f8zf****"  # Specify the ID of the image cache that you want to use to create the workflow pod. 
      entrypoint: whalesay
      templates:
        - name: whalesay
          container:
            image: docker/whalesay
            command: [ cowsay ]
            args: [ "hello world" ]